# Java TM API for XML Web Services
(JAX-WS)
Annotations

Specification Version: 2.2
Implementation Version: 2.2.5

- Overview
- Provider
- AsyncProvider
- Dispatch
- Asynchronous Client
- Handler
- MTOM and Swaref
- SOAP 1.2
- WSDL Customization
- Annotations
- WS-Addressing
- Stateful Webservice
- Catalog
- Interoperability

## Contents

    1. Overview
    2. JSR 181 (Web Services Metadata) Annotations
        2.1 javax.jws.WebService
        2.2 javax.jws.WebMethod
        2.3 javax.jws.OneWay
        2.4 javax.jws.WebParam
        2.5 javax.jws.WebResult
        2.6  javax.jws.HandlerChain
        2.7  javax.jws.soap.SOAPBinding
    3. JSR 224 (JAX-WS) Annotations
        3.1 javax.xml.ws.BindingType
        3.2 javax.xml.ws.RequestWrapper
        3.3 javax.xml.ws.ResponseWrapper
        3.4 javax.xml.ws.ServiceMode
        3.5 javax.xml.ws.WebEndpoint
        3.6 javax.xml.ws.WebFault
        3.7 javax.xml.ws.WebServiceClient
        3.8 javax.xml.ws.WebServiceProvider
        3.9 javax.xml.ws.WebServiceRef
        3.10 javax.xml.ws.Action
        3.11 javax.xml.ws.FaultAction
    4. JSR 222 (JAXB) Annotations
        4.1 javax.xml.bind.annotation.XmlRootElement
        4.2 javax.xml.bind.annotation.XmlAccessorType
        4.3 javax.xml.bind.annotation.XmlType
        4.4 javax.xml.bind.annotation.XmlElement
        4.5 javax.xml.bind.annotation.XmlSeeAlso
    5. JSR 250 (Common Annotations) Annotations
        5.1 javax.annotation.Resource
        5.2 javax.annotation.PostConstruct
        5.3 javax.annotation.PreDestroy

## 1. Overview

Annotations play a critical role in JAX-WS 2.2. First, annotations are used in mapping Java to WSDL and schema. Second, annotations are used a runtime to control how the JAX-WS runtime processes and responds to web service invocations. Currently the annotations utilized by JAXR-WS 2.0 are defined in separate JSRs:

- JSR 181: Web Services Metadata for the Java TM Platform

- JSR 222: Java TM Architecture for XML Binding (JAXB) 2.1

- JSR 224: Java TM API for XML Web Services (JAX-WS) 2.0 and 2.1

- JSR 250: Common Annotations for the Java TM Platform .

## 2. JSR 181 (Web Services Metadata) Annotations

Because JSR 181 has been written to work with JAX-RPC 1.1, we have made slight changes in the use and interpretation of these annotations to work better with JAX-WS 2.0. We are working with the 181 expert group to align the next release with JAX-WS 2.0 and we hope that all of the changes we have made will be folded in.

### 2.1 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.

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. If the implementation bean references a service endpoint interface, that service endpoint interface is used to determine the abstract WSDL contract (portType and bindings). In this case, the service implementation bean MUST NOT include any JSR-181 annotations other than @WebService and @HandlerChain. In addition, the @WebService annotation MUST NOT include the name annotation element. 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 | Not currently used by JAX-WS RI 2.2.5 |

#### Annotation Type Definition

    @Retention(value=RetentionPolicy.RUNTIME)
    @Target({TYPE})
    public @interface WebService {
        String name() default "";
        String targetNamespace() default "";
        String serviceName() default "";
        String wsdlLocation() default "";
        String endpointInterface() default "";
        String portName() default "";
    }

#### Example 1

    @WebService(name = "AddNumbers",
                targetNamespace = "http://duke.example.org", name="AddNumbers")
    public class AddNumbersImpl {
        /**
         * @param number1
         * @param number2
         * @return The sum
         * @throws AddNumbersException
         *             if any of the numbers to be added is negative.
         */
         public int addNumbers(int number1, int number2) throws AddNumbersException {
            if (number1 < 0 || number2 < 0) {
                throw new AddNumbersException("Negative number cant be added!",
                                             "Numbers: " + number1 + ", " + number2);
            }
            return number1 + number2;
         }
    }

If you are familiar with JAX-RPC 1.1, you will notice that the AddNumbersImpl implementation class does not implement a service endpoint interface. In JAX-WS 2.2 a 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 = "annotations.server.AddNumbersIF")
    public class AddNumbersImpl {
        /**
         * @param number1
         * @param number2
         * @return The sum
         * @throws AddNumbersException
         *             if any of the numbers to be added is negative.
         */
         public int addNumbers(int number1, int number2) throws AddNumbersException {
            if (number1 < 0 || number2 < 0) {
                throw new AddNumbersException("Negative number cant be added!",
                                             "Numbers: " + number1 + ", " + number2);
            }
            return number1 + number2;
         }
    }

    @WebService(targetNamespace = "http://duke.example.org", name="AddNumbers")
    public interface AddNumbersIF extends Remote {
        public int addNumbers(int number1, int number2) throws RemoteException, AddNumbersException;
    }

### 2.2 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.

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

