JAX-WS on Glassfish using wsgen

Several times of attempt on creating a JAXWS WebService with CXF, Glassfish, and Eclipse combination, I concluded that there are some issues on the development environment (CXF 2.6.0, Glassfish 3.1.2, and Eclipse Indigo). I followed several tutorials, but I always encountered either NPE or missing WSDL and failed to deploy EAR message.

CXF site suggested that Glassfish Metro library will overwrite CXF, so disable class-load in sun-web.xml page, which I did. Glassfish issue log suggested that generated wsdl is not placed under WEB-INF folder. Wizard generated a wsdl file directly under WebContent. When I moved wsdl folder under WEB-INF and modified wsdl location, I still had the same error.

Now, forget the Wizard in the Eclipse. I created JAX-WS WebService using wsgen. First, create a minimum Dynamic Web Project and create a WebService implementation class with the annotations.

@WebService
public class ExampleService {

@WebMethod
public int add( int a, int b)
{
return a + b;
}

@WebMethod
public String concat(String first, String second)
{
return first + second;
}
}

Now, run wsgen command.

msjo@local $ wsgen -verbose -classpath build/classes/ -wsdl -r WebContent/WEB-INF/wsdl -s src -d build
/classes/ com.mjtoolbox.ws.ExampleService

warning: The apt tool and its associated API are planned to be
removed in the next major JDK release.  These features have been
superseded by javac and the standardized annotation processing API,
javax.annotation.processing and javax.lang.model.  Users are
recommended to migrate to the annotation processing features of
javac; see the javac man page for more information.
Note:   ap round: 1
[ProcessedMethods Class: com.mjtoolbox.ws.ExampleService]
[should process method: add hasWebMethods: true ]
[endpointReferencesInterface: false]
[declaring class has WebSevice: true]
[returning: true]
[WrapperGen - method: add(int,int)]
[method.getDeclaringType(): com.mjtoolbox.ws.ExampleService]
[requestWrapper: com.mjtoolbox.ws.jaxws.Add]
[should process method: concat hasWebMethods: true ]
[endpointReferencesInterface: false]
[declaring class has WebSevice: true]
[returning: true]
[WrapperGen - method: concat(java.lang.String,java.lang.String)]
[method.getDeclaringType(): com.mjtoolbox.ws.ExampleService]
[requestWrapper: com.mjtoolbox.ws.jaxws.Concat]
[ProcessedMethods Class: java.lang.Object]
com\mjtoolbox\ws\jaxws\Add.java
com\mjtoolbox\ws\jaxws\AddResponse.java
com\mjtoolbox\ws\jaxws\Concat.java
com\mjtoolbox\ws\jaxws\ConcatResponse.java
Note:   ap round: 2

In order to run it properly, I have to build the project in the Eclipse. It seems Eclipse doesn’t build the project until Run on Server is executed. Have a look at the wsdl file and update the “REPLACE_WITH_ACTUAL_URL” with the actual WebService Endpoint. Make sure to replace URL with actual Service name defined in the wsdl like below.

<service name="ExampleServiceService">
<port name="ExampleServicePort"
binding="tns:ExampleServicePortBinding">
<soap:address
location="http://127.0.0.1:8080/WSbare/ExampleServiceService"/>
</port>
</service>

Another way of testing JAX-WS WebService is using Endpoint API.

Endpoint API provide the light-weight HTTP container that is included in Java SE 6. Without the web server, we can deploy the same WebService to the desire location. Of course, wsdl will be generated automatically. URL can be anything after the port number.

 

public static void main(String[] args){
Endpoint.publish("http://hy149411:8080/WSbare/Examplews", new ExampleService());
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s