Shvalb
Shvalb

Reputation: 1933

Initializing Jetty+Jersey

I'm trying to initialize Jetty with the following code:

URI baseUri = UriBuilder.fromUri("http://localhost/").port(config.getPort()).build();
ResourceConfig resConfig = new ResourceConfig(GetFutureTimetableCommand.class);
Server server = JettyHttpContainerFactory.createServer(baseUri, resConfig);

WebAppContext context = new WebAppContext();
context.setDescriptor("WebContent/WEB-INF/web.xml");
context.setResourceBase("WebContent");
context.setContextPath("rest/*");
context.setParentLoaderPriority(true);
server.setHandler(context);
server.start();

My Resource looks like this:

@Path("/timetable")
public class GetFutureTimetableCommand extends CMSCommand {

@GET    
@Produces(MediaType.APPLICATION_JSON)
public CMSBean execute(@PathParam("param") String params) {
    System.out.println("GOOD");
    return new FutureTimetable(8202L, DateTime.now().plusDays(2));
}
}

And from the browser:

http://localhost:8080/rest/timetable

But nothing really happens, what am I doing wrong??

Upvotes: 1

Views: 1242

Answers (2)

Olivier
Olivier

Reputation: 1

It seems only the root context path is taken into account when jersey is used together with jetty as per Jersey documentation (others are just ignored): https://jersey.java.net/documentation/latest/deployment.html

You probably need to change the context path with:

context.setContextPath("/");

Upvotes: 0

Will
Will

Reputation: 6711

I have found that enabling MBeans with monitoring statistics invaluable when trying to determine why a resource isn't executing.

Add the below to your Jersey Servlet definition in your web.xml and connect JVisualVM or JConsole to see lots of data on deployed resources.

<init-param>
   <param-name>jersey.config.server.monitoring.statistics.mbeans.enabled</param-name>
   <param-value>true</param-value>
</init-param>

I appreciate this isn't an answer to your problem, but hopefully should help you find it.

Will

Upvotes: 2

Related Questions