Jetty6 embedded - forwarding request/response

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Jetty6 embedded - forwarding request/response

Jeremiah Marcum
I have jetty6 running embedded inside of another servlet container/app
server (currently tomcat, but will also be inside websphere, jboss,
and possibly weblogic).

I have a servlet running inside of tomcat (we'll call
ForwardingServlet) that has an instance of the jetty6 Server.
Deployed inside the jetty6 Server I have several web applications.  I
thought that I would be able to take the request/response that my
ForwardingServlet was passed and simply pass it to the jetty6 Server's
handle(target, request, response, dispatch) method.  This doesn't work
because in the ContextHandler's handle method, if the request is not
an instance of org.mortbay.jetty.Request it tries to get the request
from the current connection:
HttpConnection.getCurrentConnection().getRequest(), which is null
because there is not a current connection, so I get a
NullPointerException.  I didn't know if the best way to go about this
is to override the ContextHandler's handle() method somehow or
register a different Connector with the Server.

So my questions: Is there a way to forward a request/response from an
outside servlet container directly to an embedded jetty6 Server?  Does
anyone know how to do this?  Are there different options?  Would I
need to write a custom Connector that instead of listening on a port
just accepts incoming request/responses? If so, does anyone know how
to do that.

Any help/ideas/comments would be greatly appreciated.
N�HY޵隊X���'���u���[�������
ަ�k��!���W�~�鮆�zk��C� 塧m����@^ǚ��^��z�Z�f�z�j�!�x2�������ɫ,��� a{� �,�H��4�m�����Z��jY�w��ǥrg�y$��~7ٸ��}8�Z�׮6%�m�˩��홨��x%��Iz�r��i��e��l���q���z�m��?�X���(��~��zw��X�����b��?��m�˩���
Reply | Threaded
Open this post in threaded view
|

Re: Jetty6 embedded - forwarding request/response

Greg Wilkins-5


Jeremiah,

I think the approach you need to take is to write a special
connector to pass the other containers requests into Jetty.

This is an interesting idea and I'd be happy to help you
develop this and perhaps change aspects of Jetty to make
it easier to do or more efficient.

chers

Jeremiah Marcum wrote:

> I have jetty6 running embedded inside of another servlet container/app
> server (currently tomcat, but will also be inside websphere, jboss,
> and possibly weblogic).
>
> I have a servlet running inside of tomcat (we'll call
> ForwardingServlet) that has an instance of the jetty6 Server.
> Deployed inside the jetty6 Server I have several web applications.  I
> thought that I would be able to take the request/response that my
> ForwardingServlet was passed and simply pass it to the jetty6 Server's
> handle(target, request, response, dispatch) method.  This doesn't work
> because in the ContextHandler's handle method, if the request is not
> an instance of org.mortbay.jetty.Request it tries to get the request
> from the current connection:
> HttpConnection.getCurrentConnection().getRequest(), which is null
> because there is not a current connection, so I get a
> NullPointerException.  I didn't know if the best way to go about this
> is to override the ContextHandler's handle() method somehow or
> register a different Connector with the Server.
>
> So my questions: Is there a way to forward a request/response from an
> outside servlet container directly to an embedded jetty6 Server?  Does
> anyone know how to do this?  Are there different options?  Would I
> need to write a custom Connector that instead of listening on a port
> just accepts incoming request/responses? If so, does anyone know how
> to do that.
>
> Any help/ideas/comments would be greatly appreciated.
> N�HY޵隊X���'���u���[�������
> ަ�k��!���W�~�鮆�zk��C� 塧m����@^ǚ��^��z�Z�f�z�j�!�x2�������ɫ,��� a{� �,�H��4�m�����Z��jY�w��ǥrg�y$���~7ٸ�m�Νj��^�ؗ��+.��+�f��)�+-%�m�˩���+-��.�ǟ����a��l��b��,���y�+��޷�b��?�+-�w��7��+.��+t===



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Re: Jetty6 embedded - forwarding request/response

Jeremiah Marcum
thank you for a quick reply.  after looking into the architecture more
i came to the same conclusion.  I am currently writing a new
Connector, EndPoint, and possibly extending HttpConnection.  The
connector and endpoint will be backed by a HttpServletRequest/Response
instead of a socket/etc.  And the extension to HttpConnection will
override the handle() method so that instead of parsing out the input
stream and generating the headers, it simply uses the backing request.
 I think this will work.  I am planning on finishing that tonight, so
if you have any other suggestions or think that there is a step I am
missing/overdoing please let me know.  Basically what I am thinking
(and this is from memory, not looking at the code) is that the
accept() method of the EmbeddedConnector will create a new
EmbeddedEndPoint that extends StreamEndPoint.  That EmbeddedEndPoint
will have the request/response set in it, and it will create a new
EmbeddedHttpConnection whose handle method will set up the
org.mortbay.jetty.Request/Response backed by the ones set in the
endpoint, and set up the header fields, etc. by using the backing
request/response in the endpoint as well.  The main thing I don't know
is how to handle the continuations, and where I should have it call
the handle() method on the EmbeddedHttpConnection, normally that is
called when the Connector gets a socket connection (i think ??).  Let
me know what you think, I'll get back to you tomorrow once I have this
farther along.

thanks,
jeremiah

On 2/8/06, Greg Wilkins <[hidden email]> wrote:

>
>
> Jeremiah,
>
> I think the approach you need to take is to write a special
> connector to pass the other containers requests into Jetty.
>
> This is an interesting idea and I'd be happy to help you
> develop this and perhaps change aspects of Jetty to make
> it easier to do or more efficient.
>
> chers
>
> Jeremiah Marcum wrote:
> > I have jetty6 running embedded inside of another servlet container/app
> > server (currently tomcat, but will also be inside websphere, jboss,
> > and possibly weblogic).
> >
> > I have a servlet running inside of tomcat (we'll call
> > ForwardingServlet) that has an instance of the jetty6 Server.
> > Deployed inside the jetty6 Server I have several web applications.  I
> > thought that I would be able to take the request/response that my
> > ForwardingServlet was passed and simply pass it to the jetty6 Server's
> > handle(target, request, response, dispatch) method.  This doesn't work
> > because in the ContextHandler's handle method, if the request is not
> > an instance of org.mortbay.jetty.Request it tries to get the request
> > from the current connection:
> > HttpConnection.getCurrentConnection().getRequest(), which is null
> > because there is not a current connection, so I get a
> > NullPointerException.  I didn't know if the best way to go about this
> > is to override the ContextHandler's handle() method somehow or
> > register a different Connector with the Server.
> >
> > So my questions: Is there a way to forward a request/response from an
> > outside servlet container directly to an embedded jetty6 Server?  Does
> > anyone know how to do this?  Are there different options?  Would I
> > need to write a custom Connector that instead of listening on a port
> > just accepts incoming request/responses? If so, does anyone know how
> > to do that.
> >
> > Any help/ideas/comments would be greatly appreciated.
> > N�HY޵隊X���'���u���[�������
> > ަ�k��!���W�~�鮆�zk��C�       塧m����@^ǚ��^��z�Z�f�z�j�!�x2�������ɫ,��� a{� �,�H��4�m�����Z��jY�w��ǥrg�y$���~7ٸ�m�Νj��^�ؗ��+.��+�f��)�+-%�m�˩���+-��.�ǟ����a��l��b��,���y�+��޷�b��?�+-�w��7��+.��+t===
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Jetty-support mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jetty-support
>
N�HY޵隊X���'���u���[�������
ަ�k��!���W�~�鮆�zk��C� 塧m����@^ǚ��^��z�Z�f�z�j�!�x2�������ɫ,��� a{� �,�H��4�m�����Z��jY�w��ǥrg�y$��~7ٸ��}8�Z�׮6%�m�˩��홨��x%��Iz�r��i��e��l���q���z�m��?�X���(��~��zw��X�����b��?��m�˩���
Reply | Threaded
Open this post in threaded view
|

Re: Re: Jetty6 embedded - forwarding request/response

Jeremiah Marcum
ok, here is what I have done so far:

My servlet holds a reference to jetty's Server class.  I have written
2 objects that extend the jetty Request and Response and basically
just wrap the HttpServletRequest/Response instead of being backed by
an HttpConnection/Parser/Generator.  When my servlet recieves a
request/response it   wraps them in my extensions and calls the handle
method on the jetty Server instance.  This seems to work well except
for a few minor issues:

I had to put my extensions to Request and Response in the
org.mortbay.jetty package as the underlying constructor is package
visible only.

I had to put a try catch in the SessionHandler where it tries to cast
the session to a SessionManager.Session object, because I'm just using
the session made by the outside web container.  This is a place where
I am wondering if there is a better way so that I'm not having to hack
the jetty.jar each new release.

org.mortbay.jetty.Request/Response constructors must take a non-null
HttpConnection (it calls httpConnection.getEndpoint() in the
constructor) object whose class has no interface so I had to make an
extension of HttpConnection that basically does nothing.  However
since I had to extend the Request/Response/HttpConnection objects
directly to override them, there are many unused objects created for
each HttpServletResponse/Request that I wrap.

I also have a dummy connector i made (just in case the server requires
a connector) that does nothing because the requests are sent directly
to the server.  This means (I think) that the outside web container
takes care of all the threading.

This seemed to be the most direct and simple approach to me.  However
I have only been looking at jetty for the past week now, so I am sure
there are things I have overlooked.

Doing it this way seems to work for retrieving both static and dynamic
content, I haven't tested too in depth though.

Any thoughts would be appreciated.

Cheers,
Jeremiah

On 2/8/06, Jeremiah Marcum <[hidden email]> wrote:

> thank you for a quick reply.  after looking into the architecture more
> i came to the same conclusion.  I am currently writing a new
> Connector, EndPoint, and possibly extending HttpConnection.  The
> connector and endpoint will be backed by a HttpServletRequest/Response
> instead of a socket/etc.  And the extension to HttpConnection will
> override the handle() method so that instead of parsing out the input
> stream and generating the headers, it simply uses the backing request.
>  I think this will work.  I am planning on finishing that tonight, so
> if you have any other suggestions or think that there is a step I am
> missing/overdoing please let me know.  Basically what I am thinking
> (and this is from memory, not looking at the code) is that the
> accept() method of the EmbeddedConnector will create a new
> EmbeddedEndPoint that extends StreamEndPoint.  That EmbeddedEndPoint
> will have the request/response set in it, and it will create a new
> EmbeddedHttpConnection whose handle method will set up the
> org.mortbay.jetty.Request/Response backed by the ones set in the
> endpoint, and set up the header fields, etc. by using the backing
> request/response in the endpoint as well.  The main thing I don't know
> is how to handle the continuations, and where I should have it call
> the handle() method on the EmbeddedHttpConnection, normally that is
> called when the Connector gets a socket connection (i think ??).  Let
> me know what you think, I'll get back to you tomorrow once I have this
> farther along.
>
> thanks,
> jeremiah
>
> On 2/8/06, Greg Wilkins <[hidden email]> wrote:
> >
> >
> > Jeremiah,
> >
> > I think the approach you need to take is to write a special
> > connector to pass the other containers requests into Jetty.
> >
> > This is an interesting idea and I'd be happy to help you
> > develop this and perhaps change aspects of Jetty to make
> > it easier to do or more efficient.
> >
> > chers
> >
> > Jeremiah Marcum wrote:
> > > I have jetty6 running embedded inside of another servlet container/app
> > > server (currently tomcat, but will also be inside websphere, jboss,
> > > and possibly weblogic).
> > >
> > > I have a servlet running inside of tomcat (we'll call
> > > ForwardingServlet) that has an instance of the jetty6 Server.
> > > Deployed inside the jetty6 Server I have several web applications.  I
> > > thought that I would be able to take the request/response that my
> > > ForwardingServlet was passed and simply pass it to the jetty6 Server's
> > > handle(target, request, response, dispatch) method.  This doesn't work
> > > because in the ContextHandler's handle method, if the request is not
> > > an instance of org.mortbay.jetty.Request it tries to get the request
> > > from the current connection:
> > > HttpConnection.getCurrentConnection().getRequest(), which is null
> > > because there is not a current connection, so I get a
> > > NullPointerException.  I didn't know if the best way to go about this
> > > is to override the ContextHandler's handle() method somehow or
> > > register a different Connector with the Server.
> > >
> > > So my questions: Is there a way to forward a request/response from an
> > > outside servlet container directly to an embedded jetty6 Server?  Does
> > > anyone know how to do this?  Are there different options?  Would I
> > > need to write a custom Connector that instead of listening on a port
> > > just accepts incoming request/responses? If so, does anyone know how
> > > to do that.
> > >
> > > Any help/ideas/comments would be greatly appreciated.
> > > N�HY޵隊X���'���u���[�������
> > > ަ�k��!���W�~�鮆�zk��C�       塧m����@^ǚ��^��z�Z�f�z�j�!�x2�������ɫ,��� a{� �,�H��4�m�����Z��jY�w��ǥrg�y$���~7ٸ�m�Νj��^�ؗ��+.��+�f��)�+-%�m�˩���+-��.�ǟ����a��l��b��,���y�+��޷�b��?�+-�w��7��+.��+t===
> >
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> > for problems?  Stop!  Download the new AJAX search engine that makes
> > searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> > _______________________________________________
> > Jetty-support mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/jetty-support
> >
>
N�HY޵隊X���'���u���[�������
ަ�k��!���W�~�鮆�zk��C� 塧m����@^ǚ��^��z�Z�f�z�j�!�x2�������ɫ,��� a{� �,�H��4�m�����Z��jY�w��ǥrg�y$��~7ٸ��}8�Z�׮6%�m�˩��홨��x%��Iz�r��i��e��l���q���z�m��?�X���(��~��zw��X�����b��?��m�˩���
Reply | Threaded
Open this post in threaded view
|

Re: Jetty6 embedded - forwarding request/response

Greg Wilkins-5
Jeremiah Marcum wrote:
> ok, here is what I have done so far:

Sorry for the slow response on comments.... I've been travelling


> My servlet holds a reference to jetty's Server class.  I have written
> 2 objects that extend the jetty Request and Response and basically
> just wrap the HttpServletRequest/Response instead of being backed by
> an HttpConnection/Parser/Generator.  When my servlet recieves a
> request/response it   wraps them in my extensions and calls the handle
> method on the jetty Server instance.  

EXCELLENT!!

> This seems to work well except
> for a few minor issues:
>
> I had to put my extensions to Request and Response in the
> org.mortbay.jetty package as the underlying constructor is package
> visible only.

Well I can either make these public....

or if you want to donate your work to Jetty, the we might not need
to.  Although a different package would still probably be better.

> I had to put a try catch in the SessionHandler where it tries to cast
> the session to a SessionManager.Session object, because I'm just using
> the session made by the outside web container.  This is a place where
> I am wondering if there is a better way so that I'm not having to hack
> the jetty.jar each new release.

Tell me where the problem is?   I will attempt to make sure that
Jetty will functon against just the HttpSession API.

I'll make any additional API conditional, so that if the
session is the wrong type it will just not be called.   I think
it will probably only be touching the access time that will be an issue.

Alternately, the real session can be wrapped as a Jetty SessionManager.Session?


> org.mortbay.jetty.Request/Response constructors must take a non-null
> HttpConnection (it calls httpConnection.getEndpoint() in the
> constructor) object whose class has no interface so I had to make an
> extension of HttpConnection that basically does nothing.  However
> since I had to extend the Request/Response/HttpConnection objects
> directly to override them, there are many unused objects created for
> each HttpServletResponse/Request that I wrap.

I will look at simplifying this.  It would be simplest if I could
see the code???

Some interfaces and some more acceptance of nulls should help a lot.
 
> I also have a dummy connector i made (just in case the server requires
> a connector) that does nothing because the requests are sent directly
> to the server.  This means (I think) that the outside web container
> takes care of all the threading.

I think you want the dummy connector.  It can be the source of the
continuation objects etc.  

Note to answer your question from the previous email...
the continuations will have to come from the connector and it
can try to get a continuation from the real container and if that
fails (not running inside another jetty), pass back a WaitingContinuation.

To get non-blocking continuations inside another container, then
you might want to have multiple connectors.  eg an additional connector
listening on a different port to service the AJAX requests.


> This seemed to be the most direct and simple approach to me.  However
> I have only been looking at jetty for the past week now, so I am sure
> there are things I have overlooked.

As you have said, there are probably lots of things that could be tidied
up if Jetty was modified a bit.   If you are happy to release the code
then I'm keen to make changes to help simplify the code.

> Doing it this way seems to work for retrieving both static and dynamic
> content, I haven't tested too in depth though.

This is really cool!

> Any thoughts would be appreciated.

cool-o-rama!

> Cheers,
> Jeremiah
>
> On 2/8/06, Jeremiah Marcum <[hidden email]> wrote:
>
>>thank you for a quick reply.  after looking into the architecture more
>>i came to the same conclusion.  I am currently writing a new
>>Connector, EndPoint, and possibly extending HttpConnection.  The
>>connector and endpoint will be backed by a HttpServletRequest/Response
>>instead of a socket/etc.  And the extension to HttpConnection will
>>override the handle() method so that instead of parsing out the input
>>stream and generating the headers, it simply uses the backing request.
>> I think this will work.  I am planning on finishing that tonight, so
>>if you have any other suggestions or think that there is a step I am
>>missing/overdoing please let me know.  Basically what I am thinking
>>(and this is from memory, not looking at the code) is that the
>>accept() method of the EmbeddedConnector will create a new
>>EmbeddedEndPoint that extends StreamEndPoint.  That EmbeddedEndPoint
>>will have the request/response set in it, and it will create a new
>>EmbeddedHttpConnection whose handle method will set up the
>>org.mortbay.jetty.Request/Response backed by the ones set in the
>>endpoint, and set up the header fields, etc. by using the backing
>>request/response in the endpoint as well.  The main thing I don't know
>>is how to handle the continuations, and where I should have it call
>>the handle() method on the EmbeddedHttpConnection, normally that is
>>called when the Connector gets a socket connection (i think ??).  Let
>>me know what you think, I'll get back to you tomorrow once I have this
>>farther along.
>>
>>thanks,
>>jeremiah
>>
>>On 2/8/06, Greg Wilkins <[hidden email]> wrote:
>>
>>>
>>>Jeremiah,
>>>
>>>I think the approach you need to take is to write a special
>>>connector to pass the other containers requests into Jetty.
>>>
>>>This is an interesting idea and I'd be happy to help you
>>>develop this and perhaps change aspects of Jetty to make
>>>it easier to do or more efficient.
>>>
>>>chers
>>>
>>>Jeremiah Marcum wrote:
>>>
>>>>I have jetty6 running embedded inside of another servlet container/app
>>>>server (currently tomcat, but will also be inside websphere, jboss,
>>>>and possibly weblogic).
>>>>
>>>>I have a servlet running inside of tomcat (we'll call
>>>>ForwardingServlet) that has an instance of the jetty6 Server.
>>>>Deployed inside the jetty6 Server I have several web applications.  I
>>>>thought that I would be able to take the request/response that my
>>>>ForwardingServlet was passed and simply pass it to the jetty6 Server's
>>>>handle(target, request, response, dispatch) method.  This doesn't work
>>>>because in the ContextHandler's handle method, if the request is not
>>>>an instance of org.mortbay.jetty.Request it tries to get the request
>>>>from the current connection:
>>>>HttpConnection.getCurrentConnection().getRequest(), which is null
>>>>because there is not a current connection, so I get a
>>>>NullPointerException.  I didn't know if the best way to go about this
>>>>is to override the ContextHandler's handle() method somehow or
>>>>register a different Connector with the Server.
>>>>
>>>>So my questions: Is there a way to forward a request/response from an
>>>>outside servlet container directly to an embedded jetty6 Server?  Does
>>>>anyone know how to do this?  Are there different options?  Would I
>>>>need to write a custom Connector that instead of listening on a port
>>>>just accepts incoming request/responses? If so, does anyone know how
>>>>to do that.
>>>>
>>>>Any help/ideas/comments would be greatly appreciated.
>>>>N�HY޵隊X���'���u���[�������
>>>>ަ�k��!���W�~�鮆�zk��C�       塧m����@^ǚ��^��z�Z�f�z�j�!�x2�������ɫ,��� a{� �,�H��4�m�����Z��jY�w��ǥrg�y$���~7ٸ�m�Νj��^�ؗ��+.��+�f��)�+-%�m�˩���+-��.�ǟ����a��l��b��,���y�+��޷�b��?�+-�w��7��+.��+t===
>>>
>>>
>>>
>>>-------------------------------------------------------
>>>This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
>>>for problems?  Stop!  Download the new AJAX search engine that makes
>>>searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
>>>http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
>>>_______________________________________________
>>>Jetty-support mailing list
>>>[hidden email]
>>>https://lists.sourceforge.net/lists/listinfo/jetty-support
>>>
>>
> N�HY޵隊X���'���u���[�������
> ަ�k��!���W�~�鮆�zk��C� 塧m����@^ǚ��^��z�Z�f�z�j�!�x2�������ɫ,��� a{� �,�H��4�m�����Z��jY�w��ǥrg�y$���~7ٸ�m�Νj��^�ؗ��+.��+�f��)�+-%�m�˩���+-��.�ǟ����a��l��b��,���y�+��޷�b��?�+-�w��7��+.��+t===



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support