• Entries (RSS)
  • Comments (RSS)

Creating a Hello World RESTful web service with RAD and WebSphere Application Server using IBM JAX-RS

Posted by | Posted in WebSphere | Posted on 22-05-2011

Tagged Under : , , ,

Creating a Hello World RESTful web service with RAD and WebSphere Application Server using IBM JAX-RS

REST is the buzzword now. So its time to learn how to create a RESTful web service now. Here is my simple hello world tutorial on creating a RESTful web service using Rapid Application Developer and IBM JAX-RS. JAX-RS is a Java API for developing REST applications. JAX-RS 1.0 defines a server-side component API to build REST applications. This ia an implementation of the JAX-RS (JSR 311) specification.

All the REST implementations I have seen need a minimum Java 1.5 to run. All these implementations use annotations. So my code will not work on WebSphere Application Server 6 and below versions. The minimum required version is WebSphere Application Server 6.1. I have tested these examples only in WAS 7. You need to have Feature pack for Web 2.0 for WebSphere installed on your application server. So once you have your app server ready with Web 2.0 feature pack installed then you have pretty much everything to get started. Follow the below steps to create your first hello world RESTful web service with RAD and WAS 7. For my development purposes I was using RAD 7.5. But I am sure that the following steps will work even for other RAD version too.
Read the rest of this entry »


Setting endpoint url in web service proxy client

Posted by | Posted in Web service | Posted on 13-08-2009

Tagged Under : ,

One of our project was developed and supported by an external vendor and due to some reasons (of course not known to me) our company decided to do all the future enhancements and support by our self. The project uses WebSphere Process Server as the middle ware and WebSphere portal server as the front end. All the communications between the portal and process server was using web service export. During the knowledge transfer session I noticed that for setting the endpoint url for different environments in their proxy client, they were editing the ServieLocator class. So I just want to post a small note on how to set the endpoint URL without changing the generated proxy classes.

To change the endpoint url for a web service we have a setEndpoint method in our proxy class. By default I guess the endpoint url will be pointing to localhost. By passing the new endpoint url to the setEndpoint method we can change it to a new host. For eg: in our hello world web service client, to change the end point url, change the code as shown below.

	HelloWorldProxy proxy = new HelloWorldProxy();

That’s it. We are done with changing the endpoint url. We can store this endpoint url as part of our properties file and read it from there. This will ensure that, we get different endpoint urls for different environments


Web service client with basic authentication

Posted by | Posted in Web service | Posted on 23-06-2009

Tagged Under : ,

Configuring a web service client for basic authentication

How do we pass the username and password to a web service which is protected by basic authentication? The generated proxy client has no methods for setting the username and password.

The solution is to set the username and password inside the generated proxy client. To do this edits your proxy java file and set the username and password properties. The properties are javax.xml.rpc.Stub.USERNAME_PROPERTY and javax.xml.rpc.Stub.PASSWORD_PROPERTY. I did it inside my _initXXX method of proxy client. For eg: my code looked like the following