#### Annotation Type Definition

    @Retention(value=RetentionPolicy.RUNTIME)
    @Target({METHOD})
    public @interface WebMethod {
        String operationName() default "";
        String action() default "";
        boolean exclude() default false;
    }

#### Example

    @WebService(targetNamespace = "http://duke.example.org", name="AddNumbers")
    public interface AddNumbersIF extends Remote {
        @WebMethod(operationName="add", action="urn:addNumbers")
        public int addNumbers(int number1, int number2) throws RemoteException, AddNumbersException;
    }

### 2.3 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.

There are no properties on the OneWay annotation.

#### Annotation Type Definition

    @Retention(value=RetentionPolicy.RUNTIME)
    @Target({METHOD})
       public @interface Oneway {
    }

#### Example

    @WebService(name="CheckIn")
    public class CheckInIF {
        @WebMethod
        @OneWay
        public void checkIn(String name);
    }

### 2.5 javax.jws.WebParam

This annotation is used to customize the mapping of a single parameter to a message part or element.

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.operation Name, if the operation is document style and the parameter style is BARE. Otherwise, the default is 20 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.operation Name, 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 | The XML namespace for the parameter. Only used if the operation is document style or the paramater maps to a header. If the target namespace is set to “”, this represents the empty namespace. | The empty namespace, if the operation is document style, the parameter style is WRAPPED, and the parameter does not map to a header. Otherwise, the default is the targetNamespace for the Web Service.
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 | Specifies whether the parameter should be carried in a header. | FALSE
partName | Used to specify the `partName` for the parameter with RPC or DOCUMENT/BARE operations. | `@WebParam.name`

#### Annotation Type Definition

    @Retention(value=RetentionPolicy.RUNTIME)
    @Target({PARAMETER})
    public @interface WebParam {

        public enum Mode {
            IN,
            OUT,
            INOUT
        };
        String name() default "";
        String targetNamespace() default "";
        Mode mode() default Mode.IN;
        boolean header() default false;
        String partName() default "";
    }

#### Example 1

    @WebService(targetNamespace = "http://duke.example.org", name="AddNumbers")
    public interface AddNumbersIF extends Remote {
        @WebMethod(operationName="add", action="urn:addNumbers")
        @WebResult(name="return")
        public int addNumbers(
            @WebParam(name="num1")int number1,
            @WebParam(name="num2")int number2) throws RemoteException, AddNumbersException;
    }

#### Example 2

    @WebService(targetNamespace = "http://duke.example.org", name="AddNumbers")
    public interface AddNumbersIF extends Remote {
        @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 RemoteException, AddNumbersException;
    }

### 2.5 javax.jws.WebResult

This annotation is used to customize the mapping of the method return value to a WSDL part or XML element.

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 | The XML namespace for the return value. Only used if the operation is document style or the return value maps to a header. If the target namespace is set to “”, this represents the empty namespace. | The empty namespace, if the operation is document style, the parameter style is WRAPPED, and the return value does not map to a header, Otherwise, the default is the targetNamespace for the Web Service.
header | Specifies whether the result should be carried in a header. | FALSE
partName | Used to specify the `partName` for the result with RPC or DOCUMENT/BARE operations. | `@WebResult.name`

#### Annotation Type Definition

    @Retention(value=RetentionPolicy.RUNTIME)
    @Target({METHOD})
    public @interface WebResult {

        String name() default "return";
        String targetNamespace() default "";
        boolean header() default false;
        String partName() default "";
    }

#### Example

    @WebService(targetNamespace = "http://duke.example.org", name="AddNumbers")
    public interface AddNumbersIF extends Remote {
        @WebMethod(operationName="add", action="urn:addNumbers")
        @WebResult(name="return")
        public int addNumbers(
            @WebParam(name="num1")int number1,
            @WebParam(name="num2")int number2) throws RemoteException, AddNumbersException;
    }

### 2.6 javax.jws.HandlerChain

This annotation is used to specified an externally defined handler chain.

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. | ""

#### Annotation Type Definition

    @Retention(value=RetentionPolicy.RUNTIME)
    @Target({TYPE})
    public @interface HandlerChain {
        String file();
        @Deprecated String name() = "";
    }

