I'm trying to start Jersey on a preconfigured port/url with a preconfigured resource instance. I can't quite figure out how to correctly do it.
Here is a snippet of a code. Help me, please, fill in the blanks:
@Component
@PerRequest
@Path("/svc")
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class MyService
{
// This piece is known
}
public class JSONMessageBodyWriter implements MessageBodyWriter<Object>
{
// This piece is known
}
public class XMLMessageBodyWriter implements MessageBodyWriter<Object>
{
// This piece is known
}
// This is where I need help
MyService service = new MyService();
...
HttpHandler handler = ???
...
HttpServer server = ???
server.createContext("/services", handler);
...
server.start();
In the snippet above, I'm trying to expose the MyService via the http://localhost:8080/services/svc url. If the JSONMessageBodyWriter and the XMLMessageBodyWriter will be plugged in - the service will work vis XML and JSON accordingly.
If you know how to do this on Jetty or Grizzly, let me know too. Can Spring help here?