Results 1 to 3 of 3
- 06-26-2010, 02:17 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 1
- Rep Power
- 0
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
- 06-26-2010, 03:05 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
- 06-27-2010, 02:14 AM #3
Similar Threads
-
java.sql.SQLException: Closed Connection
By sunjavaboy in forum JDBCReplies: 4Last Post: 03-21-2012, 01:38 PM -
DSRA9110E: Connection is closed.
By amitsingh379 in forum Java ServletReplies: 0Last Post: 04-26-2010, 07:35 AM -
Socket connection - MIDlet
By arun10427 in forum CLDC and MIDPReplies: 2Last Post: 01-26-2010, 02:51 AM -
Error opening socket: java.net.ConnectException: Connection refused: connect
By somersst in forum Java ServletReplies: 3Last Post: 01-26-2009, 05:30 PM -
How To Make Socket Connection
By madhumurundi in forum NetworkingReplies: 5Last Post: 04-21-2008, 06:05 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks