Results 1 to 3 of 3
  1. #1
    veeru541 is offline Member
    Join Date
    Jun 2010
    Posts
    1
    Rep Power
    0

    Default Java.net.socket connection :connection closed

    HI,
    I wrote a code to invoke webservices through java code, but i am getting java.net.socket connection :connection closed.Please help me in resolving it.
    Also i am able to connect the same webservices through the IE but when i am executing this code , i am getting java.net.socket exception Connection closed exception. Please help me in this regard.

    Please find the Java Code for the same:

    package com.witribe.brm.ws;

    import java.io.*;
    import java.net.*;
    import org.apache.log4j.Logger;
    import org.apache.log4j.xml.DOMConfigurator;
    import java.util.Properties;

    public class BRMWebService {

    private static Logger log = Logger.getLogger(BRMWebService.class);

    public static void sendSOAPRequest(String request) throws MalformedURLException,
    ProtocolException, FileNotFoundException, IOException
    {


    Properties props = new Properties();

    props.load(new FileInputStream("./OSMCartridge.properties"));

    DOMConfigurator.configure("./log4jConfiguration.xml");

    String inputLine;

    String response = "";

    String SOAPUrl = props.getProperty("brm.webserviceurl");

    String SOAPAction = props.getProperty("brm.webservicesoapaction");

    //"http://crm.wi-tribe.net.pk/infranetwebsvc/services/Infranet?wsdl"

    log.info("\nCalling BRM Web Service with request\n"+request+"\nWeb Service URL : "+SOAPUrl);

    URL url = new URL(SOAPUrl);

    //URLConnection connection = url.openConnection();

    //HttpURLConnection httpConn = (HttpURLConnection) connection;
    HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();

    ByteArrayOutputStream bout = new ByteArrayOutputStream();

    byte buf[] = request.getBytes();

    bout.write(buf);

    byte[] b = bout.toByteArray();

    httpConn.setRequestProperty("SOAPAction",SOAPActio n);

    httpConn.setRequestMethod("POST");
    // httpConn.setRequestMethod("GET");
    httpConn.setDoOutput(true);

    httpConn.setDoInput(true);

    httpConn.setConnectTimeout(54000);

    OutputStream out = httpConn.getOutputStream();

    out.write(b);
    httpConn.connect();

    out.close();

    // int code=((HttpURLConnection) httpConn).getResponseCode();
    // int code= httpConn.getResponseCode();

    //if(code==200) {
    if (httpConn.getResponseCode() == 200){

    InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());

    BufferedReader in = new BufferedReader(isr);

    inputLine="";

    response = "";

    while ((inputLine = in.readLine()) != null) {

    response = response + inputLine;

    }
    in.close();
    }
    else {
    InputStreamReader isr = new InputStreamReader(httpConn.getErrorStream());

    BufferedReader in = new BufferedReader(isr);

    inputLine="";

    response = "";

    while ((inputLine = in.readLine()) != null) {

    response = response + inputLine;
    }
    in.close();
    }

    log.debug("\nReceived BRM Web Service response\n"+response);

    }

    }
    Regards
    V Ravi Kiran

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,532
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by veeru541 View Post
    HI,
    I wrote a code to invoke webservices through java code, but i am getting java.net.socket connection :connection closed.Please help me in resolving it.
    Also i am able to connect the same webservices through the IE but when i am executing this code , i am getting java.net.socket exception Connection closed exception. Please help me in this regard.
    At the top of the API documentation for the HttpURLConnection it reads:

    Quote Originally Posted by API Documentation
    Each HttpURLConnection instance is used to make a single request but the underlying network connection to the HTTP server may be transparently shared by other instances. Calling the close() methods on the InputStream or OutputStream of an HttpURLConnection after a request may free network resources associated with this instance but has no effect on any shared persistent connection.
    But of course you haven't read it; why should you? Nobody does ...

    kind regards,

    Jos

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    i am getting java.net.socket exception Connection closed exception
    Where in your code does that happen?

Similar Threads

  1. java.sql.SQLException: Closed Connection
    By sunjavaboy in forum JDBC
    Replies: 4
    Last Post: 03-21-2012, 01:38 PM
  2. DSRA9110E: Connection is closed.
    By amitsingh379 in forum Java Servlet
    Replies: 0
    Last Post: 04-26-2010, 07:35 AM
  3. Socket connection - MIDlet
    By arun10427 in forum CLDC and MIDP
    Replies: 2
    Last Post: 01-26-2010, 02:51 AM
  4. Replies: 3
    Last Post: 01-26-2009, 05:30 PM
  5. How To Make Socket Connection
    By madhumurundi in forum Networking
    Replies: 5
    Last Post: 04-21-2008, 06:05 PM

Posting Permissions

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