Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Programmatically generating HTTP requests from within Jetty process

Not sure how well this will work from WebSockets, but usually to accomplish calling another servlet from the current servlet without a socket connection requirement I would use the RequestDispatcher object.

Using the ServletContext#getRequestDispatcher(String) to obtain a RequestDispatcher object, you could then call the dispatcher.forward(Request,Response) to make a remote call.

From a WebSocket you'd need to create an HttpServletRequest and HttpServletResponse object suitable for making that call tho, which could be the tricky part.

--
Joakim Erdfelt

(the people behind jetty and cometd)



On Tue, Feb 28, 2012 at 3:39 PM, Jeremy Johnson <jeremy.johnson@xxxxxxxxxxxxxxx> wrote:

Ok, I acknowledge this may come across as an odd question.

 

In an embedded Jetty process, is there a way to programmatically generate an HTTP request and receive a response without resorting opening a socket e.g. HTTPUrlConnection?

 

Why on earth would I want to do such a thing?

 

I have a RESTful web service implemented with Jersey and server up by embedded Jetty.  In the same embedded Jetty process I’ll also be serving WebSocket connections, likely speaking my own subprotocol.

 

As part of the subprotocol I’d like for WebSocket clients to have the ability to perform CRUD operations on my web service resources.  I’m considering different ways to skin this cat, one of which being to push an appropriate HTTP request for the web service to Jetty and return the results to the WebSocket client.  Since both the WebSocket and web service are running in the same process, on the surface it seems that there would be performance advantages to accomplishing this though a method call rather than hitting the network.

 

Better ideas are certainly welcome.

 

Thanks!

 


_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users



Back to the top