how to call esp process or webservice from jsp

Posted by Admin on 02-Sep-2008 05:02

Hi all,

how to call a webservice using sonic from jsp, and get back the output to jsp.

I m able to create webservice invocation and pass a file or literal and getting the output to sonic console.

can anybody explain clearly stepwise.

means flow, where to create and run jsp in sonic and

whether to call directly webservice invocation(wsdl) or make it a process and how to call this process.

Thanks in advance.

vishwa.

All Replies

Posted by rstanciu on 02-Sep-2008 06:21

are you check the standard documentation ?

http://www.psdn.com/library/entry.jspa?externalID=2743&categoryID=1353

Posted by Admin on 03-Sep-2008 23:16

Hi,

Thank you for ur response,

As i m very much interested in sonic. so give suggestion.

and first help to solve this.

I have created a webservice invocation and esb process.

and i drag this webservice into esb process, below this a java service type i created without making any changes to this file.

like this

O

webservice invocation( a wsdl file)

java service type(creating this file and uploading without any changes)

|

O

to this process while running i passing esbmessage file.

in esbmessage file clicked on add did not do any changes to this and in from file passing a test.csv file

i did not got much info from that link. i want to know like what changes i need to do jms listener so on.........

my work to call the process from web application (JSP), request and response real time.

Thanks in advance

Posted by rstanciu on 04-Sep-2008 05:20

If I well understand, you wants to call the exposed Sonic Process from jsp (tomcat?).

check this:

http://www.psdn.com/library/servlet/JiveServlet/download/48-11727-37488-27978/Capture1.png

http://www.psdn.com/library/servlet/JiveServlet/download/48-11727-37488-27979/Capture2.png

http://www.psdn.com/library/servlet/JiveServlet/download/48-11727-37488-27980/Capture3.png

http://www.psdn.com/library/servlet/JiveServlet/download/48-11727-37488-27980/Capture4.png

http://www.psdn.com/library/servlet/JiveServlet/download/48-11727-37488-27980/Capture3.png

I create a ESB process(1) and I create the interface WSDL (2), upload the process,

take the Management Console and deploy the process into a container ESB (3)(4).

Create a WS Invocation to test (5).

now from java (jsp) what you need to install Java Axis (from apache).

add your classpath:

AXIS_PATH="$CATALINA_HOME/webapps/axis/WEB-INF/lib";

AXIS_CLASSPATH="$AXIS_PATH/axis.jar:$AXIS_PATH/commons-discovery-0.2.jar";

AXIS_CLASSPATH="$AXIS_CLASSPATH:$AXIS_PATH/commons-logging-1.0.4.jar:$AXIS_PATH/jaxrpc.jar";

AXIS_CLASSPATH="$AXIS_CLASSPATH:$AXIS_PATH/log4j-1.2.8.jar:$AXIS_PATH/saaj.jar:$AXIS_PATH/wsdl4j-1.5.1.jar";

OUTPUTPATH="/tmp";

WEB_SERVICE="http://localhost:2580/process/YourEsbProcessName?wsdl";

and start :

java -cp $AXIS_CLASSPATH org.apache.axis.wsdl.WSDL2Java

-o $OUTPUTPATH $WEB_SERVICE;

This command create for you the sckeleton for consoming the service.

this is an sample java code to start cosuming a web-service with JavaAxis:

import java.io.*;

import java.lang.*;

import java.net.*;

import java.util.*;

import javax.xml.rpc.holders.*;

import javax.xml.rpc.handler.soap.SOAPMessageContext;

import org.apache.axis.Message;

import org.apache.axis.MessageContext;

import org.apache.axis.message.SOAPEnvelope;

import org.apache.axis.message.SOAPHeaderElement;

import org.apache.axis.utils.Messages;

import org.apache.commons.logging.Log;

import org.apache.axis.AxisFault;

import org.w3c.dom.Element;

import org.w3c.dom.Node;

import org.w3c.dom.Document;

import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import java.net.URL;

import javax.xml.soap.SOAPException;

import javax.xml.soap.*;

import java.util.Random;

/Progress/

import details.soap_fault.*;

import RPCEncoded.prgs.*;

public class TestService {

public String SValidateCustomer (Integer iCustNum) throws Exception {

WSTKRPCEncodedService service = new WSTKRPCEncodedServiceLocator();

URL connectURL = new URL(service.getWSTKRPCEncodedObjAddress());

WSTKRPCEncodedObjStub validateCustomer =

(WSTKRPCEncodedObjStub)service.getWSTKRPCEncodedObj(connectURL);

try {

StringHolder customerNameHolder = new StringHolder();

StringHolder resultHolder = new StringHolder();

validateCustomer.getCustomerName(iCustNum.intValue(),

customerNameHolder);

String customerName = new String(customerNameHolder.value);

return customerName;

} catch (Exception e)

return null;

} //SValidateCustomer

public String SGetInvoice (Integer iInvoiceNum) throws Exception {

WSTKRPCEncodedService service = new WSTKRPCEncodedServiceLocator();

URL connectURL = new URL(service.getWSTKRPCEncodedObjAddress());

WSTKRPCEncodedObjStub validateInvoice =

(WSTKRPCEncodedObjStub)service.getWSTKRPCEncodedObj(connectURL);

try {

String sInvoice;

StringHolder InvoiceHolder = new StringHolder();

StringHolder resultHolder = new StringHolder();

validateInvoice.getInvoice(iInvoiceNum.intValue(),

InvoiceHolder);

String s = new String(InvoiceHolder.value);

try {

File f = new File("Invoice.xml");

FileOutputStream fs = new FileOutputStream(f);

fs.write(s.getBytes(),0,InvoiceHolder.value.length());

} catch (IOException e)

return s;

} catch (Exception e)

return null;

} //SGetInvoice

public static void main(String[] args) {

TestService tst = new TestService();

try {

String s;

s = tst.SValidateCustomer (new Integer(3));

System.out.println (s);

s = tst.SGetInvoice (new Integer(5));

System.out.println (s);

} catch (Exception e)

} //main

} //class

Hope it helps !

Rares

Posted by dmillman on 04-Sep-2008 08:05

Note, that the typical way to invoke an ESB Process from a servlet is to embed the JMS client in the call. This way you get the benefit of CAA and the messaging paradigm.

This thread is closed