JAX-WS: wsgen tool with Example

Connect with

jax-ws wsgen tool exampleIn Java JAX-WS wsgen tool example, you can generate JAX-WS portable artifacts and generate WSDL and XSD files for your Java web services.

1. Use cases for JAX-WS wsgen tool

There are 2 use case for wsgen tool.

  1. Generates JAX-WS portable artifacts, here Java file is portable artifact for web service deployment.
  2. Generates WSDL and XSD files, for testing or web service client development.

2. Where JAX-WS wsgen tool found

The wsgen utility tool available under ${JAVA_HOME}/bin/wsgen. in window wsgen.bat and Linux wsgen.sh. The wsgen tool

  1. used to parse an existing web service implementation class and
  2. generates required files i.e. JAX-WS artifacts, for web service deployment.

3. What is wsgen tool?

wsgen tool is available in ${JAVA_HOME}/bin/ folder , in window wsgen.bat and in linux wsgen.sh file . This java utility tool is used to generate the artifact in java web services .

following is the help when you type wsgen on command line for java JAXWS wsgen example.

E:\jaxws>wsgen

where [options] include:
  -classpath           specify where to find input class files and wsgen extensions
  -cp                  specify where to find input class files and wsgen extensions
  -d              specify where to place generated output files
  -encoding        specify character encoding used by source files
  -extension                 allow vendor extensions - functionality not specified
                             by the specification.  Use of extensions may
                             result in applications that are not portable or
                             may not interoperate with other implementations
  -help                      display help
  -J            pass this option to javac
  -keep                      keep generated files
  -r              resource destination directory, specify where to
                             place resource files such as WSDLs
  -s              specify where to place generated source files
  -verbose                   output messages about what the compiler is doing
  -version                   print version information
  -fullversion               print full version information
  -wsdl[:protocol]           generate a WSDL file. The protocol is optional.
                             Valid protocols are [soap1.1, Xsoap1.2],
                             the default is soap1.1.
                             The non standard protocols [Xsoap1.2]
                             can only be used in conjunction with the
                             -extension option.
  -inlineSchemas             inline schemas in the generated wsdl. Must be
                             used in conjunction with the -wsdl option.
  -servicename         specify the Service name to use in the generated WSDL
                             Used in conjunction with the -wsdl option.
  -portname            specify the Port name to use in the generated WSDL
                             Used in conjunction with the -wsdl option.
  -x                   specify External Web Service Metadata xml descriptor

Extensions:
  -Xnocompile                do not compile generated Java files

Examples:
  wsgen -cp . example.Stock
  wsgen -cp . example.Stock -wsdl -servicename {http://mynamespace}MyService

4. Why wsgen tool is required?

Usually, we required wsgent utility tool to generate artifact. In Java JAX-WS wsgen example, I will generate WSDL and java class.

5. What typ of artifact?

What typ of artifact are being generated using wsgen. What is the use case of wsgen tool

  1. Generates JAX-WS portable artifacts (i.e. Java files) for web service deployment.
  2. Generates WSDL file and xsd files, for testing or web service client development.

6. web service class

This is the JAX-WS wsgen tool example generated by using wsgen.

 
package com.mysoftkey.jaxws.hellowold;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService(endpointInterface = "com.mysoftkey.jaxws.hellowold.HelloWorld")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class HelloWorldImpl implements HelloWorld {

 @WebMethod()
 public String sayHelloWorld(String name) {
  return "Hello world JAX-WS, " + name;
 }

}

7. Generate JAX-WS portable artifact java file

Browse upto project bin folder.

File: SayHelloWorld.java

 

package com.mysoftkey.jaxws.hellowold.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "sayHelloWorld", namespace = "http://hellowold.jaxws.mysoftkey.com/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "sayHelloWorld", namespace = "http://hellowold.jaxws.mysoftkey.com/")
public class SayHelloWorld {

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

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

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

}

File: SayHelloWorldResponse.java

 

package com.mysoftkey.jaxws.hellowold.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "sayHelloWorldResponse", namespace = "http://hellowold.jaxws.mysoftkey.com/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "sayHelloWorldResponse", namespace = "http://hellowold.jaxws.mysoftkey.com/")
public class SayHelloWorldResponse {

 @XmlElement(name = "return", namespace = "")
 private String _return;

 public String get_return() {
  return this._return;
 }

 public void set_return(String _return) {
  this._return = _return;
 }

}

8. Generate WSDL and XSD file using wsgen tool

copy com folder with .class of HelloWorldImpl.class in e:\jaxws\ folder and open a terminal and run

folder structure before generation

 
E:\jaxws>tree /f
Folder PATH listing for volume New Volume
Volume serial number is 00000011 D8C6:F3BB
E:.
└───com
    └───mysoftkey
        └───jaxws
            └───hellowold
                    HelloWorld.class
                    HelloWorldImpl.class

 
E:\jaxws>wsgen -cp . -verbose -keep com.mysoftkey.jaxws.hellowold.HelloWorldImpl -wsdl

Folder structure after generation of WSDL and XSDartifact

 
E:\jaxws>tree /f
Folder PATH listing for volume New Volume
Volume serial number is 00000011 D8C6:F3BB
E:.
│   HelloWorldImplService.wsdl
│   HelloWorldImplService_schema1.xsd
│
└───com
    └───mysoftkey
        └───jaxws
            └───hellowold
                    HelloWorld.class
                    HelloWorldImpl.class

9. Generated wsdl file

generate WSDL file using JAX-WS wsgen .In this post you can find JAX-WS wsgen example.
File: HelloWorldImplService.wsdl

 



  
  
    
  
  
    
  
  
    
      
      
    
  
  
    
    
      
      
        
      
      
        
      
    
  
  
    
      
    
  


10. Generated XSD file

File: HelloWorldImplService_schema1.xsd

 



  

  



you can visit how to write Java webservice client using WSDL.

11. Reference for Java JAX-WS wsgen example

For more details of Java JAXWS wsgen example you can visit Java JAX-WS wsgen tool

Thanks for visiting this page for Java JAX-WS wsgen example.
Happy Learning 🙂 for wsgen example, you can visit JAX-WS web services tutorial page.
Your comments are welcome to improve this post. Happy Learning! 🙂


Connect with

Leave a Comment

Your email address will not be published. Required fields are marked *