简体   繁体   中英

Jersey POST endpoints failing on Websphere 7

I am deploying a Jersey 2.6 application to Websphere 7 using Jackson as the JSON provider. For some reason, only my endpoints defined as POST are failing. All of my GETs are working fine and returning the correct JSON.

Here is an example endpoint:

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public void sendEmail (final Email email) {

    logger.info("Sending email {}", email);
    boolean sent = emailService.send(email);

    if (!sent) {
        throw new WebApplicationException(400);
    }
}

And here is what Email looks like:

@XmlRootElement
public class Email {

    private List<String> recipients;

    private String from;
    private String subject;

    private String body;

    public Email() {

    }

    public Email(List<String> recipients, String from, String subject,
            String body) {

        this.recipients = recipients;
        this.from = from;
        this.subject = subject;
        this.body = body;
    }

    // getters / setters....
}

Every POST I send never makes the endpoint and I see this in my Websphere SystemOut.log file. I searched feverishly for other log statements in other log files for a hint at what the problem is, but this is all I can find and its very unhelpful. Any assistance would be appreciated. Even if someone can point me to some Websphere-only log file hidden in the bowels of the installation or something:

00000030 webapp        E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[Jersey Web Application]: com.ibm.ws.webcontainer.webapp.WebAppErrorReport: Internal Server Error
        at com.ibm.ws.webcontainer.webapp.WebAppDispatcherContext.sendError(WebAppDispatcherContext.java:637)
        at com.ibm.ws.webcontainer.srt.SRTServletResponse.sendError(SRTServletResponse.java:1189)
        at org.glassfish.jersey.servlet.internal.ResponseWriter.commit(ResponseWriter.java:194)
        at org.glassfish.jersey.server.ContainerResponse.close(ContainerResponse.java:412)
        at org.glassfish.jersey.server.ServerRuntime$Responder.release(ServerRuntime.java:667)
        at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:438)
        at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:265)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:319)
        at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)
        at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1028)
        at 
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:219)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1661)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:944)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:507)
        at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:181)
        at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3954)
        at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
        at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:945)
        at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
        at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:191)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:453)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:306)
        at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:84)
        at com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1819)
        at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
        at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
        at com.ibm.io.async.AsyncChannelFuture$1.run(AsyncChannelFuture.java:205)
        at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1660)org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:373)
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)

So, thanks to the idea by peeskillet , I created an ExceptionMapper in Jersey that implemented an ExceptionMapper of Throwable in hopes it would spew out my error:

@Provider
public class MyExceptionMapper implements
        ExceptionMapper<Throwable> {

    @Override
    public Response toResponse(Throwable ex) {

        System.out.println(ex);
        return Response.status(500).build();
    }
}

Turns out it did exactly that. My error was that I didn't have a no-arg constructor in any of the classes I was posting:

Caused by: com.owlike.genson.JsonBindingException: No constructor has been found for type class com.model.User
        at com.owlike.genson.reflect.BeanDescriptor.deserialize(BeanDescriptor.java:96)
        at com.owlike.genson.convert.BeanViewConverter.deserialize(BeanViewConverter.java:105)
        at com.owlike.genson.convert.NullConverter$NullConverterWrapper.deserialize(NullConverter.java:57)
        at com.owlike.genson.convert.CircularClassReferenceConverterFactory$CircularConverter.deserialize(CircularClassReferenceConverterFactory.java:31)
        at com.owlike.genson.reflect.PropertyMutator.deserialize(PropertyMutator.java:30)

I didn't think this mattered because this worked for me locally. I only saw this error when we deployed to a Websphere 7 cluster. Regardless, this is what fixed my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM