Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    new DataOutputStream(connection.getOutputStream): connection refused issue

    Hi ,

    I am trying to send data to a 3rd party service by using below code. I get connection refused at line -wr = new DataOutputStream(connection.getOutputStream());

    I am able to see logs before the above line but jumps to exception block once it executes this block.

    The application is deployed on Wepsphere Application Server 7 and Websphere Portal Server 7. Have tried hitting the same url and proxy from server through perl script and browser, it works fine with these but breaks only when called from my code.
    Any idea why this breaks and what could be the solution on this?

    The RequisitionURL has https and have checked with application server and firewall team , they seem to have no issues with them.

    [CODE]
    System.setProperty("http.proxyHost", proxyHost);
    System.setProperty("http.proxyPort", proxyPort);

    final URL url = new URL(RequisitionURL);
    connection = (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setInstanceFollowRedirects(false);
    connection.setRequestMethod("Post");
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestProperty("charset", "utf-8");
    connection.setRequestProperty("Content-Length",Integer.toString(reqParameters.getBytes().length));
    connection.setUseCaches (false);
    LOGGER.info("Before getting output stream");
    wr = new DataOutputStream(connection.getOutputStream());
    LOGGER.info("Writing Data");
    wr.writeBytes(reqParameters);
    response.setStatus(connection.getResponseCode());
    wr.flush();
    wr.close();
    connection.disconnect();
    [CODE]

    Thanks
    Omkar

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Post the trace. Typically this error would indicate that there's a communication issue (often firewall), or that the socket established is incorrect. The firewall can block from either side and going in either direction.
    What is the requisitionURL variable? You mentioned its under ssl, so that should be using https which should interpret it properly unless its not on 443. An alternative is to not use the URL and use the Socket class instead to see if it gets you any further; the URL will rely on the system settings for the ports. Have you verified communication as well with the proxy machine and its ports between both the origin and destination machines?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    RequisitionURL has https in it..

    Have also tried with https as below
    [CODE]
    System.setProperty("https.proxyHost", proxyHost);
    System.setProperty("https.proxyPort", proxyPort);
    [CODE]


    Have attached screenshot(error.jpg)the trace logs for tested in console..Yes the communication has been verified by WAS team with the proxy machine and its ports between origin machine and destination machine.

    Only from my code we are not able to establish successful connection.

    Thanks
    Omkar
    Attached Thumbnails Attached Thumbnails new DataOutputStream(connection.getOutputStream): connection refused issue-error.jpg  

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    The cause is null, but I'm not sure at what point it's null (or what for that matter). It appears to be chained to the ibm packages.
    Cast your connection to an HttpsURLConnection instead to see if that will make the difference.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    New Coder
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Have tried with HttpsURLConnection as well..I am getting the same exception with this.

    Thanks
    Omkar

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    The only thing I can suggest than is to replace it with socket handling instead, or walk it through the debugger to find out what is null and why.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    New Coder
    Join Date
    Jun 2013
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Can you please let me know exactly how can this be done using socket. I have not much worked with socket programming.

    Thanks
    Omkar

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Start in this tutorial here: http://docs.oracle.com/javase/tutori...ets/index.html, it should layout the groundwork you need for how to handle and read/write using a socket connection.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •