0
votes

I was using Jersey 1.9 in which case to allow cross-domain issue I wrapped my objects using JsonWithPadding (com.sun.jersey.api.json.JSONWithPadding). Without JsonWithPadding it returns correct JSON response.

Having perfectly working with JsonWithPadding, it gives me the following error in the event I switched to Jersey 2. I'm using eclipse neon, tomcat 8.

It doesn't even throw any error on console rather I found error 500 on the access log along with 1082 which I believe is security(trojan) issue.

Access Log

172.22.14.88 - - [13/Jun/2017:09:17:49 -0400] "GET /csmgt/rest/client/ HTTP/1.1" 500 1082

RESPONSE:

<!DOCTYPE html>
<html>
    <head>
        <title>Apache Tomcat/8.0.28 - Error report</title>
        <style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style>
    </head>
    <body>
        <h1>HTTP Status 500 - Internal Server Error</h1>
        <div class="line"></div>
        <p>
            <b>type</b> Status report
        </p>
        <p>
            <b>message</b>
            <u>Internal Server Error</u>
        </p>
        <p>
            <b>description</b>
            <u>The server encountered an internal error that prevented it from fulfilling this request.</u>
        </p>
        <hr class="line">
        <h3>Apache Tomcat/8.0.28</h3>
    </body>
</html>

Any help with JsonWithPadding is appreciated.

1

1 Answers

0
votes

Finally, I solved my question after struggle. First of all, it wasn't possible to see the error thrown by Jersey on eclipse console rather than Error 500 response. I created the following Custom ExceptionMapper for Jersey errors get displayed on console.

import javax.ws.rs.core.Response; import javax.ws.rs.ext.Provider;

@Provider
public class MoxyThrowable implements javax.ws.rs.ext.ExceptionMapper<Exception> {
    @Override
    public Response toResponse(Exception exception) {
        exception.printStackTrace();
        return Response.status(500).build();
    }
}

... That exception mapper clearly shows me the cause is JSON With Padding I used to support CORS(Cross-Domain) which was working before I shift to Jersey 2. I realized that Jersey 2.0 defaults to MOXy Provider.

There are two API's for JSON With Padding libraries : com.sun.jersey.api.json.JSONWithPadding - I USED this org.eclipse.persistence.oxm.JSONWithPadding

--- Solution

Set @ web.xml

DISABLE MOXY

 <init-param>
    <param-name>jersey.config.disableMoxyJson.server</param-name>
    <param-value>true</param-value>
</init-param>

USE JACKSON

<init-param>
    <param-name>jersey.config.server.provider.packages</param-name>
    <param-value>YOUR SERVICES;org.codehaus.jackson.jaxrs
    </param-value>
</init-param>

--- Make sure you added jersey-media-json-jackson-2.5.1