• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Quest to make Client SOAP freely communicate with a SOAP service

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Kiran Kumar
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic