aspose file tools*
The moose likes Servlets and the fly likes servlet to servlet communication from two different servers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet to servlet communication from two different servers" Watch "servlet to servlet communication from two different servers" New topic
Author

servlet to servlet communication from two different servers

prasad hagargi
Ranch Hand

Joined: Oct 21, 2002
Posts: 36
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
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
Note that getResponseCode involves reading the response before you send the data.

Bill


Java Resources at www.wbrogden.com
 
Don't get me started about those stupid light bulbs.
 
subject: servlet to servlet communication from two different servers
 
Similar Threads
Performance Issue: HttpURLConnection
applet to servlet
Simulating browser in a application
Uploading Image from Java Desktop App to Server
Imp-How to execute a JSP file from java main