It's actually the org.apache.catalina.connector.Request that handles getting 
the session.  For the first time the session is requested, tt does this by 
getting the manager from the context, and calls the findSession(String 
sessionid) method on the manager.  If this returns null, then it does much 
like the code below, except that it sets the JSESSIONID cookie as well.

The ability to get the connector Request object depends on timing.  As a 
result, depending on your test plan, it may be easier to create a custom 
Valve (added to, say, the context, but it doesn't really matter) which will 
have easy access to the connector Request.  However, if you will only ever 
need it for the second or higher times that you use the coyoteRequest, then 
you can get it via:
         org.apache.catalina.connector.Request tcreq =
                   
(org.apache.catalina.connector.Request)coyoteRequest.getNote(CoyoteAdapter.ADAPTER_NOTES);

Then you can do something like (assuming that you have passed the cookie 
header/encoded the URL):
     Session session = tcreq.getSession();
     HttpSession hsession = session.getSession();
     // setup a bunch of attributes here

Again, depending on your testing plan, it may just be easier to deal with 
the manager directly.  I haven't seen it, so I can't comment on what is best 
for you :).

"Auke Noppe" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
I have an instance of the manager now. I forgot a reference. But, how can I
make a reference to the session in the coyoteRequest? Or does the context
manage the sessions (by the manager) and is the context the one who makes
the references between sessions and coyoteRequests?

Lots of thanks,

Auke

-----Oorspronkelijk bericht-----
Van: news [mailto:[EMAIL PROTECTED] Namens Bill Barker
Verzonden: woensdag 24 oktober 2007 3:41
Aan: users@tomcat.apache.org
Onderwerp: Re: Start tomcat without Connector

Nope, this won't work.  The Request needs to be mapped before TC knows how
to find the Session.

After the Context is started, it should have a Manager (if you haven't
explicitly configured one).  I'm guessing that you are doing some sort of
Mock unit testing, and you want the Session configured before you run your
test.  In that case, you want something like (after you call start):
    Manager manager = context.getManager();
    Session session = manager.createSession("MySessionId");
    manager.add(session);
    HttpSession hsession = session.getSession();
    hsession.setAttribute(foo, bar);



"Auke Noppe" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi,

I have the app working. But I want to set some attributes on the session
(like a user). Does anyone knows how I can get to the HttpSession? I tried
to create a org.apache.catalina.connector.Request via
connector.createRequest() and invoke the request.getSession() method, but I
always receive null from the request. The manager of the context is empty I
found out. Should it not be instantiated/set during startup?

I there another way to get a reference of a HttpSession?

Regards,

Auke

-----Oorspronkelijk bericht-----
Van: news [mailto:[EMAIL PROTECTED] Namens Bill Barker
Verzonden: dinsdag 23 oktober 2007 3:27
Aan: users@tomcat.apache.org
Onderwerp: Re: Start tomcat without Connector

It is possible, but not easy.  The Connector is integrated pretty tightly
with the Catalina code now.  In particular, you can't just call the invoke
method on the Context, since the mappings are done via the Connector.

It will probably be easier to create a Connector using the
MemoryProtocolHandler (in org.apache.coyote.memory).  You're code can get a
reference to it by calling getProtocolHandler() on the Connector, and then
feed your request through the process method of MemoryProtocolHandler.

"Auke Noppe" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi there,



Is it possible to start an instance of (embedded)tomcat without connector,
and to invoke pages through the context.invoke(request, response) method?

I have written a small application which starts embedded tomcat with a
server, engine, host and context, but without connector.

And the application invokes the invoke method of the context. But I don’t
get a response back.



public void startTomcat() throws LifecycleException {

        embedded = new Embedded();



        engine = embedded.createEngine();

        engine.setName("Catalina");



        host = embedded.createHost("localhost", getPath() + "/webapps");

        engine.addChild(host);



        context = embedded.createContext("",
"C:/stage_auke/workspace/trunk/web");

        context.setPrivileged(false);

        host.addChild(context);

        String config = host.getConfigClass();


((StandardContext)context).setDefaultWebXml(getPath()+"/conf/web.xml");



        context.setAvailable(true);

        embedded.addEngine(engine);

        embedded.start();

    }



The other method calls context.invoke with a filled request and response.







Anyone an idea?



Regards,



Auke




No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.15.5/1084 - Release Date: 21-10-2007
15:09





---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.15.6/1086 - Release Date: 22-10-2007
19:57


No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.15.6/1086 - Release Date: 22-10-2007
19:57



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.15.6/1086 - Release Date: 22-10-2007
19:57


No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.15.8/1089 - Release Date: 23-10-2007
19:39



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to