Sagewire Logo

Accessing http session objects from a JAVA class

3 Message(s) by 3 Author(s) originally posted in java developer


From: rsatdb Date:   Thursday, September 16, 2004
Hi all.

I have got servlet s run ning 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 connect ion to work with authentification and I can access
the InputStream I get back, but I could not figure out how to access my
object s 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'd now like to connect(better POST) to the servlet like the
Startpage.jsp does but from a JAVA class. That'd 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


From: Ankur Bulsara Date:   Wednesday, September 29, 2004
You may want to check out HTTP Unit, which does browser emulation for the
purposes of unit testing web apps.

You can check out an example HTTP Unit test here:
http://www.koders.com/28380/fid0D6139D0338C5DCECE1E5865150168B345DDE7F9.aspx

There are a couple of approaches you can take for hooking into your servlet.
-You could write a monitor servlet that has access to the other servlets but
provides an RMI gateway for JAVA client s to connect to.
-You could pass your session state as hidden form fields back to the client.
-You could use a JMX-adapter

-Ankur

Hi all.
I have 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 could not 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'd now like to connect(better POST) to the servlet like the
Startpage.jsp does but from a JAVA class. That'd 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


From: Jj Date:   Sunday, November 07, 2004
wrote in message serves as a client while
the sesison object only exists on the server side. You simply can not access
object across client and server sides.

Hi all.
I have 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 could not 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'd now like to connect(better POST) to the servlet like the
Startpage.jsp does but from a JAVA class. That'd 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



Next Message: How to avoid using [code][/code] standard action without using MVC framework? What good MVC framework outthere?


Blogs related to Accessing http session objects from a JAVA class

1. What are the four corner stones of OOP ? Abstraction ...
However, Java does manipulate objects by reference, and all object variables themselves are references. ... 108 What is meant by Session ? Tell me something about HTTPSession Class ? ... 426 What are the types of access modifiers ? ...

Intevrview Questions
How can we access elements of a collection? ... How does JAVA handle the same? What are access modifiers? ... Can you explain in detail javax.servlet.http package? ... Can client directly create object of session or entity beans? ...

Java Interview Questions Part 5
JDBC is a set of Java API for executing SQL statements. ... that browser. e) HttpSession- places a limit on the number of sessions that can exist in ... The ConnectionPool class maintains a Hastable, using Connection objects as keys and ...

Develop web application with netbeans ,seam and Glassfish
Accessing each component in entire seam context with one unique name. ... SESSION) @Table(name="users") public class Users implements Serializable{ private static ... taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib ...

AmeerAhmed
In Java speak, this object is called a Plain Old Java Object (aka a ... A [JUnit|http://www.junit.org] class to test the DAO is working ... Managers|CreateManager] - A HowTo for creating Business Facades, which are similar to [Session ...

Home (updated)
Groovy works cleanly with all existing Java objects and libraries and compiles ... the eclipse graphical library; GroovySOAP : accessing through groovy web ... Database Column Types When Creating Tables from a Groovy Domain Class ... ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional