File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Problem in reading the InputStream and setting the cookie value after applying the SSL(Using https). Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem in reading the InputStream and setting the cookie value after applying the SSL(Using https)." Watch "Problem in reading the InputStream and setting the cookie value after applying the SSL(Using https)." New topic

Problem in reading the InputStream and setting the cookie value after applying the SSL(Using https).

sambasiva kumar

Joined: Jan 16, 2007
Posts: 24

I am getting the following error while trying to read from the Inputstream.
It is failing to set the cookie value.
Could you please suggest me how to set the cookie in the Sun-ONE-Web-Server 6.1.
I tried by including the

<session-manager persistence-type="memory">
<property name="reapIntervalSeconds" value="20" />
<property name="enableCookies" value="true" />
<property name="cookiePath" value="/" />
<property name="cookieMaxAgeSeconds" value="-1" />

in the sun-web.xml.

Please find the code that I am using.
public synchronized PageWrapper processRequest(PageWrapper pWrapper) {
Console.println("inside processRequest urlCurrentPage = "+FISConstants.urlCurrentPage);
if(FISConstants.urlCurrentPage == null) {
Console.println("url is null application is running");
// This Condition will be true if it is run as a application
try {
// Uncomment below 2 lines to run it as a application
// NavigationController aNavController = NavigationController.getInstance();
// pWrapper = aNavController.onEvent(pWrapper);
} catch (Exception e ) {
return pWrapper;
if(!connectServlet()) {
pWrapper.setErrorMessage("Could not connect to servlet");
return pWrapper;
if(cookie == null) cookie = readCookie(connection);
System.out.println("The value of cookie in the process request is ............... "+ cookie);
return receiveRequest();

private boolean sendRequest(PageWrapper pWrapper) {
ObjectOutputStream out = null;
try {
System.out.println("Inside sendRequest");
out = new ObjectOutputStream(connection.getOutputStream());
catch (Exception e) {
return false; //return false in case of Exception
finally {
try {
if(out != null)
} catch(Exception e) {
Console.println("Unable to close Connection"+e);

return true;

private PageWrapper receiveRequest() {

PageWrapper pWrapper = null;
ObjectInputStream in = null;
try {
System.out.println("Inside receiveRequest");
in = new ObjectInputStream(connection.getInputStream());
System.out.println("The Object Input Stream is .............." + in);
pWrapper = (PageWrapper)in.readObject();
System.out.println("The page wrapper Object is .............." + pWrapper);

catch(Exception e) {
pWrapper = new PageWrapper();
finally {
try {
if(in != null)
} catch(Exception e) {
Console.println("Unable to close Connection");
return pWrapper;

private boolean connectServlet() {
try {
connection = (HttpsURLConnection)dataURL.openConnection();
System.out.println("Connecion in connectServlet is ................." + connection);
//Console.println("URL is " + dataURL);
if( cookie != null ) connection.setRequestProperty(FISConstants.COOKIE,cookie);
catch (Exception e) {
return false; //In case of Exception returns false
return true;

private String readCookie(URLConnection con) {
String key;
String value;
for( int i = 1; ( key = con.getHeaderFieldKey( i ) )!= null; ++i ){
key = key.toLowerCase();
Console.println("Key is " + key + " Value is " + con.getHeaderField(i));
if( key.equals(FISConstants.SET_COOKIE) ){
value = con.getHeaderField( i );
return value;
return null;

SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance("TLS");
X509TrustManager[] xtmArray = new X509TrustManager[] { xtm };
sslContext.init( null, xtmArray, new );
} catch( GeneralSecurityException gse ) {
// Print out some error message and deal with this exception…
// Set the default SocketFactory and HostnameVerifier
// for
if( sslContext != null ) {
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory() );
HttpsURLConnection.setDefaultHostnameVerifier( hnv );

private X509TrustManager xtm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain,
String authType) {}
public void checkServerTrusted(X509Certificate[] chain,
String authType) {
public X509Certificate[] getAcceptedIssuers() {
return null;

//Added by Sambasiva for implementation of Https
private HostnameVerifier hnv = new HostnameVerifier() {
public boolean verify(String hostname,SSLSession session) {
System.out.println("hostname: " + hostname);
return true;

public void genBatchRun(String args[]) {


The protocol is ..........https
The host is ..........xxxx
The port is ..........xxxx
The urlSuffix is ........../servlet/WebRequestController
The dataURL is ..........https://xxxx:xxxx/servlet/WebRequestController
inside processRequest urlCurrentPage = https://xxxx:xxxx
Connecion in connectServlet is
Inside sendRequest
Key is server Value is Sun-ONE-Web-Server/6.1
Key is date Value is Fri, 21 Aug 2009 07:17:37 GMT
Key is content-type Value is application/x-java-serialized-object
Key is transfer-encoding Value is chunked
The value of cookie in the process request is ............... null
Inside receiveRequest
at com.orbitreasury.fixedincome.presentation.util.AppServCommunication.receiveRequest(
at com.orbitreasury.fixedincome.presentation.util.AppServCommunication.processRequest(
at com.orbitreasury.fixedincome.control.ServerResets.main([/color]

Please suggest me a solution.
Thanks in advance.
I agree. Here's the link:
subject: Problem in reading the InputStream and setting the cookie value after applying the SSL(Using https).
It's not a secret anymore!