Accessing the http session objects

R

Roger

Hi all.

I've got servlets running in a chain. This works fine if users access
the servlets and JSPs. Now I'm trying to write a java class that can
emulate the browser, so that the applications runs without user
interaction.
I got the connection to work with authentification and I can access
the InputStream I get back, but I couldn't figure out how to access my
objects that I pinned to the session in my servlet chain.
(Startpage.jsp-->servlet-->output.jsp) The output.jsp accesses the
objects that were pinned to the session by the servlet.
I would now like to connect(better POST) to the servlet like the
Startpage.jsp does but from a java class. That would make my
application run without a browser having to connect...

------------java class code-----------------
String authString = "admin" + ":" + "admin";
String auth = "Basic " + new
sun.misc.BASE64Encoder().encode(authString.getBytes());
URL url = new URL("http://localhost:8080/Dummy");
URLConnection conn = url.openConnection();
conn.setRequestProperty("Authorization", auth);
System.out.println(conn.getInputStream().toString());
BufferedReader in = new
BufferedReader(new
InputStreamReader(conn.getInputStream()));
String line;
while((line = in.readLine()) != null) {
// process line
System.out.println(line);
}
------------/code--------------
This works find, but as mentionned I cant figure out how to access my
session objects, something that is aquivalent to
request.getAttribute(key) or request.getParameter within the servlet.
Can anyone help me or has got a hint?

Greets

Roger
 
A

Andrew Thompson

That would make my
application run without a browser having to connect...

What is the point of that?

a) If the servlets are not local, you still
need an internet connection.
b) If the servlets *are* local, convert them
to an application and be done with it.

(Just some thoughts, I may have missed
some important point in what you wrote.)

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
 
S

Shanmuhanathan T

Hi all.

I've got servlets running in a chain. This works fine if users access
the servlets and JSPs. Now I'm trying to write a java class that can
emulate the browser, so that the applications runs without user
interaction.
I got the connection to work with authentification and I can access
the InputStream I get back, but I couldn't figure out how to access my
objects that I pinned to the session in my servlet chain.
(Startpage.jsp-->servlet-->output.jsp) The output.jsp accesses the
objects that were pinned to the session by the servlet.
I would now like to connect(better POST) to the servlet like the
Startpage.jsp does but from a java class. That would make my
application run without a browser having to connect...

------------java class code-----------------
String authString = "admin" + ":" + "admin";
String auth = "Basic " + new
sun.misc.BASE64Encoder().encode(authString.getBytes());
URL url = new URL("http://localhost:8080/Dummy");
URLConnection conn = url.openConnection();
conn.setRequestProperty("Authorization", auth);
System.out.println(conn.getInputStream().toString());
BufferedReader in = new
BufferedReader(new
InputStreamReader(conn.getInputStream()));
String line;
while((line = in.readLine()) != null) {
// process line
System.out.println(line);
}
------------/code--------------
This works find, but as mentionned I cant figure out how to access my
session objects, something that is aquivalent to
request.getAttribute(key) or request.getParameter within the servlet.
Can anyone help me or has got a hint?

Greets

Roger
You could try using the httpclient from Apache commons instead.
http://jakarta.apache.org/commons/httpclient/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,103
Latest member
VinaykumarnNevatia
Top