Causes and treatment of java.io.IOException:Stream closed anomalies

Source: Internet
Author: User
Tags soap wsdl

Java.io.IOException:Stream closed


multiple threads index the same input stream, when a thread has finished executing, the InputStream is closed; the thread that reads information from the stream is thrown java.io.IOException: Stream closed exception.

   finally find out the origin of this anomaly, originally two pages call a JSP, the built-in object in this JSP
The exception that occurs when an out executes out.close (), that is, when a thread (corresponding to a JSP) finishes executing the
, the stream is closed, and another JSP that is reading the information from this stream is thrown 
java.io.IOException: Stream closed exception.

Modify the previous code:

Public object senddata (STRING JSONSTR)  {// 1.  Specifies the WebService namespace and method name of the call Soapobject  rpc = new soapobject (Namespace, methodname);// 2.  sets the parameter value of the calling method, which is optional, If the method has no parameters, you can omit this step rpc.addproperty ("arg000",  jsonstr);// 3.  generate the SOAP request information that calls the WebService method. Soapserializationenvelope envelope = new soapserializationenvelope (SOAPENVELOPE.VER11); envelope.encodingstyle =  "UTF-8";envelope.bodyout = rpc;//  Envelope.setoutputsoapobject (RPC);// 4.//  creates Httptransportse objects. The constructor of the Httptransportse class allows you to specify the Urlhttptransportse ht = new httptransportse of the WebService WSDL document ( URL);ht.debug = true;object detail1 = null;try {// 5.  Use the call method to invoke the WebService method Ht.call (Null, envelope);// detail =  (soapobject)   Envelope.getresponse ();// 6.  uses the GetResponse method to obtain the return result of the WebService method detail1 =  Envelope.getresponse ();}  catch  (ioexception e)  {// todo auto-generated catch blocke.printstacktrace ();}  catch  (xmlpullparserexception e)  {// TODO Auto-generated catch  Blocke.printstacktrace ();} Return detail1;}

Modified code:

Public object senddata (STRING JSONSTR)  {// 1.  Specifies the WebService namespace and method name of the call Soapobject  rpc = new soapobject (Namespace, methodname);// 2.  sets the parameter value of the calling method, which is optional, If the method has no parameters, you can omit this step rpc.addproperty ("arg000",  jsonstr);// 3.  generate the SOAP request information that calls the WebService method. Soapserializationenvelope envelope = new soapserializationenvelope (SOAPENVELOPE.VER11); envelope.encodingstyle =  "UTF-8";envelope.bodyout = rpc;//  Envelope.setoutputsoapobject (RPC);// 4.//  creates Httptransportse objects. The constructor of the Httptransportse class allows you to specify the Urlhttptransportse ht = new httptransportse of the WebService WSDL document ( URL);ht.debug = true;object detail1 = null;try {// 5.  Use the call method to invoke the WebService method Ht.call (Null, envelope);// detail =  (soapobject)   Envelope.getresponse ();// 6.  uses the GetResponse method to obtain the return result of the WebService method detail1 =  Envelope.getresponse ();}  catch  (ioexception e)  {// todo auto-generated catch blocke.printstacktrace (); System.out.println (New java.util.date ()  +  "Ioexception, resend the data"); try  {// 5.  use the call method to invoke the WebService method Ht.call (Null, envelope);// detail =  ( Soapobject)  envelope.getresponse ();// 6.  Use the GetResponse method to obtain the return result of the WebService method detail1 =  Envelope.getresponse ();}  catch  (IOEXCEPTION E1)  {// TODO  Auto-generated  catch  block E1.printstacktrace ();}  catch  (XMLPULLPARSEREXCEPTION E1)  {// TODO  Auto-generated  catch  Block E1.printstacktrace ();}}  catch  (xmlpullparserexception e)  {// TODO Auto-generated catch  Blocke.printstacktrace ();} Return detail1;}


This article is from the "CARLWU" blog, make sure to keep this source http://carlwu.blog.51cto.com/2329717/1617275

Causes and treatment of java.io.IOException:Stream closed anomalies

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.