user1823924
user1823924

Reputation:

RESTFUL web service - media type=application/xml

I'm currently writing a RESTFUL web service and trying to return integer to the web service.

I encounter 500 Internal Server Error from the browser and when I check the Tomcat Log, the above error occurred.

12-Nov-2018 09:47:12.547 SEVERE [http-nio-8080-exec-52] org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo MessageBodyWriter not found for media type=application/xml, type=class java.lang.Integer, genericType=int.

My code :

@POST
    @Path("/post")

    @Produces(MediaType.APPLICATION_XML)
    public static int adaptiveAuth(){ 
        int message=1;
        return message; 
    }

If I replace the function with String, it wont give any error.

@POST
    @Path("/post")

    @Produces(MediaType.APPLICATION_XML)
    public static String adaptiveAuth(){ 
        String message="POST STRING";
        return message; 
    }

Result : POST STRING

Is there any limitation on RESTFUL regarding MediaType.APPLICATION_XML ?

Thank you

Upvotes: 2

Views: 1009

Answers (1)

Mykhailo Moskura
Mykhailo Moskura

Reputation: 2211

Hello try to use Response object from jax-rs specification

https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/Response.html

It’s better to return response object which gives you flexibility to define status , body etc.

Also you can see existing answer on this topic:

Returning an Integer from RESTful web services method in java

Upvotes: 1

Related Questions