#### Example

    @WebService
    @HandlerChain( file="handlers.xml")
    public class AddNumbersImpl {
        /**
         * @param number1
         * @param number2
         * @return The sum
         * @throws AddNumbersException
         *     if any of the numbers to be added is negative.
         */
        public int addNumbers(int number1, int number2) throws AddNumbersException {
            if (number1 < 0 || number2 < 0) {
                throw new AddNumbersException("Negative number cant be added!",
                    "Numbers: " + number1 + ", " + 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>fromjavahandler.common.LoggingHandler</jws:handler-class>
                </jws:handler>
            </jws:handler-chain>
        </jws:handler-chains>
    </jws:handler-config>

IMPORTANT NOTE:

When using a handler chain file, it is important that the file is store in the appropriate place in the classpath so that the file can be found. This means that when a raw WAR file is created that the file must be place in the proper directory. Please refer to the fromjavahandlers sample application and the handlers documentation for more information.

### 2.7 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.2 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.

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.2 | 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

#### Annotation Type Definition

    @Retention(value=RetentionPolicy.RUNTIME)
    @Target({TYPE,METHOD})
    public @interface SOAPBinding {
        public enum Style {
           DOCUMENT,
           RPC,
        };
        public enum Use {
            LITERAL,
            ENCODED,
        };
        public enum ParameterStyle {
            BARE,
            WRAPPED,
        };
        Style style() default Style.DOCUMENT;
        Use use() default Use.LITERAL;
        ParameterStyle parameterStyle() default ParameterStyle.WRAPPED;
    }

#### Example

    @WebService(targetNamespace = "http://duke.example.org", name="AddNumbers")
    @SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.LITERAL)
    public interface AddNumbersIF extends Remote {
        @WebMethod(operationName="add", action="urn:addNumbers")
        @WebResult(name="return")
        public int addNumbers(
            @WebParam(name="num1")int number1,
            @WebParam(name="num2")int number2) throws RemoteException, AddNumbersException;
    }

## 3. JSR 224 (JAX-WS) Annotations

The following are standard annotations needed by JAX-WS that are not defined in 181. The developer may not ever use these annotations directly as some of them are generated by JAX-WS tools but they will be presented here to avoid confusion.

### 3.1 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.

Property | Description | Default
--- | --- | ---
value | A binding identifier (a URI). See the `SOAPBinding` and `HTTPBinding` for the definition of the standard binding identifiers.
    @see javax.xml.ws.Binding
    @see javax.xml.ws.soap.SOAPBinding#SOAP11HTTP_BINDING
    @see javax.xml.ws.soap.SOAPBinding#SOAP12HTTP_BINDING
    @see javax.xml.ws.http.HTTPBinding#HTTP_BINDING
| SOAP 1.1 / HTTP

#### Annotation Type Definition

    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    public @interface BindingType {
         /**
          * A binding identifier (a URI).
          * If not specified, the default is the SOAP 1.1 / HTTP binding.
          *
          * See the SOAPBinding and HTTPBinding
          * for the definition of the standard binding identifiers.
          *
          * @see javax.xml.ws.Binding
          * @see javax.xml.ws.soap.SOAPBinding#SOAP11HTTP_BINDING
          * @see javax.xml.ws.soap.SOAPBinding#SOAP12HTTP_BINDING
          * @see javax.xml.ws.http.HTTPBinding#HTTP_BINDING
          */
         String value() default "" ;

         /**
          * An array of Features to enable/disable on the specified binding.
          * If not specified, features will be enabled/disabled based
          * on their own rules. Refer to the documentation of the feature
          * to determine when it will be automatically enabled.
          *
          * See the SOAPBinding
          * for the definition of the standard feature identifiers.
          *
          * @see javax.xml.ws.RespectBindingFeature
          * @see javax.xml.ws.soap.AddressingFeature
          * @see javax.xml.ws.soap.MTOMFeature
          *
          * @since JAX-WS 2.1
          */
         Feature[] features() default {};
    }

}

#### Example

Example 1: Given the web service defined by

    @WebService
    @BindingType(value="http://www.w3.org/2003/05/soap/bindings/HTTP/")
    public class AddNumbersImpl {
        /**
         * @param number1
         * @param number2
         * @return The sum
         * @throws AddNumbersException
         *             if any of the numbers to be added is negative.
         */
         public int addNumbers(int number1, int number2) throws AddNumbersException {
             if (number1 < 0 || number2 < 0) {
                throw new AddNumbersException("Negative number cant be added!",
                                              "Numbers: " + number1 + ", " + number2);
            }
            return number1 + number2;
         }

The deployed endpoint would use the SOAP1.2 over HTTP binding.

### 3.2 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.

Property | Description | Default
--- | --- | ---
localName | Specifies the localName of the XML Schema element representing this request wrapper. | `operationName` as defined by `javax.jws.WebMethod`
targetNamespace | namespace of the request wrapper element | the `targetNamespace` of the SEI
className | The name of the Class representing the request wrapper |

#### Annotation Type Definition

    @Target({ElementType.TYPE})@Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface RequestWrapper {
      /**
       *  Elements local name.
      **/
      public String localName() default "";
      /**
       *  Elements namespace name.
      **/
      public String targetNamespace() default "";
      /**
       *  Request wrapper bean name.
      **/
      public String className() default "";
    }

#### Example

    public interface AddNumbersImpl {
        /**
         *
         * @param arg1
         * @param arg0
         * @return
         *     returns int
         * @throws AddNumbersException_Exception
         */
        @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)
            throws AddNumbersException_Exception;
    }

### 3.3 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.

Property | Description | Default
--- | --- | ---
localName | Specifies the localName of the XML Schema element representing this request wrapper. | `operationName` as defined by `javax.jws.WebMethod`
targetNamespace | namespace of the request wrapper element | the `targetNamespace` of the SEI
className | The name of the Class representing the request wrapper |

#### Annotation Type Definition

    @Target({ElementType.TYPE})@Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface ResponseWrapper {
      /**
       *  Elements local name.
      **/
      public String localName() default "";
      /**
       *  Elements namespace name.
      **/
      public String targetNamespace() default "";
      /**
       *  Request wrapper bean name.
      **/
      public String className() default "";
    }

#### Example

    public interface AddNumbersImpl {
        /**
         *
         * @param arg1
         * @param arg0
         * @return
         *     returns int
         * @throws AddNumbersException_Exception
         */
        @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)
            throws AddNumbersException_Exception;
    }

### 3.4 javax.xml.ws.ServiceMode

This annotation allows the Provider de veloper to to indicate whether a Provider implementation wishes to work with entire protocol messages or just with protocol message payloads.

Property | Description | Default
--- | --- | ---
value | Convey whether the Provider endpoint wants to access then entire message ( MESSAGE) or just the payload( PAYLOAD) | PAYLOAD

#### Annotation Type Definition

    @Target({ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)
    @Inherited
    public @interface ServiceMode {
      /**
       * Service mode. PAYLOAD indicates that the Provider implementation
       * wishes to work with protocol message payloads only. MESSAGE indicates
       * that the Provider implementation wishes to work with entire protocol
       * messages.
      **/
      public Service.Mode value() default Service.Mode.PAYLOAD;
    }

#### Example

    @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;
        }
    }

### 3.5 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.

Property | Description | Default
--- | --- | ---
name | Defines the local name of the XML element representing the corresponding port in the WSDL. | “”

#### Annotation Type Definition

    /**
     *  Used to annotate the getPortName()
     *  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.
     *
     *  @since JAX-WS 2.0
     *
     *  @see javax.xml.ws.WebServiceClient
    **/
    @Target({ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    public @interface WebEndpoint {
      /**
       *  The local name of the endpoint.
      **/
      String name() default "";
    }

#### 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);
        }
    }

### 3.6 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. 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 the one 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.

Property | Description | Default
--- | --- | ---
name | Defines the local name of the XML element representing the corresponding fault in the WSDL. | “”
targetNamespace | Defines the namespace of the XML element representing the corresponding fault in the WSDL. | “”
faultBean | The qualified name of the Java class that represents the detail of the fault message. | “”

#### Annotation Type Definition

    /**
     * Used to annotate service specific exception classes to customize
     * to the local and namespace name of the fault element and the name
     * of the fault bean.
     *
     *  @since JAX-WS 2.0
    **/
    @Target({ElementType.TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    public @interface WebFault {
      /**
       *  Elements local name.
      **/
      public String name() default "";
      /**
       *  Elements namespace name.
      **/
      public String targetNamespace() default "";
      /**
       *  Fault bean name.
      **/
      public String faultBean() default "";
    }

#### 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, fromjava.client.AddNumbersException faultInfo) {
            super(message);
            this.faultInfo = faultInfo;
        }
        public AddNumbersException_Exception(String message, fromjava.client.AddNumbersException faultInfo,
                                             Throwable cause) {
            super(message, cause);
            this.faultInfo = faultInfo;
        }
        public fromjava.client.AddNumbersException getFaultInfo() {
            return faultInfo;
        }
    }

### 3.7 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.

Property | Description | Default
--- | --- | ---
name | Defines the local name of the `wsdl:serviceName` in the WSDL. | “”
targetNamespace | Defines the namespace for the `wsdl:serviceName` in the WSDL. | “”
wsdlLocation | Specifies the location of the WSDL that defines this service. | “”

#### Annotation Type Definition

    /**
     *  Used to annotate a generated service interface.
     *
     *
    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.
     *
     *  @since JAX-WS 2.0
    **/
    @Target({ElementType.TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    public @interface WebServiceClient {
      /**
       *  The local name of the Web service.
      **/
      String name() default "";

      /**
       *  The namespace for the Web service.
      **/
      String targetNamespace() default "";

      /**
       *  The location of the WSDL document for the service (a URL).
      **/
      String wsdlLocation() default "";
    }

#### 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);
        }
    }

### 3.8 javax.xml.ws.WebServiceProvider

Annotation used to annotate a Provider implementation class.

Property | Description | Default
--- | --- | ---
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”
portName | The `wsdl:portName` |
wsdlLocation | Location of the WSDL description for the service |

#### Annotation Type Definition

    /**
     * Used to annotate a Provider implementation class.
     *
     * @since JAX-WS 2.0
     * @see javax.xml.ws.Provider
     */
    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface WebServiceProvider {
        /**
         * Location of the WSDL description for the service.
         */
        String wsdlLocation() default "";

        /**
         * Service name.
         */
        String serviceName() default "";

        /**
         * Target namespace for the service
         */
        String targetNamespace() default "";
        /**
         * Port name.
         */
        String portName() default "";
    }

#### 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;
        }
    }

### 3.9 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.

Property | Description | Default
--- | --- | ---
name | The JNDI name of the resource. For field annotations, the default is the field name. For method annotations, the default is the JavaBeans property name corresponding to the method. For class annotations, there is no default and this must be specified. |
type | The Java type of the resource. For field annotations, the default is the type of the field. For method annotations, the default is the type of the JavaBeans property. For class annotations, there is no default and this must be specified. |
mappedName | A product specific name that this resource should be mapped to. |
value | The service class, always a type extending `javax.xml.ws.Service`. This element must be specified whenever the type of the reference is a service endpoint interface. |
wsdlLocation | Location of the WSDL description for the service |

