cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: [CXF] problem with @Consumes("application/json")
Date Mon, 03 Jun 2013 18:30:02 GMT
Hi

You need to configure JSONProvider to map a prefix to a namespace (with a
namespace map property), or do not use namespaces at all in the incoming
message and then use JSONProvider to map it to what JAXB expects, using the
transformation feature,

another issue there is that it appears that you have a mix of JAX-RS 1.1 &
2.0 API on the classpath (NoSuchMethodExceptiom when a BadRequestException
is created)

Cheers, Sergey


On Mon, May 27, 2013 at 2:30 PM, ced_benoit <ced.benoit@gmail.com> wrote:

>
> I have a method like this:
>
>     @PUT
>     @Path("/update")
>     @Consumes("application/json")
>     @Produces("application/json")
>     public Integer update(Customer pCust){
> }
>
> When I send a json query like this:
>
> {"ns2.Customer": {
>    "code": "Code1",
>    "firstname": "Ilan",
>    "lastname": "Chur",
> }}
>
> since Saopui, i have this error:
>
> mai 27, 2013 3:26:16 PM org.apache.cxf.jaxrs.provider.AbstractJAXBProvider
> handleExceptionStart
> WARNING: javax.xml.bind.UnmarshalException
>  - with linked exception:
> [com.sun.istack.SAXParseException2; columnNumber: 0; élément inattendu (URI
> : "", local : "ns2.Customer"). Les éléments attendus sont
> <{http://test.site.com/}Customer>,<{http://test.site.com/}delete>,<{
> http://test.site.com/}deleteResponse>,<{http://test.site.com/}findAll>,<{
> http://test.site.com/}findAllResponse>,<{http://test.site.com/}findById
> >,<{http://test.site.com/}findByIdResponse>,<{http://test.site.com/}insert
> >,<{http://test.site.com/}insertResponse>,<{http://test.site.com/}update
> >,<{http://test.site.com/}updateResponse>]
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:435)
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:372)
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:342)
>         at
>
> org.apache.cxf.jaxrs.provider.json.JSONProvider.readFrom(JSONProvider.java:229)
>         at
>
> org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1196)
>         at
>
> org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1144)
>         at
> org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:695)
>         at
>
> org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:655)
>         at
>
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:238)
>         at
>
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:99)
>         at
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
>         at
>
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
>         at
>
> org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)
>         at
>
> org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
>         at
>
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:203)
>         at
>
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:137)
>         at
>
> org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:158)
>         at
>
> org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:243)
>         at
>
> org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPut(AbstractHTTPServlet.java:180)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
>         at
>
> org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:219)
>         at
>
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
>         at
>
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
>         at
>
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
>         at
>
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
>         at
> org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
>         at
>
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
>         at
>
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
>         at
>
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
>         at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
>         at
>
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
>         at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
>         at
>
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
>         at
>
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
>         at
>
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
>         at
>
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>         at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>         at java.lang.Thread.run(Thread.java:722)
> Caused by: com.sun.istack.SAXParseException2; columnNumber: 0; élément
> inattendu (URI : "", local : "ns2.Customer"). Les éléments attendus sont
> <{http://test.site.com/}Customer>,<{http://test.site.com/}delete>,<{
> http://test.site.com/}deleteResponse>,<{http://test.site.com/}findAll>,<{
> http://test.site.com/}findAllResponse>,<{http://test.site.com/}findById
> >,<{http://test.site.com/}findByIdResponse>,<{http://test.site.com/}insert
> >,<{http://test.site.com/}insertResponse>,<{http://test.site.com/}update
> >,<{http://test.site.com/}updateResponse>
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:662)
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:258)
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:253)
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:120)
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1063)
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:498)
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:480)
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:75)
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:246)
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:180)
>         at
>
> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:370)
>         ... 36 more
> Caused by: javax.xml.bind.UnmarshalException: élément inattendu (URI : "",
> local : "ns2.Customer"). Les éléments attendus sont
> <{http://test.site.com/}Customer>,<{http://test.site.com/}delete>,<{
> http://test.site.com/}deleteResponse>,<{http://test.site.com/}findAll>,<{
> http://test.site.com/}findAllResponse>,<{http://test.site.com/}findById
> >,<{http://test.site.com/}findByIdResponse>,<{http://test.site.com/}insert
> >,<{http://test.site.com/}insertResponse>,<{http://test.site.com/}update
> >,<{http://test.site.com/}updateResponse>
>         ... 47 more
>
> mai 27, 2013 3:26:16 PM org.apache.catalina.core.StandardWrapperValve
> invoke
> SEVERE: Servlet.service() for servlet [CXF Servlet Cust] in context with
> path [/Project] threw exception [L''exécution de la servlet a lancé une
> exception] with root cause
> java.lang.NoSuchMethodError:
>
> javax.ws.rs.BadRequestException.validate(Ljavax/ws/rs/core/Response;Ljavax/ws/rs/core/Response$Status;)Ljavax/ws/rs/core/Response;
>         at
> javax.ws.rs.BadRequestException.<init>(BadRequestException.java:92)
>         at
>
> org.apache.cxf.jaxrs.provider.AbstractJAXBProvider.handleExceptionEnd(AbstractJAXBProvider.java:671)
>         at
>
> org.apache.cxf.jaxrs.provider.AbstractJAXBProvider.handleJAXBException(AbstractJAXBProvider.java:683)
>         at
>
> org.apache.cxf.jaxrs.provider.json.JSONProvider.readFrom(JSONProvider.java:243)
>         at
>
> org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1196)
>         at
>
> org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1144)
>         at
> org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:695)
>         at
>
> org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:655)
>         at
>
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:238)
>         at
>
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:99)
>         at
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
>         at
>
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
>         at
>
> org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)
>         at
>
> org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
>         at
>
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:203)
>         at
>
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:137)
>         at
>
> org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:158)
>         at
>
> org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:243)
>         at
>
> org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPut(AbstractHTTPServlet.java:180)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
>         at
>
> org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:219)
>         at
>
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
>         at
>
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
>         at
>
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
>         at
>
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
>         at
> org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
>         at
>
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
>         at
>
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
>         at
>
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
>         at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
>         at
>
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
>         at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
>         at
>
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
>         at
>
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
>         at
>
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
>         at
>
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>         at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>         at java.lang.Thread.run(Thread.java:722)
>
> Is anyone has an idea, how I can solve it. I would like to send JSON
> parameter
>
>
>
>
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/CXF-problem-with-Consumes-application-json-tp5728413.html
> Sent from the cxf-dev mailing list archive at Nabble.com.
>



-- 
Sergey Beryozkin

http://sberyozkin.blogspot.com
Talend - http://www.talend.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message