JAX-WS 2.0 Annotations

JAX-WS 2.0 Annotations

@WebService

This annotation marks either a Java class or a service endpoint interface (SEI) as implementing a Web service interface.

// 该注释声明这个类或者是服务终端接口实现了联网服务接口//

This annotation is applicable for a client or server SEI;

// 可以用在客户端或者服务器的服务终端接口

or for a service endpoint implementation class for a JavaBeans endpoint.

//或者是一个JavaBean的服务终端的实现类

Three of the properties of the annotation can be used only with a service endpoint implementation class for a JavaBeans endpoint.

These properties are serviceName, portName, and endpointInterface.

//该注释的三个属性(serviceName , portName, endpointInterface) 只能用于一个javaBean终端的服务终端实现类

@WebService(endpointInterface = “com.ws.WService0001”) // 这里声明后的属性指出接口是com.ws.WService0001 虽然bean 已经 implements WService0001 但是因为规定和方便生成WSDL 这里要写明

/**
 * 这里是一个JavaBean
 */

public class WSBean0001 implements WService0001 {

@Override
       public String getTimeAsString() { return new Date().toString(); }
@Override
       public long getTimeAsElapsed() { return new Date().getTime(); }

}

/**

这个是SEI 

*/

@WebService (这个注释指出这是一个WS)
@SOAPBinding(style = Style.RPC) (SOAP的一些定义,目前不用关心)

public interface WService0001 {

@WebMethod()String getTimeAsString();
@WebMethod()long getTimeAsElapsed();

}

If the annotation references an SEI through theendpointInterfaceattribute, then the SEI must also have the @WebService annotation.

//如果注释通过(endpointInterface 属性)指向了一个SEI, 那么这个SEI必须带有@WebService (参考上例)

By default, all public methods in a class that specifies the @WebService annotation are exposed in the Web service.

//正常情况下 该类所有public方法都会曝露出来

Annotation target: Type 注释目标 : 类的类型

Properties: 属性

  • name
    The name of thewsdl:portType. Thenameproperty maps to an SEI or a Java implementation class. The default value is the unqualified name of the Java interface or class. (String)
    name 标签 WSDL:PortType的名称

    *

    <wsdl:documentation .... />?
    <wsdl:port name="nmtoken" binding="qname"> *  
          <wsdl:documentation .... /> ?
       <-- extensibility element -->
    </wsdl:port>
    <-- extensibility element -->
    

  • targetNamespace(目标命名空间)

Specifies the XML namespace of the WSDL and XML elements that are generated from the Web service.
If the @WebService.targetNamespace annotation is on a service endpoint interface, the targetNamespace is used for the namespace for the wsdl:portType (and associated XML elements).

If the @WebService.targetNamespace annotation is on a service implementation bean that does not reference a service endpoint interface (through the endpointInterface annotation element), the targetNamespace is used for both the wsdl:portType and the wsdl:service (and associated XML elements).

If the @WebService.targetNamespace annotation is on a service implementation bean that does reference a service endpoint interface (through the endpointInterface annotation element), the targetNamespace is used for only the wsdl:service (and associated XML elements).

The default value is the namespace mapped from the package name that contains the Web service. (String)

  • serviceName
    Specifies the service name of the Web service:wsdl:service. This property is not allowed on endpoint interfaces. The default value is the simple name of the Java class + Service. (String)
  • endpointInterface
    Specifies the qualified name of the service endpoint interface that defines the services' abstract Web service contract. If specified, the service endpoint interface is used to determine the abstract WSDL contract. (String)
  • portName
    Thewsdl:portName. TheportNameproperty is the name of the endpoint port. The default value is WebService.name +Port . (String)
  • wsdlLocation
    Specifies the Web address of the WSDL document that defines the Web service. The Web address is either relative or absolute. (String)
    @WebMethod

This annotation denotes a method that is a Web service operation.

You can apply this annotation to public methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a JavaBeans endpoint.

Important:

The @WebMethod annotation is only supported on classes that have the @WebService annotation.

Annotation target: Method

Properties:

  • operationName
    Specifies the name of thewsdl:operationthat matches this method. The default value is the name of the Java method. (String)
  • action
    Defines the action for this operation. For SOAP bindings, this value determines the value of the SOAPAction header. (String)
  • exclude
    Specifies whether to exclude a method from the Web service. This property can be used only with an implementation class. Used to stop an inherited method from being exposed as part of this web service. If this element is specified, other elements must not be specified for the @WebMethod. This property is not allowed on endpoint interfaces.
    The default value isfalse. (Boolean)

@Oneway

This annotation denotes a method as a one-way operation for a Web service. It has an input message but no output message. This annotation can be used only on methods that have no return value.

You can apply this annotation to public methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a JavaBeans endpoint.

Annotation target: Method

There are no properties on the OneWay annotation.

@WebParam

This annotation customizes the mapping of an individual parameter to a Web service message part and XML element.

You can apply this annotation to public methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a JavaBeans endpoint.

Annotation target: Parameter

Properties:

  • name
    If the operation is remote procedure call (RPC) style and thepartNameattribute is not specified, then this is the name of thewsdl:partattribute that represents the parameter. If the operation is document style or the parameter maps to a header, thennameis the local name of the XML element that represents the parameter. This attribute is required if the operation is document style, the parameter style isBARE, and the mode isOUTorINOUT. If thepartNameattribute is specified, then thenameattribute is ignored. (String)
  • partName
    Defines the name ofwsdl:partattribute that represents this parameter. Use this only if the operation is RPC style, or the operation is document style and the parameter style isBARE. (String)
  • targetNamespace
    Specifies the XML namespace of the XML element for the parameter. It applies only for document bindings when the attribute maps to an XML element. The default value is thetargetNamespacefor the Web service. (String)
  • mode
    The value represents the direction the parameter flows for this method. Valid values areIN,INOUT, andOUT. (String)
  • header
    Specifies whether the parameter is in a message header rather than a message body. The default value isfalse. (Boolean)
    @WebResult

This annotation customizes how a return value maps to a WSDL part or XML element.

You can apply this annotation to public methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a JavaBeans endpoint.

Annotation target: Method

Properties:

  • name
    Specifies the name of the return value as it is listed in the WSDL file and found in messages on the wire. For RPC bindings, this is the name of thewsdl:partattribute that represents the return value. For document bindings, thenameparameter is the local name of the XML element that represents the return value. The default value isreturnfor RPC and DOCUMENT/WRAPPED bindings. The default value is the method name +Responsefor DOCUMENT/BARE bindings. (String)
  • targetNamespace
    Specifies the XML namespace for the return value. Use this annotation only for document bindings when the return value maps to an XML element. The default value is the targetNamespace for the Web service. (String)
  • header
    Specifies whether the result is carried in a header. The default value isfalse. (String)
  • partName
    Specifies the part name for the result with RPC or DOCUMENT/BARE operations. The default value [email protected]. (Boolean)

@HandlerChain

This annotation associates the Web service to an externally-defined handler chain. You can use this annotation if the handler configuration must be shared across multiple Web services, and embedding handler configuration in the application source is inefficient.

Apply this annotation to a client or server Service Endpoint Interface (SEI), or to a service endpoint implementation class for a JavaBeans endpoint.

Annotation target: Type

Properties:

  • file
    Specifies the location of the handler chain file. The file location is either an absolute java.net.URL in external form or a relative path from the source or class file. (String)
  • name
    Specifies the name of the handler chain in the configuration file. (String)
    @SOAPBinding

This annotation specifies the mapping of the Web service onto the SOAP message protocol.

You can apply this annotation to a type or public methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a Java beans endpoint.

The method-level annotation is limited by what it can specify. Use the annotation only if thestyleproperty has the valueDOCUMENT. If the method-level annotation is not specified, the @SOAPBinding behavior from the type is used.

Annotation target: Type or Method

Properties:

  • style
    Defines encoding style for messages sent to and from the Web service. The valid values areDOCUMENTandRPC. The default value isDOCUMENT. (String)
  • use
    Defines the encoding used for messages sent to and from the Web service. The default value isLITERAL.ENCODEDis not a supported value. (String)
  • parameterStyle
    Determines whether the method's parameters represent the entire message body, or if the parameters are elements wrapped inside a top-level element named after the operation. Valid values areWRAPPEDorBARE. You can only use theBAREvalue withDOCUMENTstyle bindings. The default value isWRAPPED. (String)

@BindingType

This annotation specifies which binding to use when publishing an endpoint of this type. If the annotation is not specified, the default value is SOAP11_HTTP_BINDING.
You can apply this annotation to a JavaBeans implementation class for a service endpoint that is based on the Service Endpoint Interface or the Provider interface.

Important:

Use the @BindingType annotation on the JavaBeans endpoint implementation class to enable Message Transmission Optimization Mechanism (MTOM), by specifying eitherSOAP11_HTTP_MTOM_BINDINGorSOAP12_HTTP_MTOM_BINDINGas the value for the annotation.

Annotation target: Type

Properties:

  • value
    Indicates the binding identifier Web address. (String)
    @RequestWrapper

This annotation supplies the JAXB generated request wrapper bean, the element name, and the namespace for serialization and deserialization with the request wrapper bean that is used at runtime.
When starting with a Java object, this element is used to resolve overloading conflicts in document literal mode. Only theclassNameattribute is required in this case.

This annotation can be applied to methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a JavaBeans endpoint.

Annotation target: Method

Properties:

  • localName
    Specifies the local name of the XML schema element that represents the request wrapper. The default value is theoperationNameas defined in javax.jws.WebMethod annotation. (String)
  • targetNamespace
    Specifies the XML namespace of the request wrapper method. The default value is the target namespace of the SEI. (String)
  • className
    Specifies the name of the class that represents the request wrapper. (String)
    @ResponseWrapper

This annotation supplies the JAXB-generated response wrapper bean, the element name, and the namespace for serialization and deserialization with the response wrapper bean that is used at runtime.
When starting with a Java object, use this element to resolve overloading conflicts while in document literal mode. Only theclassNameattribute is required in this case.

You can apply this annotation to methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a Java beans endpoint.

Annotation target: Method

Properties:

  • localName
    Specifies the local name of the XML schema element that represents the request wrapper. The default value is theoperationName+response.operationNameis defined in javax.jws.WebMethod annotation. (String)
  • targetNamespace
    Specifies the XML namespace of the request wrapper method. The default value is the target namespace of the SEI. (String)
  • className
    Specifies the name of the class that represents the response wrapper. (String)
    @ServiceMode

This annotation specifies whether a service provider must have access to an entire message protocol or just to the message payload.
Important:

The @ServiceMode annotation is only supported on classes that have the @WebServiceProvider annotation.

Annotation target: Type

Properties:

  • value
    Indicates whether the provider class accepts the payload of the message,PAYLOADor the entire messageMESSAGE. The default value isPAYLOAD. (String)

@Resource

This annotation marks a WebServiceContext resource that the application needs.
Apply this annotation to a service endpoint implementation class for a JavaBeans endpoint or a Provider endpoint. The container will inject an instance of the WebServiceContext resource into the endpoint implementation when it is initialized.

Annotation target: Field or Method

Properties:

  • authenticationType
    Indicates the enum that represents the authentication type for this resource. The valid values areAPPLICATIONorCONTAINER. (String)
  • description
    The description of the resource. (String)
  • mappedName
    The product specific name to which this resource is mapped. (String)
  • name
    The Java Naming and Directory Interface (JNDI) name of the resource. (String)
  • shareable
    The values indicate whether the resource can be shared between this component and other components. The default value isfalse. (Boolean)
  • type
    Indicates the Java type of the resource. (String)

@PostConstruct
This annotation marks a method that must be executed after dependency injection is performed on the class.
Apply this annotation to a JAX-WS application handler, a service endpoint implementation class for a JavaBeans endpoint or a Provider endpoint.

Annotation target: Method

@PreDestroy

This annotation marks a method that must be executed when the instance is in the process of being removed by the container.

Apply this annotation to a JAX-WS application handler, a service endpoint implementation class for a JavaBeans endpoint or a Provider endpoint.

你可能感兴趣的:(JAX-WS 2.0 Annotations)