Skip to main content

Exception while trying to use jersey and jaxb



The following code:







@POST

@Path("/previous-status/{current}")

@Consumes(MediaType.APPLICATION_XML)

@Produces(MediaType.TEXT_PLAIN)

public String getPreviousStepStatus(@PathParam("current") JAXBElement<WorkflowStep> step) {

WorkflowStep wfStep = step.getValue();

return DBAccessor.getPrevStepStatus(wfStep);

}







Produces the following exception:







javax.servlet.ServletException: Servlet.init() for servlet Jersey Rest Service threw exception

org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)

org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)

org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)

org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)

org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)

org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)

org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)

java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

java.lang.Thread.run(Thread.java:662)



root cause



com.sun.jersey.spi.inject.Errors$ErrorMessagesException

com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)

com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)

com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)

com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)

com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)

com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)

com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)

com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)

com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)

com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)

com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)

javax.servlet.GenericServlet.init(GenericServlet.java:160)

org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)

org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)

org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)

org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)

org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)

org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)

org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)

java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

java.lang.Thread.run(Thread.java:662)







If it is commented I don't get the exception. The currently used libraries in the web application are:







asm-3.1.jar

jersey-core-1.11.jar

jersey-server-1.11.jar

jsr311-api-1.1.1.jar

jersey-servlet-1.11.jar

activation.jar (part of jaxb distribution)

jaxb-api.jar

jaxb-impl.jar

stax-api-1.0.1.jar

woodstox-core-asl-4.1.2.jar







The reason I have included the last 5 libraries in the list is this article from developer works





Furthermore from the tomcat start up log I see the following:







SEVERE: The following errors and warnings have been detected with resource and/or provider classes:

SEVERE: Missing dependency for method public java.lang.String restful.SilverLine.getPreviousStepStatus(javax.xml.bind.JAXBElement) at parameter at index 0

SEVERE: Method, public java.lang.String restful.SilverLine.getPreviousStepStatus(javax.xml.bind.JAXBElement), annotated with POST of resource, class restful.SilverLine, is not recognized as valid resource method.







Any ideas will be appreciated?


Comments

  1. PathParameter and entity is something different, try following:

    @POST
    @Path("/previous-status/{order}")
    @Consumes(MediaType.APPLICATION_XML)
    @Produces(MediaType.TEXT_PLAIN)
    public String getPreviousStepStatus(@PathParam("order") int order, JAXBElement<WorkflowStep> step) {

    ...

    WorkflowStep wfStep = step.getValue();
    return DBAccessor.getPrevStepStatus(wfStep);
    }


    in this case, you can do requests like POST http://host/previous-status/10 and put whatever you want into entity.

    You had xml in path param (which is part of URL), which is not possible to use. Your request would look like POST http://host/previous-status/bar, which is .. not good idea and not supported.

    You should take a look at Jersey user guide: http://jersey.java.net/nonav/documentation/latest/ , topics like path param injection, accessing entity and working with XML are well covered there.

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex