-1

I'm using cxf server for rest webservice providing a jackson provider with SimpleDateFormat as date format as described here

How do I configure the date format the server returns using CXF JAX-RS and Jackson 2 in XML?

It works providing a date time.format as defined for it rather it produce a server error.

The goal is to convert received date and convert it or return a description error to the client

Following xml configurations

<bean id="dataFormat" class="java.text.SimpleDateFormat">
    <constructor-arg type="java.lang.String" value=" yyyy-MM-dd'T'HH:mm:ssXXX" />
</bean>


<bean id="jaxbAnnIntrospector" class="org.codehaus.jackson.xc.JaxbAnnotationIntrospector" />

<bean id="objectMapper" class="org.codehaus.jackson.map.ObjectMapper">
    <property name="serializationConfig.annotationIntrospector"
            ref="jaxbAnnIntrospector" />
    <property name="deserializationConfig.annotationIntrospector"
            ref="jaxbAnnIntrospector" />
    <property name="dateFormat" ref="dataFormat" />
</bean>

<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider">
    <property name="mapper" ref="objectMapper" />
</bean>

<jaxrs:providers>
            ...
    <ref bean="jsonProvider" />
            ...
</jaxrs:providers>

Server Error:

java.lang.NoSuchMethodError: javax.ws.rs.ServerErrorException.validate(Ljavax/ws/rs/core/Response;Ljavax/ws/rs/core/Response$Status$Family;)Ljavax/ws/rs/core/Response;
    at javax.ws.rs.ServerErrorException.<init>(ServerErrorException.java:101)
    at javax.ws.rs.InternalServerErrorException.<init>(InternalServerErrorException.java:80)
    at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:242)
    at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:98)
    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:218)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:163)
    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.doPost(AbstractHTTPServlet.java:163)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:219)

Thanks in advance

Community
  • 1
  • 1
antonio
  • 29
  • 2
  • 8

1 Answers1

0

This error most likely points to some Java versions / jar / classpath contents issue. So, issue is not in Date formatting itself, but in your project set up.

It's diffcult to directly say what causes it, but I suggest using a general troubleshooting guide for this kind of issue: How do I fix a NoSuchMethodError?

Community
  • 1
  • 1
Ivan Pronin
  • 1,768
  • 16
  • 14
  • Sorry but it's a no such method due to an invalid a Dto for that Date field..so it fails before perform rest method as cxf exeptions... passing a correct format it works... – antonio Apr 03 '17 at 20:03
  • No, this error tells that JVM cannot find a method to handle appropriate task. For incorrect dateTime format Exception class would be different, e.g. `ParseException` – Ivan Pronin Apr 03 '17 at 20:37