WebSphere Application Server Version 6.1 Feature Pack for Web Services
             Operating Systems: AIX, HP-UX, i5/OS, Linux, Solaris, Windows, z/OS

             Personalize the table of contents and search results
             New or updated topic for this feature pack

Developing Java artifacts for JAX-WS applications from JavaBeans

JAX-WS tooling enables the generation of Java artifacts needed to develop JAX-WS Web services when starting from JavaBeans components.

Before you begin

To develop a Java API for XML-Based Web Services (JAX-WS) Web service application when starting from JavaBeans components, you must first develop an explicit or implicit service endpoint interface with annotations before you can generate the portable Java artifacts.

About this task

When using a bottom-up approach to develop JAX-WS Web services, use the wsgen command-line tool when starting from a service endpoint implementation. The wsgen tool processes a compiled service endpoint implementation class as input and generates the following portable artifacts:

You are not required to develop a WSDL file when developing JAX-WS Web services using the bottom-up approach of starting with JavaBeans. The use of annotations provides all of the WSDL information necessary to configure the service endpoint or the client. The Feature Pack for Web Services supports WSDL 1.1 documents that comply with Web Services-Interoperability (WS-I) Basic Profile 1.1 specifications and are either Document/Literal style documents or RPC/Literal style documents. Additionally, WSDL documents with bindings that declare a USE attribute of value LITERAL are supported while the value, ENCODED, is not supported. For WSDL documents that implement a Document/Literal wrapped pattern, a root element is declared in the XML schema and is used as an operation wrapper for a message flow. Separate wrapper element definitions exist for both the request and the response.

To ensure the wsgen command does not miss inherited methods on a service endpoint implementation bean, you must either add the @WebService annotation to the desired superclass or you can override the inherited method in the implementation class with a call to the superclass method. Implementation classes only expose methods from superclasses that are annotated with the @WebService annotation.

Procedure

  1. Locate your service endpoint implementation class file.
  2. Run the wsgen -keep -verbose service_implementation_class command to generate the portable artifacts. The wsgen command-line tool is located in the app_server_root\bin\ directory. Because the -verbose option is specified, a list of all the generated files is displayed when the command runs.

Results

You have the required Java artifacts to create a JAX-WS Web service.

Avoid trouble: The wsgen command does not differentiate the XML namespace between multiple XMLType annotations that have the same @XMLType name defined within different Java packages. When this scenario occurs, the following error is produced:
Error: Two classes have the same XML type name ....
Use @XmlType.name and @XmlType.namespace to assign different names to them...
This error indicates you have class names or @XMLType.name values that have the same name, but exist within different Java packages. To prevent this error, add the @XML.Type.namespace class to the existing @XMLType annotation to differentiate between the XML types.gotcha

Example

The following example demonstrates how to use the wsgen command to process the service endpoint implementation class to generate portable artifacts. This example EchoService service implementation class uses an explicit JavaBeans service endpoint.
  1. Copy the sample EchoServicePortTypeImpl service implementation class file and the associated EchoServicePortType service interface class file into a directory. The directory must contain a directory tree structure that corresponds to the com.ibm.was.wssample.echo package name for the class file.
    /* This is a sample EchoServicePortTypeImpl.java file.    */
    package com.ibm.was.wssample.echo;
    
    
    @javax.jws.WebService(serviceName = "EchoService", endpointInterface = 
    "com.ibm.was.wssample.echo.EchoServicePortType", 
    targetNamespace="http://com/ibm/was/wssample/echo/",
    portName="EchoServicePort")
    
    public class EchoServicePortTypeImpl implements EchoServicePortType {
    
    	public EchoServicePortTypeImpl() {
    	}
    
    	public String invoke(String obj) {
    		System.out.println(">> JAXB Provider Service: 
    Request received.\n");
    		String str = "Failed";
    		if (obj != null) {
    			try {
    				str = obj;
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		}
    		return str;
    
    	}
    
    }	
    /* This is a sample EchoServicePortType.java file.    */
    package com.ibm.was.wssample.echo;
    
    import javax.jws.WebMethod;
    import javax.jws.WebParam;
    import javax.jws.WebResult;
    import javax.jws.WebService;
    import javax.xml.ws.RequestWrapper;
    import javax.xml.ws.ResponseWrapper;
    
    
    @WebService(name = "EchoServicePortType", targetNamespace = 
    "http://com/ibm/was/wssample/echo/", 
     wsdlLocation="WEB-INF/wsdl/Echo.wsdl")
    
    public interface EchoServicePortType {
    
    
        /**
         * 
         * @param arg0
         * @return
         *     returns java.lang.String
         */
        @WebMethod
        @WebResult(name = "response", targetNamespace = 
        "http://com/ibm/was/wssample/echo/")
        @RequestWrapper(localName = "invoke", targetNamespace = 
        "http://com/ibm/was/wssample/echo/", 
         className = "com.ibm.was.wssample.echo.Invoke")
        @ResponseWrapper(localName = "echoStringResponse", 
         targetNamespace = "http://com/ibm/was/wssample/echo/", 
         className = "com.ibm.was.wssample.echo.EchoStringResponse")
        public String invoke(
            @WebParam(name = "arg0", targetNamespace = 
            "http://com/ibm/was/wssample/echo/")
            String arg0);
    
    }
    
  2. Run the wsgen command from the app_server_root\bin\ directory. The -cp option specifies the location of the service implementation class file. The -s option specifies the directory for the generated source files. The -d option specifies the directory for the generated output files. When using the -s or -d options, you must first create the directory for the generated output files.
    [Windows]
    app_server_root\bin\wsgen.bat -wsdl -s c:\generated_source\ -cp c:\my_application\classes\ 
    com.ibm.was.wssample.echo.EchoServicePortTypeImpl -verbose -d c:\generated_artifacts\
    [Linux] [AIX] [HP-UX] [Solaris] Linux and UNIX-based platforms source the script to the parent shell to inherit the exported variables by running the following command:
    . ./setupCmdLine.sh  (Notice the space between the periods.)
    from the . /app_server_root>/bin directory. Run the wsgen command,
    app_server_root/bin/wsgen.sh -wsdl -s c:/generated_source/ -cp c:/my_application/classes/ 
    com.ibm.was.wssample.echo.EchoServicePortTypeImpl -verbose -d c:/generated_artifacts/
After generating the Java artifacts using the wsgen command, the following files are generated:
/generated_source/com/ibm/was/wssample/echo/EchoStringResponse.java
/generated_source/com/ibm/was/wssample/echo/Invoke.java
/generated_artifacts/EchoService.wsdl
/generated_artifacts/EchoService_schema1.xsd
/generated_artifacts/com/ibm/was/wssample/echo/EchoStringResponse.class
/generated_artifacts/com/ibm/was/wssample/echo/Invoke.class

The EchoStringResponse.java and Invoke.java files are the generated Java class files. The compiled versions of the generated Java files are EchoStringResponse.class and Invoke.class files. The EchoService.wsdl and EchoService_schema1.xsd files are generated because the -wsdl option was specified.

What to do next

Complete the JavaBeans implementation.



In this information ...


Related concepts

IBM Redbooks, demos, education, and more


Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

IBM Suggests
Task topic    

Terms of Use | Feedback

Last updated: Nov 25, 2008 2:35:59 AM CST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.wsfep.multiplatform.doc/info/ae/ae/twbs_devjaxwsartifactsbean.html