Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HttpURLConnection getOutputStream() taking time  RSS feed

 
ravi suryavanshi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am facing some problem with HttpURLConnection.getOutputStream()method.
my application running on HP_UX(Hp unix) and Sun_os (Sun solaris). This method is responding properly to all the modules except one say ListOfVehicle. HttpURLConnection.getOutputStream() method is execuing on Application login and logout.
When i access ListOfVehicle module after that HttpURLConnection.getOutputStream() method is not behaving properly taking three to four minutes to respond. but when i m trying to connect same server from other application i m getting proper response.
i m resetting the connection and closing the buffer still is not working properly.


folloing is the code of sending data to servlet.

public class LogoutInterface {
private static final String CM_BASE = "com.siemens.mobile.applications.siefleet.provisioning.";

// public static void main(String[] args) {

private String tntURL;

public LogoutInterface() {
tntURL = "TnTURL";

}

//private SieMsSession session;
//review code TM0000148

HttpURLConnection fconn = null;
PrintWriter fout = null;
java.io.InputStream xmlInput = null;
String urlRedirect=null;

/*This Method is used to
* Getting Url connection
*
*
*/

private HttpURLConnection getURLConnection() throws SieMsException {
URL furl = null;
HttpURLConnection fconn = null;
try {
furl = new URL(getURL(tntURL));
System.err.println("ACRM URL" +tntURL);
fconn = (HttpURLConnection) furl.openConnection();
System.err.println("LogoutInterface.getURLConnection()::Connection Open");
fconn.setRequestMethod("POST");
fconn.setRequestProperty("Content-type", "text/xml");
fconn.setDoInput(true);
fconn.setDoOutput(true);
System.err.println("LogoutInterface.getURLConnection()::connection is" +fconn);
} catch (CMKeyNotFoundException e) {
System.err.println("LogoutAPI.getURLConnection() "
+ "TnTURL parameter is not defined in CM file");
throw new SieMsException(SieMsSession.nobodySession, e, 2, 200,
"TnTURL parameter is not defined in CM file", "LogoutData",
"");
} catch (MalformedURLException e) {
throw new SieMsException(SieMsSession.nobodySession, e, 2, 200, e
.getMessage(), "LogoutData", "");
} catch (IOException e) {
throw new SieMsException(SieMsSession.nobodySession, e, 2, 200, e
.getMessage(), "LogoutData", "");
}

return fconn;
}

/***************************************************************************
* XML data example to send ACRM
* <SessionDeletionVO> < FleetId >200101145</ FleetId > <LoginName>GB12</LoginName> </
* SessionDeletionVO >

*/
/**
* This Method used to send logout data to ACRM.When user click on logout button
* The above XML data will be send to ACRM
* @author vijay rajan
* @param String fleetId
* @param String String loginName
* @return - return a response string recieved from acrm()
*/
public String sendLogoutDataToACRM(String fleetId, String loginName)
throws SieMsException {
System.err.println("in sendLogoutDatato ACRM");
StringBuffer buffer = new StringBuffer();

buffer.append("<SessionDeletionVO>");
buffer.append("<LoginName>" + loginName + "</LoginName>");
buffer.append("<FleetId>" + fleetId + "</FleetId>");
buffer.append("</SessionDeletionVO>");

fconn = null;
try {
fconn = getURLConnection();
fconn.disconnect();
fconn = getURLConnection();
fconn.setReadTimeout(100);
System.err.println("geting url connection"+fconn);
/////////exactly where i m getting the problem/////////
OutputStream os = fconn.getOutputStream();
System.err.println("getoput stream");
os.write(buffer.toString().getBytes());
os.flush();
Document result = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);


DocumentBuilder parser = dbf.newDocumentBuilder();

xmlInput = fconn.getInputStream();
System.err.println("geting input stream");

result = parser.parse(xmlInput);

NodeList mainTag = result
.getElementsByTagName("SessionDeletionResponseVO");
Element mainTagElement = (Element) mainTag.item(0);
Element urlTag = (Element) mainTagElement.getElementsByTagName(
"acrmURL").item(0);
urlRedirect = ((Text) urlTag.getFirstChild()).getData()
.trim();
System.err.println("ACRM url is"+urlTag);
System.err.println("ACRM url is to redirect"+urlRedirect);
return urlRedirect;
} catch (IOException e) {
throw new SieMsException(SieMsSession.nobodySession, e, 2, 200, e
.getMessage(), "LoguotData", "");
} catch (Exception e) {
throw new SieMsException(SieMsSession.nobodySession, e, 2, 200, e
.getMessage(), "LogoutData", "");
} finally {
try {
fout.close();
fconn.disconnect();
xmlInput.close();
return urlRedirect;
} catch (Exception e) {
}
}


}
/*************************
* XML formate for data
* <SessionInformationVO>
* <sessionID>123456</sessionID >
* <fleetID>200101145</fleetID >
* <loginName>tntuser</loginName >
* <userOId>7315</userOId >
* </SessionInformationVO >
* @param fleetId
* @param loginName
* @throws SieMsException
* @author vijay rajan
* This method send data to ACRM at a login time.
*/




public void sendLoginDataToACRM(String sessionID, String sessFleetID, String sessLoginName)
throws SieMsException {
System.err.println("LogoutInterface.sendLoginDataToACRM::Start Sending Login Data ");
StringBuffer buffer = new StringBuffer();

buffer.append("<SessionInformationVO>");
buffer.append(" <sessionID>" + sessionID + "</sessionID>");
buffer.append("<fleetID>" + sessFleetID + "</fleetID>");
buffer.append("<loginName>" + sessLoginName + "</loginName>");
buffer.append("</SessionInformationVO>");



try {
fconn=null;
fconn = getURLConnection();
System.err.println("LoguotInterface.SendLoginDataToAcrm:: Geting URL Connection"+fconn);
/////////exactly where i m getting the problem/////////
OutputStream os = fconn.getOutputStream();
System.err.println("LoguotInterface.SendLoginDataToAcrm::geting output stream");
os.write(buffer.toString().getBytes());
os.flush();
System.err.println("LoguotInterface.SendLoginDataToAcrm: ata heve been send to ACRM");
System.err.println(buffer.toString());
System.err.println("ResponseCode: " + fconn.getResponseCode() + " "
+ fconn.getResponseMessage());
//Document result = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);


} catch (IOException e) {
throw new SieMsException(SieMsSession.nobodySession, e, 2, 200, e
.getMessage(), "LoguotData", "");
} catch (Exception e) {
throw new SieMsException(SieMsSession.nobodySession, e, 2, 200, e
.getMessage(), "LogoutData", "");

}


finally {
try {
fout.close();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}


}


private String getURL(String pURLName) throws CMKeyNotFoundException {
System.err.println("URL"+getMandatoryCMParameter(CM_BASE, pURLName));
return getMandatoryCMParameter(CM_BASE, pURLName);
}

public static String getMandatoryCMParameter(String pBase, String aKey)
throws CMKeyNotFoundException {
CMAdapterInterface cm = Adapters.singleton.af.getConfigurationManager();
System.err.println("LogOutAPI.getMandatoryCMParameter() inside..."
+ (pBase + aKey));
return cm.getElement(Adapters.singleton.rCtx, pBase + aKey);

}

}
 
ravi suryavanshi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the problem. I am setting the proxy in particular module and that proxy not exit that's why it is taking time. Connection is opening directly but when trying to send the data it is going through proxy and waiting for proxy. after time out it sends directly to server.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!