Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need a HTTP Client which support a Context over SSL to a JSP Site which Sessions :)

0 views
Skip to first unread message

roman.doubrava

unread,
Jul 18, 2002, 1:51:03 PM7/18/02
to
Dear Java People,

i want to build a Web Java Client which should connect over SSL
multiple times to a Webserver and post to some JSP Sites like an
Browser.
I use the JDK 1.4 with SSL Support and the HTTP Client from
http://www.innovation.ch/java/HTTPClient/

I wrote this peace of Code and everything seems to go right but when
this Client try to connect to the second JSP Site then a
java.lang.Error somewhere in the deeps of Java occurs(see on end of
this posting). I debuged the Source and marked the Position of the
line on that the error Comes.

On normal Sites(without SSL) this Variant works well without any
Errors, and the Session and Cokkies are passed to the next
connection.

Source:

import java.lang.*;
import HTTPClient.*;
import HTTPClient.HTTPResponse.*;
import java.io.*;
import javax.net.ssl.*;


public class sfclient {

static HTTPConnection con=null;
static HTTPResponse browseresult=null;
static InputStream stream=null;
static BufferedReader in=null;
static InputStreamReader inread=null;

static String log="xxxxxxxxxx";
static String pas="xxxxxxxxxx";
static sfclient myApp;

static String search;
static String inputLine;
static String lineFound;
static int result;
static int pos;
boolean breakit = false;

public sfclient(){ }

public void CheckSearch(String inputLine)
{
if (inputLine.indexOf(search) != -1) {
System.out.println("Found: "+inputLine);
pos = inputLine.indexOf(search);
lineFound = inputLine;
result = 1;
breakit = true;
}
}

public void PlayWithResponse(int control)
{

try{
if (false)
{ System.err.println("Received Error:
"+browseresult.getReasonLine());}
else {

System.out.println("Status Code:
"+browseresult.getStatusCode());
System.out.println("Version:
"+browseresult.getVersion());
System.out.println("GetUri:
"+browseresult.getOriginalURI().toString());
System.out.println(browseresult.toString());
//System.out.println("Header:
"+browseresult.getHeader());

if (control == 1){
System.out.println("second stream");
System.out.println("r1");
stream = browseresult.getInputStream();
System.out.println("r2");
inread = new InputStreamReader(stream);
System.out.println("r3");
in = new BufferedReader(inread);

} else {
stream = browseresult.getInputStream();
inread = new InputStreamReader(stream);
in = new BufferedReader(inread); // !!!!! here comes
the error !!!!
}
inputLine="empty";
if ((inputLine = in.readLine())!= null && !breakit){
while (inputLine!=null && !breakit){
if (control < 2)
System.out.println(inputLine);
else if (control == 2) CheckSearch(inputLine);
inputLine = in.readLine();
}
}
//in.close();
//stream.close();
}
}
catch (IOException ioe){ System.err.println(ioe.toString()); }
catch (ModuleException me){ System.err.println("Error handling
request: " + me.getMessage()); }
}

////////////////////// Threads Start
/////////////////////////////
static class T_Login implements Runnable
{
HTTPResponse t_rsp;
HTTPConnection t_con;

String t_email;
String t_password;

public HTTPResponse T_SendLogin()
{
try {
t_con.setDefaultAllowUserInteraction(true);
NVPair form_data[] = new NVPair[2];
form_data[0] = new NVPair("Username",
t_email);
form_data[1] = new NVPair("Password",
t_password);
CookieModule.setCookiePolicyHandler(null);
t_con.setContext("client1");
HTTPResponse resp = t_con.Post("/DCL/login",
form_data);
t_con.setDefaultAllowUserInteraction(true);
return resp;
}
catch (IOException ioe){
System.err.println(ioe.toString());return null;}
catch (ModuleException me){
System.err.println("Error handling request: " +
me.getMessage());return null;
}
}

public T_Login(String user, String password) {
t_email = user;
t_password = password;
}

public void run()
{
System.out.println("Login Thread Starts.");
try {
t_con = new HTTPConnection("https",
"www.everything.com", -1);


}
catch (HTTPClient.ProtocolNotSuppException pns){
System.err.println("Error handling request: " +
pns.getMessage());
}

browseresult = T_SendLogin();
con = t_con;
}
}
/////////////////////////////////////////////////////////////////////////////
static class T_Browse implements Runnable
{
int gal;
int sec;

public T_Browse(int t_gal, int t_sec)
{
gal = t_gal;
sec = t_sec;
}

public HTTPResponse T_sendBrowse()
{
try {
NVPair form_data[] = new NVPair[1];
form_data[0] = new NVPair("xxxxxxx", "xxxxxxx");
// I also tried to put here the isolated Session, same Error :/
HTTPResponse resp = con.Post("/ABC/TDvalidate",
form_data);
System.out.println(resp.listHeaders().toString());
return resp;
}
catch (IOException ioe)
{
System.err.println(ioe.toString());
return null;
}
catch (ModuleException me)
{
System.err.println("Error handling request: " +
me.getMessage());
return null;
}
}

public void run()
{
System.out.println("Browse Thread running.");
browseresult = T_sendBrowse();
System.out.println("Browse Thread ends..\n");
}
}
/////////////////////////// Threads Ende
/////////////////////////////

public static void main(String[] args) {

myApp = new sfclient();
System.setProperty("java.protocol.handler.pkgs","HTTPClient");
System.getProperties().put("http.proxyHost","192.168.115.101");
System.getProperties().put("http.proxyPort","8080");


// Login Procedure Start
// Login Thread Start
Thread my_T_Login = new Thread( new T_Login(log,pas) );
my_T_Login.start();
try{ my_T_Login.join(); } catch (InterruptedException ie) {}
// Login Thread End
search = "TDvalidate;jsessionid=";
myApp.PlayWithResponse(0);
System.out.println("Login Thread Ends..\n");
result = 0;
// Login Procedure End


// Browse Procedure Start
int cnt_gal;
int cnt_sec;
Thread my_T_Browse;
// Browse Thread Start
my_T_Browse = new Thread( new T_Browse(1,1) );
my_T_Browse.start();
try{ my_T_Browse.join(); } catch (InterruptedException
ie) {}
//search = "You Last Visited";
System.out.println("0");
myApp.PlayWithResponse(1);
// Browse Thread End
// Browse Procedure End

System.out.println("Connect close");
myApp.con.stop();

}


}

I get following Error after trying to connect to the second JSP Site
with the given session of the first JSP Site any Ideas ?

--------------------------------------------------------------------------------
java.lang.Error
at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:417)
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:442)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:179)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at sfclient.PlayWithResponse(sfclient.java:105)
at sfclient.main(sfclient.java:244)
Exception in thread "main"
--------------------------------------------------------------------------------

0 new messages