Re: Accessing http session objects from a java class
From: Ankur Bulsara (hotmail_at_N0_SPAM_gmail.com)
Date: 09/30/04
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 29 Sep 2004 16:36:03 -0700
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 clients to connect to.
-You could pass your session state as hidden form fields back to the client.
-You could use a JMX-adapter
-Ankur
"Roger" <rsatdb@gmx.net> wrote in message
news:4c11ed73.0409160746.d32eba@posting.google.com...
> 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
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|