This discussion is archived
9 Replies Latest reply: Apr 1, 2011 1:05 AM by 818594 RSS

getting java.net.SocketException: Connection reset

818594 Newbie
Currently Being Moderated
Dear all,
In this code I am getting one error.....
System.getProperties().put( "proxySet", "true" );
System.getProperties().put( "proxyHost", "hostIp" );
System.getProperties().put( "proxyPort", "port" );

URL url = new URL(gateWayURL);
int initLength = messageToSend.length();
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();

String userPassword = username + ":" + paswd;
sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
String encodedUserPwd =encoder.encode(userPassword.getBytes());
System.out.println("encoded pswd: "+encodedUserPwd);
conn.setRequestProperty("Proxy-Authorization", "Basic" + encodedUserPwd);

conn.setDoInput(true);
conn.setDoOutput(true);
conn.setDefaultUseCaches(false);
conn.setRequestProperty("Content-length",
String.valueOf(initLength));
conn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
conn.setRequestMethod("POST");
conn.setFollowRedirects(true);


LF.write("Writing data to Stream . . . .", LogFile.STATEMENT);
BufferedWriter out =
new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));

out.write(messageToSend);
out.flush();
LF.writeln("SUCCESS", LogFile.STATEMENT);


Here I added my log file also..

.Writing data to Stream . . . .java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:197)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:229)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:267)
at java.io.BufferedInputStream.read(BufferedInputStream.java:324)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:636)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:585)
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:1302)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:598)
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:1302)
at com.ibm.net.ssl.www2.protocol.https.c.connect(c.java:31)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:865)
at com.ibm.net.ssl.www2.protocol.https.a.getOutputStream(a.java:54)
at xxscc.oracle.apps.xtr.b2b.ssl.utils.MessageSender.sendMessage(MessageSender.java:186)
at xxscc.oracle.apps.xtr.b2b.txn.handlers.MT940StatementRequestHandler.handleTransactionRequest(MT940StatementRequestHandler.java:274)
at xxscc.oracle.apps.xtr.b2b.cp.SccB2BInterface.runProgram(SccB2BInterface.java:91)
at oracle.apps.fnd.cp.request.Run.main(Run.java:157)
ERROR : Connection reset


If any one know about this issue pls help me
  • 1. Re: getting java.net.SocketException: Connection reset
    EJP Guru
    Currently Being Moderated
    System.getProperties().put( "proxySet", "true" );
    Does nothing. Remove.
    System.getProperties().put( "proxyHost", "hostIp" );
    System.getProperties().put( "proxyPort", "port" );
    Use http.proxyHost and http.proxyPort.
    conn.setRequestProperty("Content-length", String.valueOf(initLength));
    Remove. Java will do that for you, and get iit right too.
    .Writing data to Stream . . . .java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:197)
    That usually means that you wrote to a connection that had already been closed by the other end. Could have been caused by a bad HTTP proxy. Are you sure that thing is an HTTP proxy?
  • 2. Re: getting java.net.SocketException: Connection reset
    818594 Newbie
    Currently Being Moderated
    Hi,
    I am very new in this side.I am not sure this is an HTTP proxy.How we can find it.
    Now I used
    System.getProperties().put("https.proxySet", "true");
    System.getProperties().put("https.proxyHost", serviceConsumerEnvInfo.getHostNameIPAddress());
    System.getProperties().put("https.proxyPort", String.valueOf(serviceConsumerEnvInfo.getProxyPort()));


    System.getProperties().put("http.proxySet", "true");
    System.getProperties().put("http.proxyHost", serviceConsumerEnvInfo.getHostNameIPAddress());
    System.getProperties().put("http.proxyPort", String.valueOf(serviceConsumerEnvInfo.getProxyPort()));
  • 3. Re: getting java.net.SocketException: Connection reset
    EJP Guru
    Currently Being Moderated
    I am very new in this side.I am not sure this is an HTTP proxy.How we can find it.
    Ask somebody? Where did you get the original information from? One thing for sure, nobody here can tell.
    [reordered]
    System.getProperties().put("https.proxySet", "true");
    Remove. That does even less than the other one.
    System.getProperties().put("http.proxySet", "true");
    Ditto.
    System.getProperties().put("https.proxyPort", String.valueOf(serviceConsumerEnvInfo.getProxyPort()));
    System.getProperties().put("http.proxyPort", String.valueOf(serviceConsumerEnvInfo.getProxyPort()));
    I don't find it very likely that an HTTP proxy will be using the same port as an HTTPS proxy.
  • 4. Re: getting java.net.SocketException: Connection reset
    818594 Newbie
    Currently Being Moderated
    hello,
    with certificate only we are sending the request.I think the Port is Https only.can I use Https onle..
  • 5. Re: getting java.net.SocketException: Connection reset
    818594 Newbie
    Currently Being Moderated
    System.getProperties().put("https.proxyHost", serviceConsumerEnvInfo.getHostNameIPAddress());
    System.getProperties().put("https.proxyPort", String.valueOf(serviceConsumerEnvInfo.getProxyPort()));

    Authenticator.setDefault(new Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
    return new
    PasswordAuthentication("mydomain\\username","pswd".toCharArray());


    LF.writeln("B2B Gateway URL : " + gateWayURL, LogFile.STATEMENT);
    URL url = new URL(gateWayURL);


    LF.write("Contacting B2B Gateway URL . . . .", LogFile.STATEMENT);
    HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();

    LF.write("Retrive data from another Site . . . .", LogFile.STATEMENT);
    conn.setDoInput(true);
    conn.setDoOutput(true);
    conn.setDefaultUseCaches(false);
    // conn.setRequestProperty("Content-length",
    // String.valueOf(initLength));
    conn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
    conn.setRequestMethod("POST");
    conn.setFollowRedirects(true);
    LF.writeln("SUCCESS", LogFile.STATEMENT);

    LF.write("Writing data to Stream . . . .", LogFile.STATEMENT);
    BufferedWriter out =
    new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));

    out.write(messageToSend);
    out.flush();
    LF.writeln("SUCCESS", LogFile.STATEMENT);


    Now I am getting the same error
  • 6. Re: getting java.net.SocketException: Connection reset
    EJP Guru
    Currently Being Moderated
    So what did you find out when you asked about the proxy?
  • 7. Re: getting java.net.SocketException: Connection reset
    818594 Newbie
    Currently Being Moderated
    Dear Friend,
    Now I used HTTPS only and I used password authenticator class..
    Here I added my log file.pls find it and help me


    Writing data to Stream . . . .java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy service is denied. )"
         at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:1353)
         at com.ibm.net.ssl.www2.protocol.https.c.connect(c.java:31)
         at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:865)
         at com.ibm.net.ssl.www2.protocol.https.a.getOutputStream(a.java:54)
         at xxscc.oracle.apps.xtr.b2b.ssl.utils.MessageSender.sendMessage(MessageSender.java:198)
         at xxscc.oracle.apps.xtr.b2b.txn.handlers.MT940StatementRequestHandler.handleTransactionRequest(MT940StatementRequestHandler.java:274)
         at xxscc.oracle.apps.xtr.b2b.cp.SccB2BInterface.runProgram(SccB2BInterface.java:91)
         at oracle.apps.fnd.cp.request.Run.main(Run.java:157)
    RESPONSE CODE : 407
    Response Code from Server :407
    RESPONSE TEXT : Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy service is denied. )
    Response String from Server :Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy service is denied. )
    ERROR : Internal Server Problem
  • 8. Re: getting java.net.SocketException: Connection reset
    EJP Guru
    Currently Being Moderated
    Now I used HTTPS only and I used password authenticator class.
    That will authenticate you to the endpoint, not to the proxy. I'm not aware of any way to do proxy authentication in Java other than by manually setting the appropriate headers, which you will have to look up in the HTTP 1.1 specification.
  • 9. Re: getting java.net.SocketException: Connection reset
    818594 Newbie
    Currently Being Moderated
    really thanks for your reply

    Edited by: aneeshmathew on Apr 1, 2011 1:05 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points