Zero content type when migrating from Jersey to RESTEasy.

So, I wrote a sample REST resource that works like a charm in Jersey / Tomcat, but when I take it in RestEASY / Tomcat, it blows. I mean really? what happened to the work out of the box. Anyway, a little upset. I get this error when trying to access a resource ( http: // localhost: 7070 / mg / mytest )

"content-type was null and expected to extract the body

7842 [http-7070-2] ERROR com.loyalty.mg.rest.exception.MGExceptionMapper - an error that fell into the exception display unit - org.jboss.resteasy.spi.BadRequestException: the content type was null and expected to retrieve the body on org. jboss.resteasy.core.MessageBodyParameterInjector.inject (MessageBodyParameterInjector.java:131) at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments (MethodInjectorImpl.java:98) on org.jboss.resteasy.core.MethodvjectorImplpl.jectorplpl java: 121) on org.jboss.resteasy.core.ResourceMethod.invokeOnTarget (ResourceMethod.java:247) on org.jboss.resteasy.core.ResourceMethod.invoke (ResourceMethod.java:212) on org.jboss.resteasy.core .ResourceMethod.invoke (ResourceMethod.java:202)

@Path("/mytest")
public class TestResource  {

    @GET
    public Response getData()

, - , , , . ?

:)

<context-param>
  <param-name>resteasy.media.type.mappings</param-name>
  <param-value>json : application/json, xml : application/xml</param-value> 
</context-param>
+3
5

, , :

     final MediaType mediaType = request.getHttpHeaders().getMediaType();
     if (mediaType == null) {
        throw new BadRequestException(
             "content-type was null and expecting to extract a body");
     }

, RestEASY . , , , RestEASY.

, - , , , . ?

. , , RestEASY , .

+4

, :

@GET
@Path("/foo/{bar}")
@Produces(MediaType.TEXT_HTML)
public Response foo(@PathParam("bar") String bar) {

... bar @PathParam. RestEasy , , URL-, .

, , , .

+3

RestEASY : http://www.infoq.com/news/2008/10/jaxrs-comparison

, , , @ , :

@Produces("application/json")
@GET
public Response getData() {
  ...
}
+1

, , , . . , RestEasy - RESTLET.

, , JBoss RestEasy , *.jars, , JAX-RS, .

, GET Content_Type ( ), GET , ? ! ( JSON, XML, , XML , ..). RestEasy, JBoss , , URL REST.

 @GET 
 @Path("/echo/{message}")  
 @Produces("text/plain")  
 public String echo(@PathParam("message")String message){  
     return message;      
 }  

 @GET 
 @Path("/employees")  
 @Produces("application/xml")  
 @Stylesheet(type="text/css", href="${basepath}foo.xsl")
 public List<Employee> listEmployees(){  
    return new ArrayList<Employee>(employees.values());  
 }  

 @GET 
 @Path("/employee/{employeeid}")  
 @Produces("application/xml")  
 public Employee getEmployee(@PathParam("employeeid")String employeeId){  
     return employees.get(employeeId);          
 }  

 @GET 
 @Path("/json/employees/")  
 **@Produces("application/json")**  
 public List<Employee> listEmployeesJSON(){  
     return new ArrayList<Employee>(employees.values());  
}   
+1

GET , Content-Type.

RestEASY, , .

EDIT

RFC2616 $4.3

, ( 5.1.1) - .

; , .

GET " ", GET . GET " ", .

In any case, RestEASY should not require a Content-Type in the GET request.

-1
source

Source: https://habr.com/ru/post/1751131/


All Articles