#### Annotation Type Definition

    /**
     *  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.
     *
     *  @see javax.annotation.Resource
     *
     *  @since JAX-WS 2.0
     *
    **/
    @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
    @Retention(RetentionPolicy.RUNTIME)
    public @interface WebServiceRef {
         /**
          * The JNDI name of the resource.  For field annotations,
          * the default is the field name.  For method annotations,
          * the default is the JavaBeans property name corresponding
          * to the method.  For class annotations, there is no default
          * and this must be specified.
          */
         String name() default "";
         /**
          * The Java type of the resource.  For field annotations,
          * the default is the type of the field.  For method annotations,
          * the default is the type of the JavaBeans property.
          * For class annotations, there is no default and this must be
          * specified.
          */
         Class type() default Object.class ;
         /**
          * A product specific name that this resource should be mapped to.
          * The name of this resource, as defined by the name
          * element or defaulted, is a name that is local to the application
          * component using the resource.  (It's a name in the JNDI
          * java:comp/env namespace.)  Many application servers
          * provide a way to map these local names to names of resources
          * known to the application server.  This mapped name is often a
          * global JNDI name, but may be a name of any form.

          *
          * Application servers are not required to support any particular
          * form or type of mapped name, nor the ability to use mapped names.
          * The mapped name is product-dependent and often installation-dependent.
          * No use of a mapped name is portable.
          */
         String mappedName() default "";

         /**
          * The service class, always a type extending
          * javax.xml.ws.Service. This element must be specified
          * whenever the type of the reference is a service endpoint interface.
          */
         Class value() default Object.class ;
         /**
          * A URL pointing to the WSDL document for the web service.
          * If not specified, the WSDL location specified by annotations
          * on the resource type is used instead.
          */
         String wsdlLocation() default "";
    }

### 3.12 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.

Property | Description | Default
--- | --- | ---
input | Explicit value of `Action` message addressing property for the `input` message of the operation. If the value is "", then no `wsaw:Action` is generated. | “”
ouput | Explicit value of `Action` message addressing property for the `output` message of the operation. If the value is "", then no `wsaw:Action` is generated. | “”
fault | Explicit value of `Action` message addressing property for the `fault` message(s) of the operation. Each exception that is mapped to a fault and requires explicit `Action` message addressing property, need to be specified as a value in this property using FaultAction annotation. | {}

#### Annotation Type Definition

    @Documented
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.METHOD)
    public @interface Action {
        /**
         * Explicit value of Action message addressing property for the input
         * message of the operation. If the value is "", then no wsaw:Action
         * is generated.
         */
        String input() default "";

        /**
         * Explicit value of Action message addressing property for the output
         * message of the operation. If the value is "", then no wsaw:Action
         * is generated.
         */
        String output() default "";

        /**
         * Explicit value of Action message addressing property for the fault
         * message(s) of the operation. Each exception that is mapped to a fault and requires explicit
         * Action message addressing property, need to be specified as a value in this property
         * using FaultAction annotation.
         */
        FaultAction[] fault() default { };
    }

#### Example

Example 1: 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>

Example 2: Specify explicit value for `Action` message addressing property for only the `input` message. The default values are used for the `output` message.

      @javax.jws.WebService
      public class AddNumbersImpl {
          @javax.xml.ws.Action(input="http://example.com/inputAction")
          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"/>
            </operation>
          <portType>
        ...
        <definitions>

    It is legitimate to specify an explicit value for Action message addressing property for output message only. In this case, a default value of wsaw:Action is used
      for the input message.

Example 3: See @FaultAction for an example of how to specify an explicit value for `Action` message addressing property for the `fault` message. @see FaultAction

### 3.13 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.

Property | Description | Default
--- | --- | ---
className | Name of the exception class | there is no default and is required.
value | Value of `Action` message addressing property for the exception | “”

#### Annotation Type Definition

    @Documented
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.METHOD)
    public @interface FaultAction {
        /**
         * Name of the exception class
         */
        Class className();

        /**
         * Value of Action message addressing property for the exception
         */
        String value() default "";
    }

#### Example

Example 1: 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>

Example 2: Here is an example that shows how to specify explicit values for `Action` message addressing property if the Java method throws only one service specific exception, without specifying the values for `input` and `output` messages.

      @javax.jws.WebService
      public class AddNumbersImpl {
          @javax.xml.ws.Action(
              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"/>
              <output message="tns:AddNumbersOutput" name="Result"/>
              <fault message="tns:addNumbersFault" name="InvalidNumbers"
                wsa:Action="http://example.com/addnumbers/fault"/>
            </operation>
          <portType>
        ...
        <definitions>

Example 3: Here is an example that shows how to specify explicit values for `Action` message addressing property if the Java method throws more than one service specific exception.

      @javax.jws.WebService
      public class AddNumbersImpl {
          @javax.xml.ws.Action(
              fault = {
                  @javax.xml.ws.FaultAction(className=AddNumbersException.class, value="http://example.com/addFaultAction")
                  @javax.xml.ws.FaultAction(className=TooBigNumbersException.class, value="http://example.com/toobigFaultAction")
              })
          public int addNumbers(int number1, int number2)
              throws AddNumbersException, TooBigNumbersException {
              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"/>
              <output message="tns:AddNumbersOutput" name="Result"/>
              <fault message="tns:addNumbersFault" name="AddNumbersException"
                wsa:Action="http://example.com/addnumbers/fault"/>
              <fault message="tns:tooBigNumbersFault" name="TooBigNumbersException"
                wsa:Action="http://example.com/toobigFaultAction"/>
            </operation>
          <portType>
        ...
        <definitions>

## 4. JSR 222 (JAXB) Annotations

The following JAXB annotations are being documented because JAX-WS generates them when generating wrapper beans and exception beans according to the JAX-WS 2.0 spec. Please refer to sections 3.5.2.1 and 3.6 of the JAX-WS 2.0 specification for more information on these beans. For more information on these and other JAXB annotations please refer to the JAXB 2.0 specification.

### 4.1 javax.xml.bind.annotation.XmlRootElement

This annotation is used to map a top level class to a global element in the XML schema used by the WSDL of the web service.

Property | Description | Default
--- | --- | ---
name | Defines the local name of the XML element representing the annotated class |
    "##default" – the name is derived from the class
namespace | Defines the namespace of the XML element representing the annotated class | "##default" – the namespace is derived from the package of the class

#### Annotation Type Definition

    @Retention(RUNTIME)
    @Target({TYPE})
    public @interface XmlRootElement {
        /**
         * namespace name of the XML element.
         *
         * If the value is "##default", then the XML namespace name is derived
         * from the package of the class ( {@link XmlSchema} ). If the
         * package is unnamed, then the XML namespace is the default empty
         * namespace.
         */
        String namespace() default "##default";
        /**
         * local name of the XML element.
         *
         * If the value is "##default", then the name is derived from the
         * class name.
         *
         */
        String name() default "##default";
    }

#### Example

    @XmlRootElement(name = "addNumbers", namespace = "http://server.fromjava/")
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "addNumbers", namespace = "http://server.fromjava/", propOrder = {
        "arg0",
        "arg1"
    })
    public class AddNumbers {

        @XmlElement(name = "arg0", namespace = "")
        private int arg0;
        @XmlElement(name = "arg1", namespace = "")
        private int arg1;

        public int getArg0() {
            return this.arg0;
        }

        public void setArg0(int arg0) {
            this.arg0 = arg0;
        }

        public int getArg1() {
            return this.arg1;
        }

        public void setArg1(int arg1) {
            this.arg1 = arg1;
        }
    }

### 4.2 javax.xml.bind.annotation.XmlAccessorType

This annotation is used to specify whether fields or properties are serialized by default.

Property | Description | Default
--- | --- | ---
value | Specifies whether fields or properties are serialized by default. The value can be XmlAccessType.FIELD or XmlAccessType.PROPERTY or XmlAccessType.PUBLIC_MEMBER or XmlAccessType.NONE | XmlAccessType.PROPERTY

#### Annotation Type Definition

    @Inherited @Retention(RUNTIME) @Target({PACKAGE, TYPE})
    public @interface XmlAccessorType {

        /**
         * Specifies whether fields or properties are serialized.
         *
         * @see XmlAccessType
         */
        XmlAccessType value() default XmlAccessType.PUBLIC_MEMBER;
    }
    /**
     * Used by XmlAccessorType to control serialization of fields or
     * properties.
     *
     */

    public enum XmlAccessType {
        /**
         * Every getter/setter pair in a JAXB-bound class will be automatically
         * bound to XML, unless annotated by {@link XmlTransient}.
         *
         * Fields are bound to XML only when they are explicitly annotated
         * by some of the JAXB annotations.
         */
        PROPERTY,
        /**
         * Every non static, non transient field in a JAXB-bound class will be automatically
         * bound to XML, unless annotated by {@link XmlTransient}.
         *
         * Getter/setter pairs are bound to XML only when they are explicitly annotated
         * by some of the JAXB annotations.
         */
        FIELD,
        /**
         * Every public getter/setter pair and every public field will be
         * automatically bound to XML, unless annotated by {@link XmlTransient}.
         *
         * Fields or getter/setter pairs that are private, protected, or
         * defaulted to package-only access are bound to XML only when they are
         * explicitly annotated by the appropriate JAXB annotations.
         */
        PUBLIC_MEMBER,
        /**
         * None of the fields or properties is bound to XML unless they
         * are specifically  annotated with some of the JAXB annotations.
         */
        NONE
    }

#### Example

    @XmlRootElement(name = "addNumbers", namespace = "http://server.fromjava/")
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "addNumbers", namespace = "http://server.fromjava/", propOrder = {
        "arg0",
        "arg1"
    })
    public class AddNumbers {

        @XmlElement(name = "arg0", namespace = "")
        private int arg0;
        @XmlElement(name = "arg1", namespace = "")
        private int arg1;

        public int getArg0() {
            return this.arg0;
        }

        public void setArg0(int arg0) {
            this.arg0 = arg0;
        }

        public int getArg1() {
            return this.arg1;
        }

        public void setArg1(int arg1) {
            this.arg1 = arg1;
        }
    }

### 4.3 javax.xml.bind.annotation.XmlType

This annotation is used to map a value class to an XML Schema type. A value class is a data container for values represented by properties and fields. A schema type is a data container for values represented by schema components within a schema type's content model (e.g. Model groups, attributes etc).

Property | Description | Default
--- | --- | ---
name | Defines the local name of the XML type representing this class in the XML schema used by the WSDL of the web service | "##default"
namespace | Defines the namespace of the XML type representing this class in the XML schema used by the WSDL of the web service | "##default"
propOrder | Defines a list of names of JavaBean properties in the class. Each name in the list is the name of a Java identifier of the JavaBean property. The order in which JavaBean properties are listed is the order of XML Schema elements to which the JavaBean properties are mapped. All of the JavaBean properties being mapped must be listed (i.e. if a JavaBean property mapping is prevented by @XmlTransient, then it does not have to be listed). Otherwise, it is an error. By default, the JavaBean properties are ordered using a default order specified in the JAXB 2.0 specification. | {“”}

#### Annotation Type Definition

    @Retention(RUNTIME) @Target({TYPE})
    public @interface XmlType {
        /**
         * Name of the XML Schema type which the class is mapped.
         */
        String name() default "##default" ;

        /**
         * Specifies the order for XML Schema elements when class is
         * mapped to a XML Schema complex type.
         *
         *  Refer to the table for how the propOrder affects the
         * mapping of class
         *
         *  The propOrder is a list of names of JavaBean properties in
         *     the class. Each name in the list is the name of a Java
         *     identifier of the JavaBean property. The order in which
         *     JavaBean properties are listed is the order of XML Schema
         *     elements to which the JavaBean properties are mapped.
         *  All of the JavaBean properties being mapped to XML Schema elements
         *     must be listed.
         *  A JavaBean property or field listed in propOrder must not
         *     be transient or annotated with @XmlTransient.
         *  The default ordering of JavaBean properties is determined
         *     by @{@link XmlAccessorOrder}.
         */
        String[] propOrder() default {""};

        /**
         * Name of the target namespace of the XML Schema type. By
         * default, this is the target namespace to which the package
         * containing the class is mapped.
         */
        String namespace() default "##default" ;

        /**
         * Class containing a no-arg factory method for creating an
         * instance of this class. The default is this class.
         *
         * If factoryClass is DEFAULT.class and
         * factoryMethod is "", then there is no static factory
         * method.
         *
         * If factoryClass is DEFAULT.class and
         * factoryMethod is not "", then
         * factoryMethod is the name of a static factory method
         * in this class.
         *
         * If factoryClass is not DEFAULT.class, then
         * factoryMethod must not be "" and must be the name of
         * a static factory method specified in factoryClass.
         */
        Class factoryClass() default DEFAULT.class;

        /**
         * Used in {@link XmlType#factoryClass()} to
         * signal that either factory mehod is not used or
         * that it's in the class with this {@link XmlType} itself.
         */
        static final class DEFAULT {}

        /**
         * Name of a no-arg factory method in the class specified in
         * factoryClass factoryClass().
         *
         */
        String factoryMethod() default "";
    }

#### Example

    @XmlRootElement(name = "addNumbers", namespace = "http://server.fromjava/")
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "addNumbers", namespace = "http://server.fromjava/", propOrder = {
        "arg0",
        "arg1"
    })
    public class AddNumbers {

        @XmlElement(name = "arg0", namespace = "")
        private int arg0;
        @XmlElement(name = "arg1", namespace = "")
        private int arg1;

        public int getArg0() {
            return this.arg0;
        }

        public void setArg0(int arg0) {
            this.arg0 = arg0;
        }

        public int getArg1() {
            return this.arg1;
        }

        public void setArg1(int arg1) {
            this.arg1 = arg1;
        }
    }

### 4.4 javax.xml.bind.annotation.XmlElement

This annotation is used to map a property contained in a class to a local element in the XML Schema complex type to which the containing class is mapped.

Property | Description | Default
--- | --- | ---
name | Defines the local name of the XML element representing the property of a JavaBean | "##default” - the element name is derived from the JavaBean property name.
namespace | Defines the namespace of the XML element representing the property of a JavaBean | "##default” - the namespace of the containing class
nillable | Not generated by JAX-WS |
type | Not generated by JAX-WS |

#### Annotation Type Definition

    @Retention(RUNTIME) @Target({FIELD, METHOD})
    public @interface XmlElement {
        /**
         * Name of the XML Schema element.
         *  If the value is "##default", then element name is derived from the
         * JavaBean property name.
         */
        String name() default "##default";

        /**
         * Customize the element declaration to be nillable.
         * If nillable() is true, then the JavaBean property is
         * mapped to a XML Schema nillable element declaration.
         */
        boolean nillable() default false;

        /**
         * Customize the element declaration to be required.
         * If required() is true, then Javabean property is mapped to
         * an XML schema element declaration with minOccurs="1".
         * maxOccurs is "1" for a single valued property and "unbounded"
         * for a multivalued property.
         * If required() is false, then the Javabean property is mapped
         * to XML Schema element declaration with minOccurs="0".
         * maxOccurs is "1" for a single valued property and "unbounded"
         * for a multivalued property.
         */

        boolean required() default false;

        /**
         * XML target namespace of the XML Schema element.
         *
         * If the value is "##default", then the namespace is determined
         * as follows:
         *
         *
         *  If the enclosing package has {@link XmlSchema} annotation,
         *  and its {@link XmlSchema#elementFormDefault() elementFormDefault}
         *  is {@link XmlNsForm#QUALIFIED QUALIFIED}, then the namespace of
         *  the enclosing class.
         *
         *
         *  Otherwise "" (which produces unqualified element in the default
         *  namespace.
         *
         */
        String namespace() default "##default";

        /**
         * Default value of this element.
         *
         *
         * The '\u0000' value specified as a default of this annotation element
         * is used as a poor-man's substitute for null to allow implementations
         * to recognize the 'no default value' state.
         */
        String defaultValue() default "\u0000";

        /**
         * The Java class being referenced.
         */
        Class type() default DEFAULT.class;

        /**
         * Used in {@link XmlElement#type()} to
         * signal that the type be inferred from the signature
         * of the property.
         */
        static final class DEFAULT {}
    }

#### Example

    @XmlRootElement(name = "addNumbers", namespace = "http://server.fromjava/")
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "addNumbers", namespace = "http://server.fromjava/", propOrder = {
        "arg0",
        "arg1"
    })
    public class AddNumbers {

        @XmlElement(name = "arg0", namespace = "")
        private int arg0;
        @XmlElement(name = "arg1", namespace = "")
        private int arg1;

        public int getArg0() {
            return this.arg0;
        }

        public void setArg0(int arg0) {
            this.arg0 = arg0;
        }

        public int getArg1() {
            return this.arg1;
        }

        public void setArg1(int arg1) {
            this.arg1 = arg1;
        }
    }

### 4.5 javax.xml.bind.annotation.XmlSeeAlso

Instructs JAXB to also bind other classes when binding this class.

Property | Description | Default
--- | --- | ---
value | Other classes that JAXB can use when binding this class | {}

#### Annotation Type Definition

    /**
       * Instructs JAXB to also bind other classes when binding this class.
       *
       * Java makes it impractical/impossible to list all sub-classes of
       * a given class. This often gets in a way of JAXB users, as it JAXB
       * cannot automatically list up the classes that need to be known
       * to {@link JAXBContext}.
       *
       * For example, with the following class definitions:
       *
       *
       * class Animal {}
       * class Dog extends Animal {}
       * class Cat extends Animal {}
       *
       *
       * The user would be required to create {@link JAXBContext} as
       * JAXBContext.newInstance(Dog.class,Cat.class)
       * (Animal will be automatically picked up since Dog
       * and Cat refers to it.)
       *
       * {@link XmlSeeAlso} annotation would allow you to write:
       *
       * @XmlSeeAlso({Dog.class,Cat.class})
       * class Animal {}
       * class Dog extends Animal {}
       * class Cat extends Animal {}
       *
       *
       * This would allow you to do JAXBContext.newInstance(Animal.class).
       * By the help of this annotation, JAXB implementations will be able to
       * correctly bind Dog and Cat.
       *
       */
      @Target({ElementType.TYPE})
      @Retention(RUNTIME)
      public @interface XmlSeeAlso {
          Class[] value();p;  Class[] value();
      }

