aspose file tools*
The moose likes Web Services and the fly likes Quest to make Client SOAP freely communicate with a SOAP service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Quest to make Client SOAP freely communicate with a SOAP service" Watch "Quest to make Client SOAP freely communicate with a SOAP service" New topic
Author

Quest to make Client SOAP freely communicate with a SOAP service

Kiran Kumar
Ranch Hand

Joined: Jan 06, 2003
Posts: 91
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


------------<br />SCJP
Kiran Kumar
Ranch Hand

Joined: Jan 06, 2003
Posts: 91
Hurray! It worked at last. I wasnt taking care of the \ns and ctrlFs in the SOAP XML document that I was sending to the server.
Thanks anyway,
Kiran Devaram
Kansas State University
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
In SOAP discussions, I like to mention Glue. With one or two lines you can publish any Java class as a SOAP service, or bind any Java client to a remote service. See it at The Mind Electric


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
Don't get me started about those stupid light bulbs.
 
subject: Quest to make Client SOAP freely communicate with a SOAP service