This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
I am trying to create a servlet that serves as a broker within a 'web services' model. For example - there exists a web service that upon receiveing the correct HTTP GET request, in XML format, it will return to me a JPG formatted image of my choice. My servlet actually receives a request first, as its the real client app, but if I don't have that image I go and get it from this external web service.
An example GET request that I'll generate to send out to the service might be:
String XMLRequest= ""
I send this string using a simple URLConnection Object, for example:
URL url = new URL("http://10.3.1.56/imageserver.asp"); URLConnection connection = url.openConnection(); connection.setDoOutput(true); PrintWriter out1 = new PrintWriter(connection.getOutputStream()); out1.println(XML_Request); out1.close();
Now I want to get my response off that connection:
BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
The problem is that I do not always know what I will get back. If the image is unavailable or my request string is bad, I'll get an XML error message back...like: