I'm going crazy trying to run Jetty Jersey and Jackson outside of Eclipse.
I have a main class:
public class Main { public static void main(String[] args) throws Exception { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*").setInitParameter( "jersey.config.server.provider.classnames", CanaryEndpoint.class.getCanonicalName()); Server jettyServer = new org.eclipse.jetty.server.Server(8089); jettyServer.setHandler(context); jettyServer.start(); jettyServer.join(); } }
Endpoint Class:
@Path("/endpoint") public class CanaryEndpoint { @POST @Path("/test") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public String canaryTest(ValueWrapper param) { System.out.println("Deserialized Property: " + param.isFlag()); return "{OK}"; } }
and class Entity (to unserialize):
@XmlRootElement @XmlAccessorType(XmlAccessType.NONE) public class ValueWrapper { @XmlElement public boolean flag; public ValueWrapper() {} public boolean isFlag() { return flag; } public void setFlag(boolean flag) { this.flag = flag;} }
Now this is the funny part. I use Postman to test JSON consumption by sending a POST petition to port 8089 and the original JSON {"flag" : "true"} with an adequate set of both Content-type and Accept.
When I play the Main class through the eclipse server correctly, but when I do it in the CLI (mvn clean package + java -cpJar main_class), the server responds with Error 415: Unsuported Media Type
My simple pom.xml:
<jersey.version>2.14</jersey.version> <jetty-version>9.2.6.v20141205</jetty-version> (...) <artifactId>jetty-server</artifactId> <artifactId>jetty-servlet</artifactId> <artifactId>jersey-container-servlet-core</artifactId> <artifactId>jersey-json</artifactId> <artifactId>jersey-media-json-jackson</artifactId>
Any suggestion on what's going on?
EDIT: I narrowed the issue a bit. It looks like com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider does not register when the application runs from the console . How can I manually register it?
source share