So here is what I did ...
import java.io.*;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPEnvelope;
import org.w3c.dom.*;
public class AxisClientCall
{
public AxisClientCall()
{
}
public static void callService()
{
try {
String SOAPUrl = "https://exactEndPointURL";
String SOAPAction = "SOAPAction as Defined in WSDL";
String operName = "Operation Name as Defined in WSDL";
FileInputStream fin = new FileInputStream("SOAPRequest.xml");
SOAPEnvelope requestEnv = new SOAPEnvelope ((InputStream)fin);
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(SOAPUrl) );
call.setUseSOAPAction(true);
call.setSOAPActionURI(SOAPAction);
call.setEncodingStyle(null);
call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
call.setOperationName(new QName("", operName) );
SOAPEnvelope responseEnv = call.invoke(requestEnv );
System.out.println(" responseEnv = " + responseEnv);
if (responseEnv!=null)
{
Document doc = responseEnv.getAsDocument();
oracle.xml.parser.v2.XMLElement o = (oracle.xml.parser.v2.XMLElement) doc.getDocumentElement();
OutputStream out = System.out;
o.print(out);
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.toString());
}
}
public static void main(String[] args)
{
AxisClientCall AxisClientCall = new AxisClientCall();
AxisClientCall.callService();
}
}
There is good tutorial at http://java.sun.com/javaee/5/docs/tutorial/doc/bnbhr.html
That could be another approach to invoke SOAP service.
Thanks to countless developer folks on the web, the SOAP service call was finally built and tested successfully.
For https based service requests, you would need to import the site security certificate in java's keystore. If it is simple http, then no need to do anything. To make this java program work, I had to use following libraries.
j2ee-1.4.jar
commons-discovery-0.2.jar
axis-wsdl4j-1.2.1.jar
axis-jaxrpc-1.4.jar
axis.jar
axis-ant.jar
commons-logging-1.1.1.jar
No comments:
Post a Comment