Re: Accessing http session objects from a java class

From: Ankur Bulsara (hotmail_at_N0_SPAM_gmail.com)
Date: 09/30/04

  • Next message: Erik Rosenbach: "parsing mime"
    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


  • Next message: Erik Rosenbach: "parsing mime"

    Relevant Pages

    • Re: servlet redirecting
      ... > I have servlet A, which outputs content according to the session ... I also make it output a timestamp). ... > when the browser is redirected to A, the old page is displayed [from ...
      (comp.lang.java.programmer)
    • Re: TOMCAT PROBLEM: Establishing a session
      ... >> Hi I am running Tomcat in standalone mode. ... >> refresh button on my Mozilla browser. ... > What method did you use to determine whether there is a session or not? ... servlet, we have written a second servlet which implements a HashTable ...
      (comp.lang.java.programmer)
    • ServletOutputStream to Browser OK in NS, but not IE??
      ... I am replacing a Netscape Application Server appLogic with a servlet. ... the current browser session), but always pops up the file download box ... the user never sees the download box. ...
      (comp.lang.java.programmer)
    • =?iso-8859-1?q?Re:_Verst=E4ndnis_zu_EJB_JBoss_etc?=
      ... Ein Servlet ist die primitivste Urform um mit einem Browser zu ... Per Java: ... JSP - Seite schreibst Du: ...
      (de.comp.lang.java)
    • Re: Tomcat 5.0.25 my own servlet example doesnt run.
      ... mojgan wrote: ... > I recently installed Tomcat 5.0.25 on Windows XP, ... > I also tried to write my own servlet (very similar to the ... But when I point my browser to the ...
      (comp.lang.java.programmer)