<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="javax.xml.soap.SOAPFactory" import="javax.xml.soap.SOAPElement" import="javax.xml.soap.SOAPException" %> startprocess.jsp

Web Service API - Sample




<% // Process template settings String myOperation = "operation1"; // Interface editor: we did use the default String myPortTypeName = "advertiseProcessInterface"; // see Interface editor String myInterfaceURI = "http://WSApiModule/"+myPortTypeName; // see IF editor String myNamespacePrefix = "mynsprefix"; // can be any value String myProcessTemplateName = "advertiseProcess"; // Data received from HTML form String myFName = (String) request.getParameter("fname"); // first name String myLName = (String) request.getParameter("lname"); // last name String mySName = (String) request.getParameter("sname"); // street name String myCName = (String) request.getParameter("cname"); // city name // assemble the SOAP message SOAPElement mySoapMessage = null; try { SOAPFactory mySoapFactoryInstance = SOAPFactory.newInstance(); // define elements and link them together as defined in objects BO_Customer and BO_Address mySoapMessage = mySoapFactoryInstance.createElement(myOperation, myNamespacePrefix, myInterfaceURI); // define the BO_Customer object SOAPElement myInputElement = mySoapFactoryInstance.createElement("customer"); SOAPElement myInputElement1 = mySoapFactoryInstance.createElement("firstName"); myInputElement1.addTextNode(myFName); myInputElement.addChildElement(myInputElement1); SOAPElement myInputElement2 = mySoapFactoryInstance.createElement("lastName"); myInputElement2.addTextNode(myLName); myInputElement.addChildElement(myInputElement2); // define the BO_Customer object SOAPElement myInputElement3 = mySoapFactoryInstance.createElement("address"); SOAPElement myAddressElement1 = mySoapFactoryInstance.createElement("street"); myAddressElement1.addTextNode(mySName); myInputElement3.addChildElement(myAddressElement1); SOAPElement myAddressElement2 = mySoapFactoryInstance.createElement("city"); myAddressElement2.addTextNode(myCName); myInputElement3.addChildElement(myAddressElement2); myInputElement.addChildElement(myInputElement3); mySoapMessage.addChildElement(myInputElement); } catch (Exception e) { System.out.println("Error while creating SOAP element: "+e); e.printStackTrace(System.out); } // prepare parameters for starting the process com.ibm.www.SendMessage myCallParameters = new com.ibm.www.SendMessage(); myCallParameters.set_any(mySoapMessage); myCallParameters.setProcessTemplateName(myProcessTemplateName); myCallParameters.setOperation(myOperation); javax.xml.namespace.QName myPortTypeQName = new javax.xml.namespace.QName(myInterfaceURI, myPortTypeName); myCallParameters.setPortType(myPortTypeQName); com.ibm.www.SendMessageResponse mySendMessageResponse = null; try { mySendMessageResponse = MyBFMAccess.sendMessage(myCallParameters); } catch (Exception e) { System.out.println("Error while doing call: "+e); e.printStackTrace(System.out); } if (mySendMessageResponse == null || mySendMessageResponse.getPIID() == null) { out.println("No response available; please inspect server logs for possible problems."); System.out.println("Call failed, no response to be processed"); } else { String myPIID = mySendMessageResponse.getPIID(); out.println("Asynchronous process started successfully.

"); out.println("Follow this link to see the process status and to inspect the results.
"); System.out.println("Process started, PIID = "+mySendMessageResponse.getPIID()); } // end if %>

Advanced sample - Home