## 5. JSR 250 (Common Annotations) Annotations

The following annotations are being documented because JAX-WS endpoints use them for resource injection, and as lifecycle methods. Please refer to sections 5.2.1 and 5.3 of the JAX-WS 2.0 specification for resource injection, and lifecycle management. For more information on these and other common annotations please refer to the

JSR 250: Common Annotations for the Java TM Platform .

### 5.1 javax.annotation.Resource

This annotation is used to mark a WebServiceContext resource that is needed by a web service. It is applied to a field or a method for JAX-WS endpoints. The container will inject an instance of the WebServiceContext resource into the endpoint implementation when it is initialized.

Property | Description | Default
--- | --- | ---
type | Java type of the resource | For field annotations, the default is the type of the field. For method annotations, the default is the type of the JavaBeans property.

#### Annotation Type Definition

    @Target({TYPE, FIELD, METHOD})
    @Retention(RUNTIME)
    public @interface Resource {
        ...
     /**
         * The Java type of the resource. For field annotations,
         * the default is the type of the field. For method annotations,
         * the default is the type of the JavaBeans property.
         * For class annotations, there is no default and this must be
         * specified.
         */
     Class type() default java.lang.Object.class;
    }

#### Example

    @WebService
    public class HelloImpl {
     @Resource
        private WebServiceContext context;
     public String echoHello(String name) {
          ...
        }
    }

### 5.2 javax.annotation.PostConstruct

This annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization. This method MUST be invoked before the class is put into service.

#### Annotation Type Definition

    @Documented
    @Retention (RUNTIME)
    @Target(METHOD)
    public @interface PostConstruct {
    }ONT>

#### Example

    @WebService
    public class HelloImpl {
     @PostConstruct
        private void init() {
            ...
        }
     public String echoHello(String name) {
            ...
        }
    }

### 5.3 javax.annotation.PreDestroy

The PreDestroy annotation is used on methods as a callback notification to signal that the instance is in the process of being removed by the container. The method annotated with PreDestroy is typically used to release resources that it has been holding.

#### Annotation Type Definition

    @Documented
    @Retention(value=RUNTIME)
    @Target(value=METHOD)
    public @interface PreDestory {
    }

#### Example

    @WebService
    public class HelloImpl {
     public String echoHello(String name) {
            ...
        }
     @PreDestroy
        private void release() {
            ...
        }
    }