users@jersey.java.net

Re: Intergrating Jetty and Jersey

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 06 Mar 2008 17:51:24 +0100

Jonathan Cook - Online wrote:
> Great. Thanks. This works!

Great!


> Now on to my next problem which is dependency problems between different
> versions of asm*jar and hibernate.
> But I'm hoping this will solve my problems:
> https://jersey.dev.java.net/servlets/ReadMsg?listName=users&msgNo=533
>

It should, there are also other threads:

https://jersey.dev.java.net/servlets/SearchList?list=users&searchText=cglib&defaultField=body&Search=Search

For example, see Farrukh's solution:

https://jersey.dev.java.net/servlets/ReadMsg?listName=users&msgNo=368

Paul.

> Jon
>
> -----Original Message-----
> From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
> Sent: 06 March 2008 13:33
> To: users_at_jersey.dev.java.net; Jonathan Cook - Online
> Subject: Re: Intergrating Jetty and Jersey
>
> Hi Jonathan,
>
> Try the following:
>
> ServletHolder sh = new ServletHolder(ServletContainer.class);
> sh.setInitParameter(
> "com.sun.ws.rest.config.property.resourceConfigClass",
> "com.sun.ws.rest.api.core.PackagesResourceConfig");
> sh.setInitParameter(
> "com.sun.ws.rest.config.property.packages",
> <package name to search from>);
>
> Server server = new Server(9999);
> Context context = new Context(server, "/", Context.SESSIONS);
> context.addServlet(sh, "/*");
> server.start();
>
> the above worked for me. At the end of the email is a complete stand
> alone example. I used the following jars:
>
> jersey/lib/jersey.jar
> jersey/lib/asm-3.1.jar
> jersey/lib/jsr311-api.jar
> jetty-6.1.3/lib/jetty-6.1.3.jar
> jetty-6.1.3/lib/jetty-util-6.1.3.jar
> jetty-6.1.3/lib/servlet-api-2.5-6.1.3.jar
>
>
> This is fairly cool, it means i now know how to use embedded Jetty for
> unit testing the servlet container :-)
>
> Hope this helps,
> Paul.
>
> package jetty;
>
> import com.sun.ws.rest.api.client.Client;
> import com.sun.ws.rest.api.client.WebResource;
> import com.sun.ws.rest.spi.container.servlet.ServletContainer;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import org.mortbay.jetty.Server;
> import org.mortbay.jetty.servlet.Context;
> import org.mortbay.jetty.servlet.ServletHolder;
>
> public class Main {
>
> @Path("/")
> public static class TestResource {
>
> @GET
> public String get() {
> return "GET";
> }
> }
>
> /**
> * @param args the command line arguments
> */
> public static void main(String[] args) throws Exception {
> ServletHolder sh = new ServletHolder(ServletContainer.class);
>
> sh.setInitParameter("com.sun.ws.rest.config.property.resourceConfigClass
> ",
> "com.sun.ws.rest.api.core.PackagesResourceConfig");
> sh.setInitParameter("com.sun.ws.rest.config.property.packages",
> "jetty");
>
> Server server = new Server(9999);
> Context context = new Context(server, "/", Context.SESSIONS);
> context.addServlet(sh, "/*");
> server.start();
>
> Client c = Client.create();
> WebResource r = c.resource("http://localhost:9999/");
> System.out.println(r.get(String.class));
>
> server.stop();
> }
> }
>
> Jonathan Cook - Online wrote:
>> Does anybody know if it is possible to use Jetty and Jersey together
>> rather than the built in HTTPHandler that comes with Jersey. I believe
>
>> you can use Jersey with Tomcat so assumed you could use it with Jetty
>> which is just another web server.
>>
>> Currently I have the following code:
>> Server server = new Server(8080);
>> Context context = new
>> Context(server,"/",Context.SESSIONS);
>>
>> //config.
>> com.sun.ws.rest.spi.container.servlet.ServletContainer
> container =
>> new
>> com.sun.ws.rest.spi.container.servlet.ServletContainer();
>> container.init();
>>
>> context.addServlet(new ServletHolder(container), "/*");
>
>>
>> server.start();
>>
>> But when the Jetty server starts it complains about no paths found. I
>> don't think it can find the resources successfully. Even if I pass
>> some init params it still doesn't work.
>>
>> Do you know if Jersey will work with Jetty?
>>
>> Thanks
>> Jonathan
>>
>>
>>
>>
>> *_ _*
>> *Jonathan Cook*
>> Software Engineer
>>
>> Feeds Team
>> *BBC Future Media & Technology (Journalism)
>> *BC3 B1, Broadcast Centre
>>
>> *T:* 020 800 84734 (02 84734)
>>
>>
>>
>> http://www.bbc.co.uk
>> This e-mail (and any attachments) is confidential and may contain
>> personal views which are not the views of the BBC unless specifically
>> stated.
>> If you have received it in error, please delete it from your system.
>> Do not use, copy or disclose the information in any way nor act in
>> reliance on it and notify the sender immediately.
>> Please note that the BBC monitors e-mails sent or received.
>> Further communication will signify your consent to this.
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109