if (test_Request != null) {
	((javax.xml.rpc.Stub)test_Request)._setProperty(Stub.USERNAME_PROPERTY, "username");	

If you set any other property name you will get an exception

Exception in thread "main" javax.xml.rpc.JAXRPCException: WSWS3212E: Error: Property name javax.xml.rpc.Stub.XXX not supported.
	at com.ibm.ws.webservices.engine.client.Stub._setProperty(Stub.java:541)

org.xml.sax.SAXException: WSWS3047E: Error: Cannot deserialize element

Posted by | Posted in Websphere Process Server / Integration Developer | Posted on 22-10-2008

Tagged Under : , , , , ,

Yesterday I came across a new exception while invoking my web service using WebSphere Process Server. I was trying to invoke an external web service from WID. The exception or web service fault message I was getting was

CNTR0020E: EJB threw an unexpected (non-declared) exception during invocation of method "transactionNotSupportedActivitySessionNotSupported" on bean "BeanId(CustomerProfileApp#CustomerProfileEJB.jar#Module, null)". Exception data: com.ibm.websphere.sca.ServiceRuntimeException: <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Fault><faultcode>soapenv:Server.generalException</faultcode><faultstring>org.xml.sax.SAXException: WSWS3047E: Error: Cannot deserialize element elementName of bean beanName. To see the message containing the parsing error in the log, either enable web service engine tracing or set MessageContext.setHighFidelity(true).</faultstring></soapenv:Fault></soapenv:Body>
	at com.ibm.wsspi.sca.webservice.jaxrpc.ServiceImportHandler.handleFault(ServiceImportHandler.java:313)
	at com.ibm.ws.webservices.engine.handlers.jaxrpc.HandlerProxy.handleFault(HandlerProxy.java:159)
	at com.ibm.ws.webservices.engine.handlers.jaxrpc.JAXRPCHandlerChain.oneHandleFault(JAXRPCHandlerChain.java:869)
	at com.ibm.ws.webservices.engine.handlers.jaxrpc.JAXRPCHandlerChain.handleFault(JAXRPCHandlerChain.java:846)
	at com.ibm.ws.webservices.engine.handlers.jaxrpc.JAXRPCHandlerChain.handleFault(JAXRPCHandlerChain.java:839)
	at com.ibm.ws.webservices.engine.handlers.jaxrpc.JAXRPCHandler.invokeClientFaultHandler(JAXRPCHandler.java:535)
	at com.ibm.ws.webservices.engine.handlers.jaxrpc.JAXRPCHandler$3.onFault(JAXRPCHandler.java:453)
	at com.ibm.ws.webservices.engine.PivotHandlerWrapper.onFault(PivotHandlerWrapper.java:516)
	at com.ibm.ws.webservices.engine.PivotHandlerWrapper.invoke(PivotHandlerWrapper.java:317)
	at com.ibm.ws.webservices.engine.WebServicesEngine.invoke(WebServicesEngine.java:336)
	at com.ibm.ws.webservices.engine.client.Connection.invokeEngine(Connection.java:929)
	at com.ibm.ws.webservices.engine.client.Connection.invoke(Connection.java:722)

This usually happens when you have an array of complex types. There is a technote available from IBM and they are providing three different solution. I just followed one of the solutions given by that technote. So to resolve this issue follow the below steps.

1. Open your WSDL file
2. Search for the elementName that cannot be serialized.
3. If you found an entry like

	<element name="elementName" nillable="true" type="someComplexType" />

4. Add ‘ xmlns=”"‘ to that element.

5. Now your element definition will look like

	<element name="elementName" nillable="true" type="someComplexType"  xmlns="" />

This will resolve the issue. At least it solved my problem. However the IBM recommended solution is to use the proper namespace.


Invoking a web service using web service proxy client

Posted by | Posted in Web service, WebSphere | Posted on 15-09-2008

Tagged Under : , , ,

Invoking a web service using web service proxy client

Yesterday I got a comment on my post “Generating a web service proxy client” asking how do we invoke or test this web service using the webservice proxy client. So I thought of writing a post of how to use the generated proxy client to call a webservice. Here I am going to create a simple JSP file that is going to use the webservice proxy client to call or invoke the Hello World web service running in WebSphere.

Before you start, please make sure that you have generated the web service client as mentioned in Generate web service proxy client in java. If you do not have the Hello World web service running in your server, follow the tutorial at Creating a Hello World web service using RAD.

While generating the webservice proxy client I generated the Java files using no wrapped style.

One we have the java proxy files generated we can see some files named XXXProxy.java, XXX.java, XXXService.java, XXXServiceInformation.java, XXXServiceLocator.java etc in our workspace. Now create a new jsp file for calling the web service. Add the following code to invoke the Hello World webservice using our web service proxy client.

	com.test.HelloWorldProxy proxy = new com.test.HelloWorldProxy();
        String name = proxy.sayHello("Albin Joseph");

If everything works fine, we would see a ‘Hello Albin Joseph’ as the output in your console.

Our Hello World service was exposing a sayHello method as a webservice. The HelloWorldProxy class is the proxy client class for our webservice. If we are not setting the end point url (the url of the webservice), our proxy client would take the default one present in the wsdl file.