![]() | |
| |
Java API for XML-Based Web Services (JAX-WS) relies on the use of annotations to specify metadata associated with Web services implementations and to simplify the development of Web services. Annotations describe how a server-side service implementation is accessed as a Web service or how a client-side Java class accesses Web services.
The JAX-WS programming standard introduces support for annotating Java classes with metadata that is used to define a service endpoint application as a Web service and how a client can access the Web service. JAX-WS supports the use of annotations based on the Metadata Facility for the Java Programming Language (JSR 175) specification, the Web Services Metadata for the Java Platform (JSR 181) specification and annotations defined by the JAX-WS 2.0 and later (JSR 224) specification which includes JAXB annotations. Using annotations from the JSR 181 standard, you can simply annotate the service implementation class or the service interface and now the application is enabled as a Web service. Using annotations within the Java source simplifies development and deployment of Web services by defining some of the additional information that is typically obtained from deployment descriptor files, WSDL files, or mapping metadata from XML and WSDL into the source artifacts.
Use annotations to configure bindings, handler chains, set names of portType, service and other WSDL parameters. Annotations are used in mapping Java to WSDL and schema, and at runtime to control how the JAX-WS runtime processes and responds to Web service invocations.
For JAX-WS Web services, the use of the webservices.xml deployment descriptor is OPTIONAL because you can use annotations to specify all of the information that is contained within the deployment descriptor file. You can use the deployment descriptor file to augment or override existing JAX-WS annotations. Any information that you define in the webservices.xml deployment descriptor overrides any corresponding information that is specified by annotations.
JSR 181 (Web Services Metadata) Annotations
javax.jws.WebService
The purpose of this annotation is to mark a endpoint implementation as implementing a web service or to mark that a service endpoint interface as defining a web service interface. All endpoint implementation classes MUST have a WebService annotation and must meet the requirements of section 3.3 of the JAX-WS 2.0 specification.
Table 4.1. javax.jws.WebService
| Property | Description | Default |
|---|---|---|
| name | The name of the wsdl:portType | The unqualified name of the Java class or interface |
| targetNamespace | The XML namespace of the the WSDL and some of the XML elements generated from this web service. Most of the XML elements will be in the namespace according to the JAXB mapping rules. | The namespace mapped from the package name containing the web service according to section 3.2 of the JAX-WS 2.0 specification. |
| serviceName | The Service name of the web service: wsdl:service | The unqualified name of the Java class or interface + "Service" |
| endpointInterface | The qualified name of the service endpoint interface. This annotation allows the separation of interface contract from implementation. If this property is specified, all other WebService properties are ignored as are all other 181 annotations. Only the annotations on the service endpoint interface will be taken into consideration. The endpoint implementation class is not required to implement the endpointInterface. | None – If not specified, the endpoint implementation class is used to generate the web service contract. In this case, a service endpoint interface is not required. |
| portName | The wsdl:portName | The WebService.name + "Port" |
| wsdlLocation | Specifies the Web address of the WSDL document defining the Web service. The Web address is either relative or absolute. | - |
Example 1:
@WebService(name="AddNumbers", targetNamespace="http://duke.example.org", name="AddNumbers")
public class AddNumbersImpl {
public int addNumbers(int number1, int number2) {
return number1 + number2;
}
}
You can notice that the AddNumbersImpl implementation class does not implement
a service endpoint interface. In JAX-WS 2.0 service endpoint interface is no longer required. If a
service endpoint interfaces is desired, then the @WebService annotation on the
endpoint implementation is modified to specify the endpoint interface and the actual service endpoint
interface must also have a @WebService annotation. The following is the above
AddNumbersImpl modified to use a service endpoint interface.
Example 2:
@WebService(endpointInterface = "com.example.AddNumbersIF")
public class AddNumbersImpl {
public int addNumbers(int number1, int number2) {
return number1 + number2;
}
}
@WebService(targetNamespace="http://duke.example.org", name="AddNumbers")
public interface AddNumbersIF {
public int addNumbers(int number1, int number2);
}
NOTE: The following rules apply for methods on classes annotated with the @WebService annotation:
If the @WebService annotation of an implementation class references an Service Endpoint Interface (SEI), the implementation class MUST NOT have any @WebMethod annotations.
ALL public methods for an SEI are considered exposed methods regardless of whether the @WebMethod annotation is specified or not. It is incorrect to have an @WebMethod annotation on an SEI that contains the exclude attribute.
For an implementation class that DOES NOT reference an SEI, if the @WebMethod annotation is specified with a value of exclude=true, that method is NOT exposed. If the @WebMethod annotation is not specified, all public methods are exposed including the inherited methods with the exception of methods inherited from java.lang.Object.
javax.jws.WebMethod
The purpose of this annotation is to expose a method as a web service operation. The method must meet all the requirements of section 3.4 of the JAX-WS 2.0 specification.
Table 4.2. javax.jws.WebMethod
| Property | Description | Default |
|---|---|---|
| operationName | The name of the wsdl:operation matching this method. For operations using the mode defined by SOAPBinding.Style.DOCUMENT, SOAPBinding.Use.LITERAL, and SOAPBinding.ParameterStyle.BARE, this name is also used for the global XML element representing the operations body element. The namespace of this name is taken from the value WebService.targetNamespace or its default value. | The name of the Java method |
| action | The XML namespace of the the WSDL and some of the XML elements generated from this web service. Most of the XML elements will be in the namespace according to the JAXB mapping rules. | "" |
| exclude | Used to exclude a method from the WebService. | false |
Example:
@WebService(targetNamespace="http://duke.example.org", name="AddNumbers")
public interface AddNumbersIF {
@WebMethod(operationName="add", action="urn:addNumbers")
public int addNumbers(int number1, int number2);
}
NOTE: Apply this annotation to methods on a client or server Service Endpoint Interface (SEI) or a server endpoint implementation class.
NOTE: The @WebMethod annotation is only supported on classes that are annotated with the @WebService annotation.
javax.jws.OneWay
The purpose of this annotation is to mark a method as a web service one-way operation. The method must meet all the requirements of section 3.4.1 of the JSR 224 spec.
Example:
@WebService(name="CheckIn")
public interface CheckInIF {
@WebMethod
@OneWay
public void checkIn(String name);
}
javax.jws.WebParam
This annotation is used to customize the mapping of a single parameter to a message part or element.
Table 4.3. javax.jws.WebParam
| Property | Description | Default |
|---|---|---|
| name | Name of the parameter. If the operation is rpc style and @WebParam.partName has not been specified, this is name of the wsdl:part representing the parameter. @WebMethod.operationName, if the operation is document style and the parameter style is BARE. If the operation is document style or the parameter maps to a header, this is the local name of the XML element representing the parameter. A name MUST be specified if the operation is document style, the parameter style is BARE, and the mode is OUT or INOUT. | @WebMethod.operationName, if the operation is document style and the parameter style is BARE. Otherwise, the default is argN, where N represents the index of the parameter in the method signature (starting at arg0). |
| targetNamespace | - | - |
| mode | Represents the direction the parameter flows for this method. Possible values are IN, INOUT and OUT. INOUT and OUT modes can only be used with parameters that meet the requirements for a holder as classified by section 3.5 of the JAX-WS 2.0 specification. OUT and INOUT parameters can be used by all RPC and DOCUMENT bindings. | IN for non-holder parameters INOUT for holder parameters. |
| header | - | FALSE |
| partName | Used to specify the partName for the parameter with RPC or DOCUMENT/BARE operations. | @WebParam.name |
Example 1:
@WebService(targetNamespace="http://duke.example.org", name="AddNumbers")
public interface AddNumbersIF {
@WebMethod(operationName="add", action="urn:addNumbers")
@WebResult(name="return")
public int addNumbers(
@WebParam(name="num1")int number1,
@WebParam(name="num2")int number2
);
}
Example 2:
@WebService(targetNamespace="http://duke.example.org", name="AddNumbers")
public interface AddNumbersIF {
@WebMethod(operationName="add", action="urn:addNumbers")
@WebResult(name="return")
public void addNumbers(
@WebParam(name="num1")int number1,
@WebParam(name="num2")int number2,
@WebParam(name="result" mode=WebParam.Mode.OUT) Holder<Integer> result)
throws AddNumbersException;
}
javax.jws.WebResult
This annotation is used to customize the mapping of the method return value to a WSDL part or XML element.
Table 4.4. javax.jws.WebResult
| Property | Description | Default |
|---|---|---|
| name | The name of the return value in the WSDL and on the wire. For RPC bindings this is the part name of the return value in the response message. For DOCUMENT bindings this is the local name of the XML element representing the return value. | "return" for RPC and DOCUMENT/WRAPPED bindings. Method name + "Response for DOCUMENT/BARE bindings. |
| targetNamespace | - | - |
| header | - | FALSE |
| partName | Used to specify the partName for the result with RPC or DOCUMENT/BARE operations. | @WebResult.name |
Example:
@WebService(targetNamespace="http://duke.example.org", name="AddNumbers")
public interface AddNumbersIF {
@WebMethod(operationName="add", action="urn:addNumbers")
@WebResult(name="return")
public int addNumbers(
@WebParam(name="num1")int number1,
@WebParam(name="num2")int number2
);
}
javax.jws.HandlerChain
This annotation is used to specified an externally defined handler chain.
Table 4.5. javax.jws.HandlerChain
| Property | Description | Default |
|---|---|---|
| file | Location of the file containing the handler chain definition. The location can be relative or absolute with in a classpath system. If the location is relative, it is relative to the package of the web service. If it is absolute, it is absolute from some path on the classpath. | none |
| name | DEPRECATED: The handler chain name from within the handler chain file. | "" |
Example:
@WebService
@HandlerChain(file="handlers.xml")
public class AddNumbersImpl {
public int addNumbers(int number1, int number2) {
return number1 + number2;
}
}
handlers.xml:
<jws:handler-config xmlns:jws="http://java.sun.com/xml/ns/javaee">
<jws:handler-chains>
<jws:handler-chain>
<jws:handler>
<jws:handler-class>handler.common.LoggingHandler</jws:handler-class>
</jws:handler>
</jws:handler-chain>
</jws:handler-chains>
</jws:handler-config>
You can only configure the server side handler by using the @HandlerChain annotation on the Service Endpoint Interface (SEI) or the server endpoint implementation class.
Use one of several ways to configure a client side handler. You can configure a client side handler by using the @HandlerChain annotation on the generated service class or SEI. Additionally, you can programmatically register your own implementation of the HandlerResolver interface on the Service, or programmatically set the handler chain on the Binding object.
javax.jws.soap.SOAPBinding
JSR 181 also allows you to specify a SOAPBinding annotation on a endpoint implementation or service endpoint interface. This annotation lets the developer choose between document/literal wrapped, document/literal bare, rpc/literal and rpc/encoded endpoints with the default being document/literal wrapped. JAX-WS 2.1 does not support rpc/encoded.
The main difference between document/literal bare and document/literal wrapped is that methods on a document/literal wrapped endpoint can have multiple parameters bound to the body of a SOAP message, while a document/literal bare can only have one such parameter.
The main difference between document/literal wrapped and rpc/literal is that a document/literal invocation can be fully validated by a standard validating XML parser, while an rpc/literal invocation cannot because of the implied wrapper element around the invocation body.
Table 4.6. javax.jws.HandlerChain
| Property | Description | Default |
|---|---|---|
| style | Defines the style for messages used in a web service. The value can be either DOCUMENT or RPC. | DOCUMENT |
| use | Defines the encoding used for messages used in web service. Can only be LITERAL for JAX-WS 2.1 | LITERAL |
| parameterStyle | Determines if the method's parameters represent the entire message body or whether the parameters are wrapped in a body element named after the operation. Choice of WRAPPED or BARE. BARE can only be used with DOCUMENT style bindings. | WRAPPED |
Example:
@WebService(targetNamespace="http://duke.example.org", name="AddNumbers")
@SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.LITERAL)
public interface AddNumbersIF {
@WebMethod(operationName="add", action="urn:addNumbers")
@WebResult(name="return")
public int addNumbers(
@WebParam(name="num1")int number1,
@WebParam(name="num2")int number2
);
}
JSR 224 (JAX-WS) Annotations
javax.xml.ws.BindingType
The BindingType annotation is used to specify the binding to use for a web service endpoint implementation class. As well as specify additional features that may be enabled.
This annotation may be overriden programmatically or via deployment descriptors, depending on the platform in use.
Example 1: Given the web service defined, the deployed endpoint would use the SOAP1.2 over HTTP binding:
@WebService
@BindingType(value="http://www.w3.org/2003/05/soap/bindings/HTTP/")
public class AddNumbersImpl {
public int addNumbers(int number1, int number2) {
return number1 + number2;
}
}
Example 2: Here is another sample use of the BindingType annotation that specifies use of the SOAP1.1/HTTP binding, it enables both the AddressingFeature and the MTOMFeature and also sets the threshold feature parameter on the MTOMFeature:
@WebService
@BindingType(value=SOAPBinding.SOAP11HTTP_BINDING,
features={
@Feature(AddressingFeature.ID),
@Feature(value=MTOMFeature.ID,
parameters={@FeatureParameter(name=MTOMFeature.THRESHOLD, value="1000")})
}
)
public class MyWebService {
...
}
NOTE: You can use the @BindingType annotation on the JavaBeans endpoint implementation class to enable MTOM by specifying either javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING or javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING as the value for the annotation.
javax.xml.ws.RequestWrapper
This annotation annotates methods in the Service Endpoint Interface with the request wrapper bean to be used at runtime.
When starting from Java this annotation is used resolve overloading conflicts in document literal mode. Only the className is required in this case.
Example:
public interface AddNumbersImpl {
@WebMethod
@WebResult(targetNamespace = "")
@RequestWrapper(localName="addNumbers",
targetNamespace="http://server.fromjava/",
className="fromjava.client.AddNumbers")
@ResponseWrapper(localName="addNumbersResponse",
targetNamespace="http://server.fromjava/",
className="fromjava.client.AddNumbersResponse")
public int addNumbers(
@WebParam(name = "arg0", targetNamespace = "")
int arg0,
@WebParam(name = "arg1", targetNamespace = "")
int arg1);
}
javax.xml.ws.ResponseWrapper
This annotation annotates methods in the Service Endpoint Interface with the response wrapper bean to be used at runtime.
When starting from Java this annotation is used resolve overloading conflicts in document literal mode. Only the className is required in this case.
Example:
public interface AddNumbersImpl {
@WebMethod
@WebResult(targetNamespace="")
@RequestWrapper(localName="addNumbers",
targetNamespace="http://server.fromjava/",
className="fromjava.client.AddNumbers")
@ResponseWrapper(localName="addNumbersResponse",
targetNamespace="http://server.fromjava/",
className="fromjava.client.AddNumbersResponse")
public int addNumbers(
@WebParam(name = "arg0", targetNamespace = "")
int arg0,
@WebParam(name = "arg1", targetNamespace = "")
int arg1);
}
javax.xml.ws.ServiceMode
This annotation allows the Provider developer to indicate whether a Provider implementation wishes to work with entire protocol messages or just with protocol message payloads.
Example:
@WebServiceProvider(wsdlLocation="WEB-INF/wsdl/AddNumbers.wsdl")
@ServiceMode(value=Service.Mode.PAYLOAD)
public class AddNumbersImpl implements Provider<Source> {
public Source invoke(Source source) throws RemoteException {
try {
DOMResult dom = new DOMResult();
Transformer trans = TransformerFactory.newInstance().newTransformer();
trans.transform(source, dom);
Node node = dom.getNode();
Node root = node.getFirstChild();
Node first = root.getFirstChild();
int number1 = Integer.decode(first.getFirstChild().getNodeValue());
Node second = first.getNextSibling();
int number2 = Integer.decode(second.getFirstChild().getNodeValue());
return sendSource(number1, number2);
} catch(Exception e) {
e.printStackTrace();
throw new RemoteException("Error in provider endpoint");
}
}
private Source sendSource(int number1, int number2) {
int sum = number1+number2;
String body =
"<ns:addNumbersResponse xmlns:ns=\"http://duke.example.org\"><return>"
+sum
+"</return></ns:addNumbersResponse>";
Source source = new StreamSource(
new ByteArrayInputStream(body.getBytes()));
return source;
}
}
NOTE: The @ServiceMode annotation is only supported on classes that are annotated with the @WebServiceProvider annotation.
javax.xml.ws.WebEndpoint
Used to annotate the get PortName() methods of a generated service interface.
The information specified in this annotation is sufficient to uniquely identify a wsdl:port element inside a wsdl:service. The latter is determined based on the value of the @WebServiceClient annotation on the generated service interface itself.
Example:
@WebServiceClient(name="AddNumbersImplService",
targetNamespace="http://server.fromjava/",
wsdlLocation="http://localhost:8080/jaxws-fromjava/addnumbers?wsdl")
public class AddNumbersImplService extends Service {
private final static URL WSDL_LOCATION;
private final static QName ADDNUMBERSIMPLSERVICE =
new QName("http://server.fromjava/", "AddNumbersImplService");
private final static QName ADDNUMBERSIMPLPORT =
new QName("http://server.fromjava/", "AddNumbersImplPort");
static {
URL url = null;
try {
url = new URL("http://localhost:8080/jaxws-fromjava/addnumbers?wsdl");
} catch (MalformedURLException e) {
e.printStackTrace();
}
WSDL_LOCATION = url;
}
public AddNumbersImplService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public AddNumbersImplService() {
super(WSDL_LOCATION, ADDNUMBERSIMPLSERVICE);
}
/**
*
* @return
* returns AddNumbersImpl
*/
@WebEndpoint(name = "AddNumbersImplPort")
public AddNumbersImpl getAddNumbersImplPort() {
return (AddNumbersImpl)super.getPort(ADDNUMBERSIMPLPORT, AddNumbersImpl.class);
}
}
javax.xml.ws.WebFault
This annotation is generated by the JAX-WS tools into service specific exception classes generated from a WSDL to customize to the local and namespace name of the fault element and the name of the fault bean and to mark the service specific exception as one generated from WSDL. Developers should not use this annotation themselves. The reason that the JAX-WS needs to know if a service specific exception is generated from a WSDL or not is because these exceptions will already have a fault bean generated for them. The name of this fault bean is not the same name as on generated from a Java service specific exception class. For more information on this topic, please refer to section 3.6 of the JAX-WS 2.0 specification.
Example:
@javax.xml.ws.WebFault(name="AddNumbersException",
targetNamespace="http://server.fromjava/jaxws")
public class AddNumbersException_Exception extends Exception {
private fromjava.client.AddNumbersException faultInfo;
public AddNumbersException_Exception(String message, AddNumbersException faultInfo) {
super(message);
this.faultInfo = faultInfo;
}
public AddNumbersException_Exception(String message, AddNumbersException faultInfo, Throwable cause) {
super(message, cause);
this.faultInfo = faultInfo;
}
public fromjava.client.AddNumbersException getFaultInfo() {
return faultInfo;
}
}
This annotation can only be applied to a fault implementation class on the client or server.
javax.xml.ws.WebServiceClient
The information specified in this annotation is sufficient to uniquely identify a wsdl:service element inside a WSDL document. This wsdl:service element represents the Web service for which the generated service interface provides a client view.
Example:
@WebServiceClient(name="AddNumbersImplService",
targetNamespace="http://server.fromjava/",
wsdlLocation="http://localhost:8080/jaxws-fromjava/addnumbers?wsdl")
public class AddNumbersImplService extends Service {
private final static URL WSDL_LOCATION;
private final static QName ADDNUMBERSIMPLSERVICE =
new QName("http://server.fromjava/", "AddNumbersImplService");
private final static QName ADDNUMBERSIMPLPORT =
new QName("http://server.fromjava/", "AddNumbersImplPort");
static {
URL url = null;
try {
url = new URL("http://localhost:8080/jaxws-fromjava/addnumbers?wsdl");
} catch (MalformedURLException e) {
e.printStackTrace();
}
WSDL_LOCATION = url;
}
public AddNumbersImplService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public AddNumbersImplService() {
super(WSDL_LOCATION, ADDNUMBERSIMPLSERVICE);
}
/**
*
* @return
* returns AddNumbersImpl
*/
@WebEndpoint(name = "AddNumbersImplPort")
public AddNumbersImpl getAddNumbersImplPort() {
return (AddNumbersImpl)super.getPort(ADDNUMBERSIMPLPORT, AddNumbersImpl.class);
}
}
javax.xml.ws.WebServiceProvider
Annotation used to annotate a Provider implementation class.
Example:
@ServiceMode(value=Service.Mode.PAYLOAD)
@WebServiceProvider(wsdlLocation="WEB-INF/wsdl/AddNumbers.wsdl")
public class AddNumbersImpl implements Provider {
public Source invoke(Source source) {
try {
DOMResult dom = new DOMResult();
Transformer trans = TransformerFactory.newInstance().newTransformer();
trans.transform(source, dom);
Node node = dom.getNode();
Node root = node.getFirstChild();
Node first = root.getFirstChild();
int number1 = Integer.decode(first.getFirstChild().getNodeValue());
Node second = first.getNextSibling();
int number2 = Integer.decode(second.getFirstChild().getNodeValue());
return sendSource(number1, number2);
} catch(Exception e) {
e.printStackTrace();
throw new RuntimeException("Error in provider endpoint", e);
}
}
private Source sendSource(int number1, int number2) {
int sum = number1+number2;
String body = "" + sum + "";
Source source = new StreamSource(new ByteArrayInputStream(body.getBytes()));
return source;
}
}
NOTE:
A Java class that implements a Web service must specify either the @WebService or @WebServiceProvider annotation. Both annotations cannot be present.
The @WebServiceProvider annotation is only supported on the service implementation class.
Any class with the @WebServiceProvider annotation must implement the javax.xml.ws.Provider interface.
javax.xml.ws.WebServiceRef
The @WebServiceRef annotation is used to define a reference to a web service and (optionally) an injection target for it. Web service references are resources in the Java EE 5 sense.
Example:
import javax.xml.ws.WebServiceRef;
import com.techtip.jaxws.sample.CalculatorService;
import com.techtip.jaxws.sample.Calculator;
public class JAXWSClient {
@WebServiceRef(wsdlLocation="http://localhost:8080/CalculatorService?WSDL")
static CalculatorService service;
public void doTest() {
try {
Calculator port = service.getCalculatorPort();
int ret = port.add(2, 2);
} catch(Exception e) {
e.printStackTrace();
}
}
}
NOTE: The @WebServiceRef annotation can be used to inject instances of JAX-WS services and ports.
NOTE: The @WebServiceRef annotation is only supported in certain class types. Examples are JAX-WS endpoint implementation classes, JAX-WS handler classes, Enterprise JavaBeans classes, and servlet classes. This annotation is supported in the same class types as the @Resource annotation. See the Java Platform, Enterprise Edition (Java EE) 5 specification for a complete list of supported class types.
javax.xml.ws.Feature
The @Feature annotation is used to enable/disable a feature to use for a web service endpoint implementation class. This annotation is used with @BindingType annotation.
Here is a sample use of the @BindingType annotation that specifies use of the SOAP1.1/HTTP binding, it enables both the AddressingFeature and the MTOMFeature and also sets the threshold feature parameter on the MTOMFeature:
@BindingType(
value=SOAPBinding.SOAP11HTTP_BINDING,
features={
@Feature(AddressingFeature.ID),
@Feature(value=MTOMFeature.ID,
parameters={@FeatureParameter(name=MTOMFeature.THRESHOLD, value="1000")})
}
)
public class MyWebService {
...
}
javax.xml.ws.FeatureParameter
The @FeatureParameter annotation is used to specify paramaters for a feature. This annotation is used with @Feature.
javax.xml.ws.Action
The @Action annotation allows explicit association of Action message addressing property with input, output, and fault messages of the mapped WSDL operation.
This annotation can be specified on each method of a service endpoint interface or implementation. For such a method, the mapped operation in the generated WSDL contains explicit wsaw:Action attribute on the WSDL input, output and fault messages of the WSDL operation based upon which attributes of the Action annotation have been specified.
Example: Specify explicit values for Action message addressing property for input and output messages:
@javax.jws.WebService
public class AddNumbersImpl {
@javax.xml.ws.Action(
input="http://example.com/inputAction",
output="http://example.com/outputAction")
public int addNumbers(int number1, int number2) {
return number1 + number2;
}
}
The generated WSDL looks like:
<definitions targetNamespace="http://example.com/numbers" ...>
...
<portType name="AddNumbersPortType">
<operation name="AddNumbers">
<input message="tns:AddNumbersInput" name="Parameters" wsaw:Action="http://example.com/inputAction"/>
<output message="tns:AddNumbersOutput" name="Result" wsaw:Action="http://example.com/outputAction"/>
</operation>
<portType>
...
<definitions>
javax.xml.ws.FaultAction
The @FaultAction annotation is used inside an @Action annotation to allow an explicit association of Action message addressing property with the fault messages of the WSDL operation mapped from the exception class.
The fault message in the generated WSDL operation mapped for className class contains explicit wsaw:Action attribute.
Example: Specify explicit values for Action message addressing property for the input, output and fault message if the Java method throws only one service specific exception:
@javax.jws.WebService
public class AddNumbersImpl {
@javax.xml.ws.Action(
input="http://example.com/inputAction",
output="http://example.com/outputAction",
fault = {@javax.xml.ws.FaultAction(className=AddNumbersException.class,
value="http://example.com/faultAction")}
)
public int addNumbers(int number1, int number2) throws AddNumbersException {
return number1 + number2;
}
}
The generated WSDL looks like:
<definitions targetNamespace="http://example.com/numbers" ...>
...
<portType name="AddNumbersPortType">
<operation name="AddNumbers">
<input message="tns:AddNumbersInput" name="Parameters" wsaw:Action="http://example.com/inputAction"/>
<output message="tns:AddNumbersOutput" name="Result" wsaw:Action="http://example.com/outputAction"/>
<fault message="tns:AddNumbersException" name="AddNumbersException" wsaw:Action="http://example.com/faultAction"/>
</operation>
<portType>
...
<definitions>
|
|
|
|
Hosting provided by PerfoHost: KVM VPS. Unix VPS. Windows VPS. VPN. Domains. Dedicated servers. Colocation.