Resource first:
package com.tutego.traida.server;
import javax.ws.rs.*;
@Path( "/" )
public class GreetingResource
{
@GET @ProduceMime("text/plain")
public String get()
{
return "Yea!";
}
}
Bring it to Jetty
package com.tutego.traida.server;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
import com.sun.jersey.spi.container.servlet.ServletContainer;
public class Application
{
public static void main( String[] args ) throws Exception
{
ServletHolder sh = new ServletHolder( ServletContainer.class );
sh.setInitParameter( "com.sun.jersey.config.property.resourceConfigClass",
"com.sun.jersey.api.core.PackagesResourceConfig" );
sh.setInitParameter( "com.sun.jersey.config.property.packages", "com.tutego.traida.server" );
Server server = new Server( 9999 );
Context context = new Context( server, "/", Context.SESSIONS );
context.addServlet( sh, "/*" );
server.start();
}
}
To use REST-parameters
@Path( "/edit-customer/{customerid}" )
public class EditCustomerResource
{
@GET @ProduceMime("text/plain")
public String editUser( @PathParam("customerid") String customerId )
{
....
}
}