Sunday, June 12, 2011

Java integration to Siebel Webservice

 

A few weeks back we had this requirement to have a Java client connect to our Siebel Webservice and do various operations. In this model, the Siebel side was the backend, and a Java applet was the frontend to the system. I setup the inbound Webservice in Siebel in no time, using ASIs. But the Java folks were having problems in setting up a connection to the system. They even said there were problems in the WSDL and Webservice, and that they were getting various parser errors on their side. Guess they were too dependent on eclipse, and they could not find an import WSDL feature on it !!

Truth is, Java is one of those languages which understands webservices very well, and if properly used, could make the integration work easiest to implement. You don’ have to build the SOAP request by hand (though, that is one option) as is done in some scripting languages. You just have to figure out how to generate the stub file, or the necessary class files into the system.

Now there are two ways to import a WSDL into a  Java system, you would use the WSDLtoJava.bat file if you are using the apache axis framework. This is when a Java servlet on Tomcat/Apache is talking to another server. I preferred the easier way to using the wsimport command as this is a simple client talking to a Siebel server. I will be using the Service Request ASI WSDL from a previous post.

You need to have the Java SDK installed and the paths properly configured on your system. Open up a command prompt window and type in  “java  -version” or “javac” to see if the paths have been added correctly.

Go ahead and import the wsdl using the command wsimport SR_WSDL.wsdl. Here I am running the command from the root of C: drive. You will see the importer at work generating class files.

clip_image002[9]

You can ignore any warnings you see as long as you don’t get any errors. wsimport would have created a nested folder structure with multiple class files. Here the path created is C:\com\siebel\xml\sm_servicerequest.

image

Now its time to start writing your main java file which will make an instance of these class files and trigger the integration to siebel. You will have to know which class represents the webservice, here it is SMServiceRequestWS_Service.class. You can also generate the actual java files to see how the class and methods under them have been defined. Inorder to do this, use the command wsimport –keep.

clip_image002[13]

This time wsimport will create the java files for each class file.

clip_image002[15]

Back to our main java file. Import the generated class files using:

import com.siebel.xml.sm_servicerequest.*;

As can be seen, this string is actually the path of the generated class files. This is what my final Client.java file looked like :

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

import com.siebel.xml.sm_servicerequest.*;

import java.io.Writer;

//the above namespace is from the generated code from the wsdl.

public class Client

{

static SMServiceRequestWS_Service service = new SMServiceRequestWS_Service();

public static void main(String[] args)

{

try

{

Client client = new Client();

client.doTest(args);

}

catch(Exception e)

{

e.printStackTrace();

}

}

public void doTest(String[] args)

{

try

{

SMServiceRequestWS pm = service.getSMServiceRequestWS();

// Building the Request hierachy

QueryPageSRInput req = new QueryPageSRInput();

req.setPageSize("10");

req.setViewMode("All");

req.setStartRowNum("0");

ListOfSmServicerequest list = new ListOfSmServicerequest();

ServiceRequest SR =new ServiceRequest();

list.getServiceRequest().add(SR);

req.setListOfSmServicerequest(list);

// Variable to store Response hierarchy

QueryPageSROutput res = new QueryPageSROutput();

// Invoke the service

System.out.println("Invoking the Webservice ");

res =pm.queryPageSR(req);

System.out.println(res.getLastPage());

for (int i = 0; i < res.getListOfSmServicerequest().getServiceRequest().size(); i++)

{

System.out.print(res.getListOfSmServicerequest().getServiceRequest().get(i).getStatus() + "\t");

System.out.print(res.getListOfSmServicerequest().getServiceRequest().get(i).getSRNumber() + "\t");

System.out.println(res.getListOfSmServicerequest().getServiceRequest().get(i).getOwner());

}

}

catch(Exception e)

{

e.printStackTrace();

}

}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

All the information you need to build up the request and parse out the response is in the .java files created by wsimport. As can be seen, the final code does not have any variables for the URL,namespace or SOAPAction. These details are taken care of in the .java files.

Time to compile and run the Client.java file. Commands are:

javac Client.java

java Client

The client instance should connect to the Siebel Webservice now :

image

This code runs a  Query and prints out the Service Request Status, RowId and Owner details.

That’s it !! This is all you need to have a java client invoking a Siebel Webservice.

1 comment:

  1. Nice Article. Made it easier to write Java client of Siebel web service.
    I am facing an issue in my client code. I have created SR object with its values. I've also created the input and output objects. But I cannot find the method in which I pass the input object and expect output object as return value. i.e. the actual call to web service is not happening. Please help.
    Thanks.

    ReplyDelete