I am currently facing a problem with Jersey and Jackson where I can't find a solution for: When I am trying to get an POJO serialized from JSON as a POST-Parameter in an Jersey-Endpoint, it returns an error if I call it from an uberjar. If I use the same wget-call after I started the main-method from eclipse, everything works fine and I get the expected answers. I've searched for other people having problems when using jersey and post-parameter application types, like Error 415 Unsupported Media Type: POST not reaching REST if JSON, but it does if XML and JAX-RS: How to automatically serialize a collection when returning a Response object?, but the main errors where that they didn't specify headers in the call or use wrong @Consumes-tags, which I do not. According to my research no one had similiar problems that the call worked when the server was started from eclipse, but did not work when the server was started externally.
The class starting the server is the following:
public class ServerStarter {
public static final String BASE_URI = "http://localhost:8282/test/";
public static void main(String[] args) throws IOException {
final ResourceConfig rc = new ResourceConfig().packages("starter");
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
System.out.println(String.format("Drücke Enter um Server zu beenden.", BASE_URI));
System.in.read();
server.stop();
}
}
And the Endpoint looks like this:
@Path("testme")
public class Endpoint {
@POST
@Consumes(MediaType.APPLICATION_JSON)
public String testMe(Parameters ep) {
return ep.toString();
}
}
And the Parameters-class, which should be the POJO, looks like this:
public class Parameters {
private int x;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
}
If I do mvn clean package assembly:single, start the server and then call wget localhost:8282/test/testme --post-data='{"x": 10 }' --header="Content-Type: application/json"
, it returns 415 Unsupported Media Type
.
The dependencies in the pom.xml are the following:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
<version>2.13</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.13</version>
</dependency>
Does anyone know how to solve this problem? I am out of clues, as far as I thought, the call from eclipse should be similar to the call in the uberjar.