Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents
maxLevel34
minLevel3

Working with JAX-WS

...

annotations

Listed below are the most important annotations and their member-value pairs.

...

  • Java to WSDL (code first) approach
  • WSDL to Java (contract first) approach

Java to WSDL Development Model with JAX-WS

In this approach, development starts from the code or the service implementation and the Web application engine generates the WSDL for the developer. The developer can write his POJO service and use annotations to control the structure of the WSDL. The JAX-WS runtime generates the WSDL according to these annotations used. The advantage of using annotations is that the Web application implementation can be changed without affecting the generated WSDL contract. Therefore, JAX-WS is the standard development technique when it comes to POJO development.

Some sample POJO services using JAX-WS are as follows:

Sample 1:

This simple example uses the @WebService annotation to convert a simple POJO into a Web application. When you use this annotation, all the public methods in the class become operations in the application by default. If you want to exclude a particular method, you have to specify it using the 'exclude' property of the @WebMethod annotation. Also, if some method should be mapped into a one way operation, you have to use the @Oneway annotation. The sample code of this POJO is as follows:

Code Block
languagejava
package org.wso2.jaxws.sample01;

import javax.jws.WebService;
import javax.jws.Oneway;
import javax.jws.WebMethod;

@WebService
public class SimpleSample {

    public String echo(String echoInput) {
        return echoInput;
    }

    @Oneway
    public void ping(String pingInput) {
        System.out.println("Ping : " + pingInput);
    }

    @WebMethod(exclude = true)
    public String hideMethod(String hideInput) {
        return "Hiding : " + hideInput;
    }
}
Sample 2:

This sample service (StudentMarksService) contains two operations called 'computeAverage' and 'computeHighestMarks'. Both these methods get a Student object as a parameter. The sample code is as follows, showing how you can customize the WSDL service interface using annotations.

...

You can simply compile these sample classes, create .jar archives and deploy them in a running Carbon instance.

WSDL to Java Development Model with JAX-WS

In this method, the WSDL contract is used to generate the application's skeleton and other binding classes through the usage of some WSDL to Java tool (Look under the Tools section for more information). The tool generates the Service Endpoint Interface (SEI) and the JAXB binding classes according to the WSDL and the schema. Service developer only has to write the application class by implementing the SEI.

A WSDL to Java sample using JAX-WS is as follows:

Sample 1:

The same "StudentMarksService" mentioned above is used here.

...

Info

For more information on writing JAX-WS annotated Web applications, go to: http://axis.apache.org/axis2/java/core/docs/jaxws-guide.html

Configuration JAX-WS applications for AS

...

  • If you

...

  • want to enable SaaS mode or CORS for your

...

Building JAX-WS applications for AS

JAX-WS and JAX-RS applications can be bundled in a CXF application. Given below is the general folder structure of a CXF application. However, this can change depending on your application.

Please see the instructions on class loading for web applications, which explains how you can add the webapp-classloading.xml file to your web app. This XML is a custom file implemented by WSO2 to give flexibility in classloading. You must have this file in order to deploy JAX-WS and JAX-RS applications, because the CXF runtime is not visible to the webapps by default.

Code Block
HellowService.war
    WEB-INF/
        web.xml
        cxf-servlet.xml
        wsdl
        lib/
        classes/
    META-INF/
        webapp-classloading.xml