Proxysocks5 Stream Is Closed

P

Stream is closed error by closing connection - Stack Overflow

Stream is closed error by closing connection – Stack Overflow

I am using this function –
public BufferedReader GetResponse(String url, String urlParameters){
HttpsURLConnection con=null;
try{
URL obj = new URL(url);
con = (HttpsURLConnection) Connection();
//add reuqest header
tRequestMethod(“POST”);
// Send post request
tDoOutput(true);
DataOutputStream wr = new DataOutputStream(tOutputStream());
wr. writeBytes(urlParameters);
();
int responseCode = tResponseCode();
BufferedReader returnValue= new BufferedReader(new InputStreamReader(tInputStream()));
con. disconnect();
return returnValue;}
catch(Exception e){
(“——————–There is an error in response function “);
intStackTrace();
(“There is an arror in AjaxCAll function of login controller. “tMessage());
(“There is an arror in AjaxCAll function of login controller. “);
return null;}
finally{}}
If I am using this –
Then I am getting stream is closed error,
But if I comment the con. disconnect() line then everything is working fine. I don’t know why this is happening.
Calling function
BufferedReader rd = tResponse(url, urlParameters);
String line = “”;
while ((line = adLine())! = null) { //getting error here if i close connection in response method
// Parse our JSON response
responsString += line;
JSONParser j = new JSONParser();
JSONObject o = (JSONObject) (line);
if (ntainsKey(“response”)) {
restMessage = (Map) (“response”);} else {
restMessage = (Map) o;}}} finally{
();}
asked Mar 11 ’15 at 5:09
4
From JavaDoc of HttpURLConnection (which HttpsURLConnection extends):
Calling the disconnect() method may close the underlying socket if a persistent connection is otherwise idle at that time.
Inside your GetResponse() method, you got a reference to the HttpsURLConnection’s InputStream as a BufferedReader. However, when you used con. disconnect(), you closed that underlying InputStream.
In the code that calls the GetResponse() method, you when you later try to use the returned BufferedReader, you get an the stream is closed error because you have already indirectly closed that stream with con. disconnect().
You need to rearrange your code to not call con. disconnect() until you are finished with your BufferedReader.
This is one approach:
GetResponse():
public HttpsURLConnection GetResponse(String url, String urlParameters) {
HttpsURLConnection con = null;
DataOutputStream wr = null;
//add request header
wr = new DataOutputStream(tOutputStream());
catch(Exception e) { //better to catch more specific than Exception
finally{
if(wr! = null) {
();}}
return con;}
Calling code:
HttpsURLConnection con = tResponse(url, urlParameters);
if(con == null) {
//stop processing or maybe throw an exception depending on what you want to do. }
BufferedReader rd = null;
int responseCode = tResponseCode(); //what’s this for? nothing is being done with the variable
rd = new BufferedReader(new InputStreamReader(tInputStream()));
while ((line = adLine())! = null) {
restMessage = (Map) (“response”);}
else {
restMessage = (Map) o;}}}
//handle exception}
finally {
if(rd! = null) {
con. disconnect(); //we already checked if null above}
answered Mar 11 ’15 at 6:06
dbankdbank1, 1451 gold badge17 silver badges28 bronze badges
1
Not the answer you’re looking for? Browse other questions tagged java io stream urlconnection urlconnection or ask your own question.
stream closed error while connecting to PO | SAP Community

stream closed error while connecting to PO | SAP Community

0
May 03, 2019 at 09:25 AM
653 Views
Hi All,
We have multiple interfaces connecting to ECC system from PO system(PO–>ECC) using Bluecoat proxy.
We are getting the error “Message could not be forwarded to the JCA adapter. Reason: Read timed out”. As per the suggestions provided in portals, we have increased the Timeout parameter from 30 to 60 seconds and still the problem remains same. Then we tried with 90 seconds and now we are getting the error “Message could not be forwarded to the JCA adapter. Reason: Stream closed”.
Please help me in this.
ProxySOCKS5 (simple JSch API)

ProxySOCKS5 (simple JSch API)

All Implemented Interfaces:
Proxy
public class ProxySOCKS5
extends Object
implements Proxy
A Proxy implementation using a SOCKS V5 proxy.
This first authenticates to the proxy and then sends an CONNECT request
to connect to the desired server.
See Also:
RFC 1928: SOCKS Protocol Version 5,
RFC 1929: Username/Password Authentication for SOCKS V5
Constructor Summary
Constructors
Constructor and Description
ProxySOCKS5(String proxy_host)
Creates a new ProxySOCKS5 object.
ProxySOCKS5(String proxy_host,
int proxy_port)
Creates a new ProxyHTTP object.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods
Modifier and Type
Method and Description
void
close()
Closes the connection.
connect(SocketFactory socket_factory,
String host,
int port,
int timeout)
Opens a connection to the target server.
static int
getDefaultPort()
returns the default proxy port – this is 1080 as defined for SOCKS.
InputStream
getInputStream()
Returns an InputStream to read data from the remote server.
OutputStream
getOutputStream()
Returns an OutputStream to write data to the remote server.
Socket
getSocket()
Returns the socket used for the connection.
setUserPasswd(String user,
String passwd)
Sets the user name and password needed for authentication
to the proxy.
Methods inherited from class
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
ProxySOCKS5
public ProxySOCKS5(String proxy_host)
Parameters:
proxy_host – the proxie’s host name, maybe including the port
number separated by:. (The default port is 1080. )
public ProxySOCKS5(String proxy_host,
proxy_host – the proxie’s host name.
proxy_port – the port number of the proxy.
Method Detail
setUserPasswd
public void setUserPasswd(String user,
to the proxy. This has no relation to any authentication on
the target server.
If the proxy needs authentication, this method should be called
before calling connect(,, int, int) (i. e. before passing the Proxy
object to the JSch library).
This class supports the “No Authentication Required” method as well
as the “UserName/Password” method.
user – the user name
passwd – the password.
connect
public void connect(SocketFactory socket_factory,
throws JSchException
Description copied from interface: Proxy
After successful invocation of this method the other methods
can be called to retrieve the results.
Specified by:
connect in interface Proxy
socket_factory – a factory for sockets. Might be null, then
the implementation will use plain sockets.
host – the SSH server host we want to connect to.
port – the port at the SSH server.
timeout – how long to wait maximally for a connection, in
milliseconds. If 0, wait as long as needed.
Throws:
JSchException
getInputStream
public InputStream getInputStream()
If the SSH protocol is tunneled through another protocol for
proxying purposes, this InputStream has to do the unwrapping.
getInputStream in interface Proxy
getOutputStream
public OutputStream getOutputStream()
proxying purposes, this OutputStream has to do the wrapping.
getOutputStream in interface Proxy
getSocket
public Socket getSocket()
This will only be used for timeout-configurations.
getSocket in interface Proxy
close
public void close()
Closes the connection. This should close the underlying socket as well.
close in interface Proxy
getDefaultPort
public static int getDefaultPort()
returns the default proxy port – this is 1080 as defined for SOCKS.

Frequently Asked Questions about proxysocks5 stream is closed

About the author

proxyreview

If you 're a SEO / IM geek like us then you'll love our updates and our website. Follow us for the latest news in the world of web automation tools & proxy servers!

By proxyreview

Recent Posts

Useful Tools