Dear All,
First of all thanks to Bill for providing Snoop utility to monitor message communication between
SOAP Client and Server.
In my quest to write a Soap-independent Client which communicates with a SOAP server, I have come up with a client which looks like this
-------------------------------------------------
import java.io.*;
import java.net.*;
import java.util.*;
public class CalcClientHttp {
public static void main(
String[] args) throws Exception {
URL url = new URL("http://localhost/soap/servlet/rpcrouter");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(connection.getOutputStream());
String payload = " POST /soap/servlet/rpcrouter HTTP/1.0 \n Host: localhost \n Content-Type: text/xml; charset=utf-8 \n Content-Length: 403 \n <?xml version='1.0' encoding='UTF-8'?> \n <SOAP-ENV:Envelope \n xmlns:SOAP-ENV= \"http://schemas.xmlsoap.org/soap/envelope/\" \n xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" \n xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\"> \n <SOAP-ENV:Body> \n <ns1
rint xmlns:ns1=\"urn
njavaserver\" \n SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"> \n </ns1
rint> \n </SOAP-ENV:Body> \n </SOAP-ENV:Envelope> \n ";
out.write(payload);
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
StringBuffer sb = new StringBuffer();
while((line = in.readLine()) != null) {
sb.append(line);
}
out.close();
in.close();
System.out.println(sb.toString());
}
}
-------------------------------------------------
When I try running the Client using "java CalcClient", I get the following error.
__________________________________________
Exception in
thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL:
http://localhost/soap/servlet/rpcrouter at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:709)
at CalcClientHttp.main(CalcClientHttp.java:16)
_______________________________________________
Does the XML payload the client sends, needs to be encoded? If yes, how can we do that?
A Soap client spends lots of time building XML payload to be sent to the server. By hard coding the XML payload, I am guessing this communication will be much much faster.
Pointers are appreciated.
Thanks,
Kiran Devaram
Kansas State University
devaram@ksu.edu