• 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

servlet to servlet communication from two different servers

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there,when i am trying to send a binary data using the below mentioned method in a servlet,i am getting error as ".java.net.ProtocolException: Cannot write output after reading input."
The target URL is a servlet on another server,what can be the reason
public void forwardRequest(String strURL,String strReqPacket){
try{
//get the url to be invoked.

URL url = new URL(strURL);
HttpURLConnection urlConn = (HttpURLConnection)url.openConnection();
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.connect();
//get the response code
String strResponseCode = urlConn.getResponseCode();

//send the binary data of the request
DataOutputStream printout = new DataOutputStream (urlConn.getOutputStream ());
String strContent = strReqPacket;
printout.writeBytes(strContent+"\n");
printout.flush ();
printout.close ();

//read the response
InputStream is = urlConn.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String response = in.readLine();
System.out.println(response);
while(response!=null){
System.out.println(response);
response = in.readLine();
}

}catch(IOException ioe){
System.out.println("....exception in .CommunicationController.forwardRequest()."+ioe);
}//end of try catch


}//end of method forwardRequest
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that getResponseCode involves reading the response before you send the data.

Bill
 
Your mind is under my control .... your will is now mine .... read this tiny ad
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic