Web Service (1.8)

Source: Internet
Author: User
Tags soap wsdl

The Xmlweb Service-based Java API (JAX-ws) uses annotations to specify the metadata associated with a Web service implementation and simplifies the development of Web service. The comment describes how to use the server-side service implementation as a Web service access or how the Java class of the client accesses the Web service.

The JAX-WS programming Standard supports commenting on a Java class with metadata that defines the service endpoint application as a Web service and commenting on how the client can access the Web service. JAX-WS support uses the Metadata Facility for the Java programming Language (Java Specification request (JSR) 175) specification and "Web Service metadata for the Java platform" (JSR 1 81) specification annotations, and annotations (including JAXB annotations) defined by the JAX-WS 2.0 (JSR 224) specification can also be used. By using annotations that conform to the JSR 181 standard, you can simply annotate a service implementation class or service interface, and now enable the application as a WEB service. Using annotations in Java source code simplifies the development and deployment of WEB Service because it defines additional information that is typically obtained from deployment descriptor files and WSDL files, or maps metadata from XML and WSDL to the source artifacts.

Use annotations to configure bindings, handler chains, collection names for port types, services, and other WSDL parameters. Annotations are used to map Java to WSDL and schema, and to control how the Jax-WS runtime handles and responds to Web Service calls at run time.

The comments for Jax-WS support are listed in the following table. The target of the comment applies to the following Java objects:
    • Types such as Java classes, enumerations, or interfaces
    • Method
    • Field used to represent a local instance variable in a Java class
    • Parameters in the Java method
Web Service metadata annotations (JSR 181)Annotation classes: Comments: Properties:
Javax.jws.WebService When the Web service is implemented, the Java class is marked@WebService Comment, and the service Endpoint interface (SEI) is marked when the Web service interface is implemented.

Points:

• Java classes that implement Web Service must specify @WebService or @WebServiceProvider annotations. Neither of these annotations can be provided at the same time.

This comment applies to the server endpoint implementation class for the client/server SEI or JavaBeans endpoint.

• If a comment endpointInterface references an sei through an attribute, you must also annotate the SEI with a @WebService comment.

• See rules that apply to the methods of a class that uses @WebService annotations for more information.

  • comment target: type
  • property:
    -name
    wsdl:porttype the name of the  . The default value is the unqualified name of the Java class or interface. (string)
    -targetnamespace
    Specifies the XML namespace for the WSDL and XML elements generated from the Web Service. 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 . 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 abstract Web service contract for the service. If this qualified name is specified, the service endpoint interface is used to determine the abstract WSDL contract. (string)
    -portname
    wsdl:portname . 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 can be a relative path or an absolute path. (string)
javax.jws.webmethod @WebMethod The/strong>  comment represents a method as a Web Service operation. The

Applies this comment to the method on the client or Server service endpoint interface (SEI), or to the server endpoint implementation class that is applied to the JavaBeans endpoint.

Important:

• Only support the use of @WebMethod annotations on classes annotated with @WebService annotations.

  • Comment target: Method
  • Property:
    -OperationName
    Specifies the name of the wsdl:operation   that matches this method. The default value is the name of the Java method. (string)
    -action
    defines the behavior of this operation. For SOAP bindings, this value determines the value of the SOAPAction header. The default value is the name of the Java method. (string)
    -Exclude
    Specifies whether a method is excluded from the Web Service. The default value is   false . (Boolean)
Javax.jws.Oneway @Oneway Note represents a method as a Web Service one-way operation that has only input messages and no output messages.

Apply this comment to a method on the client or Server service endpoint interface (SEI), or to the server endpoint implementation class that is applied to the JavaBeans endpoint.

  • Annotation Target: Method
  • There are no properties that apply to Oneway annotations.
Javax.jws.WebParam @WebParam Annotations are used to customize mappings from a single parameter to a WEB Service message part and XML element.

Apply this comment to a method on the client or Server service endpoint interface (SEI), or to the server endpoint implementation class that is applied to the JavaBeans endpoint.

  • Annotation target: Parameters
  • property:
    The name of the
    -name
    parameter. If the operation is a remote procedure call (RPC) type and the partname   property is not specified, this is the name of the   Wsdl:part   property that represents the parameter. If the action is a document type or the parameter is mapped to a header,   -name   is the local name of the XML element that represents the parameter. If the action is a document type, the parameter type is   BARE   and the way is   out   or   INOUT , you must specify this Property. (string)
    -PartName
    defines the name of the   Wsdl:part property that is used to represent this parameter. Use this parameter only if the operation type is RPC or if the operation is a document type and the parameter type is BARE  . (string)
    -targetnamespace
    Specifies the XML namespace of the parameter's XML element. When a property is mapped to an XML element, it is applied only to document bindings. The default value is Web Service   targetnamespace . (string)
    -mode
    This value represents the direction of the parameter flow for this method. Valid values are   in , INOUT  , and   out . (string)
    -header
    Specifies whether the parameter is in the message header or the body of the message. The default value is   false . (Boolean)
Javax.jws.WebResult @WebResult Annotations are used to customize mappings from return values to WSDL parts or XML elements.

Apply this comment to a method on the client or Server service endpoint interface (SEI), or to the server endpoint implementation class that is applied to the JavaBeans endpoint.

  • Comment target: Method
  • Property:
    -Name
    when returned The return value is listed in the WSDL file and when the return value is found in a message on the connection, the name of the returned value is specified. For RPC bindings, this is the name of the   Wsdl:part property that is used to represent the return value. For document bindings, the -name parameter is the local name of the XML element that represents the return value. For RPC and document/wrapped bindings, the default value is   return . For Document/bare bindings, the default value is the method name +  Response . (string)
    -targetnamespace
    Specifies the XML namespace for the return value. This parameter is used only if the operation type is RPC or if the operation is a document type and the parameter type is BARE. (string)
    -header
    Specifies whether the header is accompanied by a result. The default value is false . (Boolean)
    -PartName
    Specifies the part name of the result of the RPC or Document/bare operation. The default value is @WebResult. Name . (string)
Javax.jws.HandlerChain @HandlerChain Annotations are used to associate a Web Service with an externally defined handler chain.

Server-side handlers can only be configured by using @HandlerChain annotations on the SEI or implementation class.

However, there are several ways to configure client handlers. The client's handlers can be configured by using @HandlerChain annotations for the generated service class or SEI. In addition, you can register your own Handlerresolver interface implementation on the service by program, or set the handler chain on the bound object by program.

  • Note Target: type
  • Property:
    -File
    Specifies where the handler chain file is located. The file location can be an absolute java.net.URL in an external format, or it can be a relative path in a class file. String
    -Name
    Specifies the name of the handler chain in the configuration file. String
Javax.jws.SOAPBinding @SOAPBinding   Comments Specifies the mapping between the Web Service and the SOAP message protocol. The

Applies this comment to the type or method on the client or Server service endpoint interface (SEI), or to the server endpoint implementation class that is applied to the JavaBeans endpoint. The comment at the

Method level is limited to the object it can specify, and is used only if the style   property is   DOCUMENT  . If you do not specify a method-level comment, the @SOAPBinding   Behavior of the type is used.

  • Annotation target: Type or method
  • Property:
    -style
    Defines the encoding style that is sent to the Web service and messages from the Web service. Valid values are DOCUMENT and RPC . The default value is DOCUMENT . String
    -Use
    Defines the format for sending messages to the Web service and from the Web service. The default value is LITERAL . ENCODEDnot supported in Feature Pack for Web Services. String
    -ParameterStyle
    Determines whether the parameter of the method represents the entire message body, or whether the parameter is an element that encapsulates the top-level element that is named after the action is performed. Valid values are WRAPPED or BARE . DOCUMENTonly values can be used for bindings of type BARE . The default value is WRAPPED . String

Jax-ws annotations (JSR 224)Annotation classes: Comments: Properties:
javax.xml.ws.bindingtype @ Bindingtype   Note Specifies the binding to use when publishing endpoints of this type. The

Applies this comment to the server endpoint implementation class of the JavaBeans endpoint or provider endpoint.

Important:

• You can specify the value of this comment as Javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING or Javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING to use @BindingType comments on the Java bean endpoint implementation class to enable MTOM.

  • comment target: type
  • property:
    -Value
    indicates the binding identity Web address. Valid values are Javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING , javax.xml.ws.soap.SOAPBinding.SOAP12 Http_binding and   Javax.xml.ws.http.HTTPBinding.HTTP2HTTP_BINDING . The default value is Javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING . (string)
javax.xml.ws.requestwrapper @ The Requestwrapper   Comment provides the JAXB-generated request wrapper bean, element name, and namespace for serializing and deserializing the request wrapper bean used at run time.

When starting from a Java object, this element is used to resolve overload conflicts in document literal mode. In this case, only   className   properties are required. The

Applies this comment to the method on the client or Server service endpoint interface (SEI) or to the server endpoint implementation class that is applied to the JavaBeans endpoint.

  • Comment target: Method
  • Property:
    -LocalName The
    specifies the local name of the XML schema element that is used to represent the request wrapper. The default value is the   operationname defined in the Javax.jws.WebMethod comment. (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 used to represent the request wrapper. (string)
javax.xml.ws.responsewrapper @ The Responsewrapper   Comment provides the JAXB-generated response wrapper bean, element name, and namespace for serializing and deserializing the response wrapper bean that is used at run time.

When starting from a Java object, this element is used to resolve overload conflicts in document literal mode. In this case, only   className   properties are required. The

Applies this comment to the method on the client or Server service endpoint interface (SEI) or to the server endpoint implementation class that is applied to the JavaBeans endpoint.

  • Comment target: Method
  • Property:
    -LocalName The
    specifies the local name of the XML schema element that is used to represent the request wrapper. The default value is   operationname  +  Response . OperationName   is defined in the 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 is used to represent the response wrapper. (string)
javax.xml.ws.servicemode @ Servicemode   Note Specifies whether the service provider needs to have access to the entire protocol message or simply to the message's valid content.

Important:

• Only @ServiceMode annotations are supported on classes annotated with @WebServiceProvider annotations.

  • comment target: type
  • property:
    -Value
    Indicates whether the provider class is a valid content to accept a message   PAYLOAD   or the entire message   messages . The default value is   PAYLOAD . (string)
Javax.xml.ws.WebFault @WebFault Comment Maps a WSDL fault to a Java exception. The comment is used to capture the name of the failure during serialization of the JAXB type generated from the global element referenced by the WSDL fault message. It can also be used to customize mappings from service-specific exceptions to WSDL failures.

This comment can only be applied to a fault implementation class on a client or server.

  • Note Target: type
  • Property:
    -Name
    Specifies the local name of the XML element used to represent the corresponding failure in the WSDL file. The actual value must be specified. String
    -TargetNamespace
    Specifies the namespace of the XML element that is used to represent the corresponding failure in the WSDL file. String
    -Faultbean
    Specifies the name of the fault Bean class. String
Javax.xml.ws.WebServiceProvider @WebServiceProvider   Comment indicates that a class satisfies the requirements of the Jax-WS Provider Implementation class.

Important:

• Java classes that implement Web Service must specify @WebService or @WebServiceProvider annotations. Neither of these annotations can be provided at the same time.

• @WebServiceProvider annotations are supported only by the service implementation class.

• Any class that has @WebServiceProvider comments must have an operation named   invoke  .

  • Note Target: type
  • Property:
    -TargetNamespace
    Specifies the XML namespace for the WSDL and XML elements generated from the Web Service. The default value is the namespace mapped from the package name that contains the Web Service. String
    -ServiceName
    Specify the service name for the Web service: wsdl:service . The default value is the simple name + Serviceof the Java class. String
    -PortName
    wsdl:portName。 The default value is the name of the class + Port. String
    -Wsdllocation
    The web address of the WSDL document that defines the Web Service. This property is required. String

JAX-ws common Annotations (JSR)Annotation classes: Comments: Properties:
javax.annotation.resource @ Resource   Comment marks the Webservicecontext resources required by the application. The

Applies this comment to the server endpoint implementation class of the JavaBeans endpoint or provider endpoint. When the container is initialized, the container adds an instance of the Webservicecontext resource to the endpoint implementation.

  • comment target: field or method
  • property:
    -type The/dt>
    indicates the Java type of the resource. You need to use the default value java.lang.Object   or javax.xml.ws.Web servicecontext value. If the type is the default value, you must add the resource to the field or method. In this case, the type of the field or the type of the JavaBeans property defined by the method must be javax.xml.ws.WebServiceContext . (string)
Javax.annotation.PostConstruct @PostConstruct Annotation markup requires a method that executes after a dependency injection is performed on the class.

Apply this comment to the server endpoint implementation class of the JAX-WS application Handler, JavaBeans endpoint, or provider endpoint.

  • Annotation Target: Method
Javax.annotation.PreDestroy @PreDestroy Comment marks the method that must be executed when the container drops an instance.

Apply this comment to the server endpoint implementation class of the JAX-WS application Handler, JavaBeans endpoint, or provider endpoint.

  • Annotation Target: Method
Rules that apply to the methods of a class that use @WebService annotations the following rules apply to methods that use @WebService annotations to annotate classes.
    • If an @WebService comment for an implementation class references the SEI, the instance class cannot have any @WebMethod annotations.
    • All common methods of the SEI are considered to be displayed, regardless of whether @WebMethod annotations are specified. It exclude is incorrect to use @WebMethod comment on the SEI that contains the attribute.
    • For an implementation class that does not reference the SEI, the method is not displayed if a value is specified for the @WebMethod comment exclude=true . If @WebMethod annotation is not specified, all public methods, including inherited methods, are displayed, but not methods inherited from Java.lang.Object.

Web Service (1.8)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.