uCosminexus Application Server, Web Service Development Guide
The following is an example of creating a provider implementation class com.sample.UserInfoImpl. The created class com.sample.UserInfoImpl is saved in the c:\temp\jaxws\works\dispatch_provider\server\src\com\sample\ directory with the UTF-8 format.
package com.sample;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.soap.AttachmentPart;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Provider;
@javax.xml.ws.WebServiceProvider(serviceName="UserInfoService")
@javax.xml.ws.ServiceMode(value=javax.xml.ws.Service.Mode.MESSAGE)
public class UserInfoImpl implements Provider<SOAPMessage>{
public SOAPMessage invoke( SOAPMessage request ){
// Response message
SOAPMessage response = null;
// Attachment (face photograph)
AttachmentPart attachment = null;
try {
// Data acquisition from the request message
// Acquire the employee number
SOAPBody soapBody = request.getSOAPBody();
SOAPBodyElement reqRoot =
(SOAPBodyElement)soapBody.getChildElements().next();
Iterator number_iterator = reqRoot.getChildElements();
String number =
((SOAPElement)number_iterator.next()).getFirstChild().getNodeValue();
// Acquire the face photograph
Iterator attachment_iterator = request.getAttachments();
while(attachment_iterator.hasNext()){
attachment = (AttachmentPart)attachment_iterator.next();
}
// If any other process, such as registering the face photograph, is to be executed
// for the acquired attachment, implement the process
// Generating a response message
response = MessageFactory.newInstance().createMessage();
SOAPBody resSoapBody = response.getSOAPBody();
SOAPBodyElement resRoot = resSoapBody.addBodyElement(
new QName("http://sample.com", "result"));
SOAPElement soapElement = resRoot.addChildElement(
new QName("http://sample.com", "value"));
// Set up a registration confirmation message
if(null == attachment){
soapElement.addTextNode("Failure(no image).");
} else {
soapElement.addTextNode("Success.");
}
} catch (SOAPException e) {
e.printStackTrace();
}
return response;
}
}
|
For SOAP 1.2, add the javax.xml.ws.BindingType annotation to the provider implementation class that you have created. Specify the value http://www.w3.org/2003/05/soap/bindings/HTTP/ indicating the SOAP 1.2/HTTP binding. The following is an example of adding the javax.xml.ws.BindingType annotation:
package com.sample;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.soap.AttachmentPart;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Provider;
@javax.xml.ws.BindingType("http://www.w3.org/2003/05/soap/bindings/HTTP/")
@javax.xml.ws.WebServiceProvider
@javax.xml.ws.ServiceMode(value=javax.xml.ws.Service.Mode.MESSAGE)
public class UserInfoImpl implements Provider<SOAPMessage>{
public SOAPMessage invoke( SOAPMessage request ){
(Hereafter, same as for SOAP1.1)
|
Note that you can also specify the constant value field javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING instead of http://www.w3.org/2003/05/soap/bindings/HTTP/ in the value of the javax.xml.ws.BindingType annotation. For an example to specify constant value fields, see the section 5.3.1 Creating a Web Service Implementation Class.
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.