Featured Posts

Integrating GlassFish Application server with Apache... A typical production topology for GlassFish will be a front ending GlassFish with Apache for serving the static files. To integrate GlassFish Application Server with Apache web server follow the below...

Readmore

Some Java, JEE and WebSphere stuffs Rss

Setting endpoint url in web service proxy client

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

1

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();
	proxy.setEndpoint(endPointurl);

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 Albin Joseph | Posted in Web service | Posted on 23-06-2009

2

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");	
	((javax.xml.rpc.Stub)test_Request)._setProperty(Stub.PASSWORD_PROPERTY,"password");	
}

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 Albin Joseph | Posted in Websphere Process Server / Integration Developer | Posted on 22-10-2008

0

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 Albin Joseph | Posted in Web service, WebSphere | Posted on 15-09-2008

33

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();
        proxy.setEndpoint("http://localhost:9081/WSTest/services/HelloWorld");
        String name = proxy.sayHello("Albin Joseph");
 
        System.out.println(name);

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.

Creating a webservice using RAD 7

Posted by Albin Joseph | Posted in RAD | Posted on 27-07-2008

15

Creating a webservice using RAD 7

Few months back I had posted about webservice Hello World tutorial in Java. At that time I did not find any simple tutorial on how to create a Hello World webservice in Java. Today I will explain how to create a simple webservice in Java using Rational Application Developer version 7(The steps will be almost same for RAD 6 also).

First create a project for our webservice. I just named my project as WebService. Then we need a class for our webservice. We will be exposing this class as our webservice. I have created a class HelloWorld.java with one sayHello method in it. The complete code listing for our HelloWorld.java is given below.

package com.test;
 
public class HelloWorld {
	public String sayHello(String name){
		return "Hello "+name;
	}
}

The next step is to expose this HelloWorld.java as our web service. Right click on the Project and click on New. Click on Other if your ‘Web Services’ folder is not listed. Expand the ‘Web Services’ folder and select Web Service

Click on Next. The Web Service creation wizard opens up. From the next page opened, select HelloWorld.java as our service implementation and the server types.

Click on Next.

Click on Next.

Click on Next.

Click on Finish. You are done with your HelloWorld web service using RAD 7.