cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nagulapalli, Srinivas" <Srinivas.Nagulapa...@ncr.com>
Subject Help- Cannot make Client invocation using ParameterConverter to JAX_RS service using cxf-3.0.2
Date Wed, 10 Sep 2014 21:16:15 GMT
Hi

When invoking simple JAX-RS service marshalling java.util.Date, it works on server side, but
on client side when invoking after making sure ParameterConverter is added to jaxrs:providers
element
Under jaxrs:client, it gives error saying the method cannot be matched.  3.0.2 snapshot has
fix for date marshalling and want to make sure if I am missing something.

Stacktrace, client invoking code and config used + Server side code and its config are below.

Using: cxf-*-3.0.2 snapshot (because it has fix for the needed Date marshalling)
cxf-core-3.0.2-20140828.070840-30.jar, cxf-rt-frontend-jaxrs-3.0.2-20140828.071806-27.jar,
cxf-rt-rs-client.3.0.2-20140828.072409-26.jar, cxf-rt-rs-service-description-3.0.2-20140828.071832-27.jar
cxf-rt-transports-http-3.0.2-20140828.071216-27.jar

Appreciate greatly any help or pointers.

Thanks
Srini
Stacktrace:

WARN http-bio-8080-exec-8 org.apache.cxf.jaxrs.utils.JAXRSUtils - No operation matching request
path "/RestDemo2/services/rest/UserManager/getUserBeforeDate/1959-01-01T00:00:00.000Z" is
found, Relative Path: /getUserBeforeDate/1959-01-01T00:00:00.000Z, HTTP Method: GET, ContentType:
application/json, Accept: application/json,. Please enable FINE/TRACE log level for more details.
WARN http-bio-8080-exec-8 org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper - javax.ws.rs.ClientErrorException:
HTTP 406 Not Acceptable
        at org.apache.cxf.jaxrs.utils.SpecExceptions.toHttpException(SpecExceptions.java:117)
        at org.apache.cxf.jaxrs.utils.ExceptionUtils.toHttpException(ExceptionUtils.java:157)
        at org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:526)
        at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:177)
        at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:77)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
        at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:243)
        at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:197)
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:149)
        at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:290)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:214)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:724)
/////////////////////
//Client side:
public class UserManagerServiceTest {
        public static void main(String[] args) {
                ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext
(new String[]{"rest-client.xml"});
                UserManager userManagerService = (UserManager) appContext.getBean("userManagerService");
                Date startDate = new DateTime(1959, 1, 1, 0, 0, DateTimeZone.UTC).toDate();
                Date endDate = new DateTime(1962, 1, 1, 0, 0, DateTimeZone.UTC).toDate();

                userManagerService.getUserBeforeDate(startDate);
                userManagerService.getUserByDateRange(startDate, endDate);
                appContext.close();
        }
}
///////////////////////
//rest-client.xml
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://cxf.apache.org/core"
        xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:jaxrs="http://cxf.apache.org/jaxrs-client"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                http://cxf.apache.org/jaxrs-client http://cxf.apache.org/schemas/jaxrs-client.xsd
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
        http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">


        <bean id="someDateConverter" class="com.my.demo.util.SomeDateConverter" />
        <bean id="paramConverterProvider" class="com.my.demo.util.ParamConverterProviderImpl">
                <constructor-arg>
                        <map><entry key="java.util.Date" value-ref="someDateConverter"
/></map>
                </constructor-arg>
        </bean>

        <jaxrs:client id="userManagerService"
                address="http://localhost:8080/RestDemo2/services/rest/UserManager"
                serviceClass="com.my.demo.rest.services.UserManager"
                inheritHeaders="true">
                <jaxrs:headers>
                        <entry key="Accept" value="application/json" />
                        <entry key="Content-Type" value="application/json" />
                </jaxrs:headers>
                <jaxrs:providers>
                        <ref bean="paramConverterProvider" />
                </jaxrs:providers>
        </jaxrs:client>
////////////////////
</beans>


/////Server side://////
//UserManager.java:

@Consumes("application/json")
@Produces("application/json")
public interface UserManager
{
        @GET
        @Path("/getUserByDateRange/{startDate}/{endDate}")
         @Produces(MediaType.TEXT_PLAIN)
        public String getUserByDateRange(@PathParam("startDate") Date startDate, @PathParam("endDate")
Date endDate);

        @GET
        @Path("/getUserBeforeDate/{startDate}")
         @Produces(MediaType.TEXT_PLAIN)
        public String getUserBeforeDate(@PathParam("startDate") Date startDate);

        @POST
        @Path("/insertUser/")
        public UserResponse insertUser(UserRequest request);
}
////////////////////////
//UserManagerService.java

public class UserManagerService implements UserManager{
        private UserManagerDao userDao;
        public UserManagerDao getUserDao(){return userDao;}
        public void setUserDao(UserManagerDao userDao){this.userDao = userDao;}

        public String getUserByDateRange(Date startDate, Date endDate){
                String response = new String();
                StringBuffer buf = new StringBuffer();
                try{
                        List<User> listUsers = getUserDao().fetchUserByDateRange(startDate,
endDate);
                        for (User user: listUsers){
                                buf.append("User:" + user);
                                buf.append("\n");
                        }
                        return buf.toString();
                }catch (Exception e){
                        response = "Error:"+ e.getClass() + ": " + e.getMessage();
                }
                return response;
        }

        public String getUserBeforeDate(Date startDate){
                String response = new String();
                StringBuffer buf = new StringBuffer();
                try{
                        List<User> listUsers = getUserDao().fetchUserBeforeDate(startDate);
                        for (User user: listUsers){
                                buf.append("User:" + user);
                                buf.append("\n");
                        }
                        return buf.toString();
                }catch (Exception e){
                        response = "Error:"+ e.getClass() + ": " + e.getMessage();
                }
                return response;
        }

        public UserResponse insertUser(UserRequest request){
                UserResponse response = new UserResponse();
                try{
                        getUserDao().insertUser(request.getUser());
                }
                catch (Exception e){
                        response.setSuccess(false);
                        response.setErrorMessage(e.getClass() + ": " + e.getMessage());
                }
                return response;
        }
}
/////////////////////////////////
//SomeDateConverter.java
public class SomeDateConverter implements ParamConverter<Date> {
        Logger logger = LoggerFactory.getLogger(SomeDateConverter.class);
        @Override
        public Date fromString(String dateString) {
                if (dateString.contains("-")) {
                        DateTime result = ISODateTimeFormat.dateTimeParser().withZone(DateTimeZone.UTC).parseDateTime(dateString);
                        return result.toDate();
                }
                return new Date(Long.parseLong(dateString));
        }

        @Override
        public String toString(Date dateToConvert) {
                return ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC)  .print(dateToConvert.getTime());
        }
}
/////////////////////////////////
//ParamConverterProviderImpl.java
public class ParamConverterProviderImpl implements ParamConverterProvider {
        private final Map<Class<?>, ? extends ParamConverter<?>> paramConverters;
        public ParamConverterProviderImpl(      Map<Class<?>, ? extends ParamConverter<?>>
paramConverters) {
                this.paramConverters = paramConverters;
        }
        @Override
        public <T> ParamConverter<T> getConverter(Class<T> rawClass,Type
genericType, Annotation[] annotations) {
                return (ParamConverter<T>) paramConverters.get(rawClass);
        }
}
////////////////////////
//rest-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxws="http://cxf.apache.org/jaxws"
        xmlns:jaxrs="http://cxf.apache.org/jaxrs" xsi:schemaLocation=" http://cxf.apache.org/core
        http://cxf.apache.org/schemas/core.xsd http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxrs
        http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
-->
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://cxf.apache.org/core"
        xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                http://cxf.apache.org/jaxrs-client http://cxf.apache.org/schemas/jaxrs-client.xsd
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
        http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">

        <import resource="classpath:META-INF/cxf/cxf.xml" />
        <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

        <cxf:bus>
                <cxf:features>
                        <cxf:logging />
                </cxf:features>
        </cxf:bus>

        <bean id="someDateConverter" class="com.my.demo.util.SomeDateConverter" />
        <bean id="paramConverterProvider" class="com.my.demo.util.ParamConverterProviderImpl">
                <constructor-arg>
                        <map>
                                <entry key="java.util.Date" value-ref="someDateConverter"
/>
                        </map>
                </constructor-arg>
        </bean>

        <bean id="userDao"
                class="com.my.demo.rest.dao.impl.UserManagerMemoryDao">
        </bean>

        <bean id="userManagerService"
                class="com.my.demo.rest.services.impl.UserManagerService">
                <property name="userDao" ref="userDao" />
        </bean>

        <bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"
/>

        <jaxrs:server id="userManagerREST" address="/rest/UserManager">
                <jaxrs:serviceBeans>
                        <ref bean="userManagerService" />
                </jaxrs:serviceBeans>
                <jaxrs:providers>
                        <ref bean='jsonProvider' />
                        <ref bean="paramConverterProvider" />
                </jaxrs:providers>
        </jaxrs:server>

</beans>
//////////////////


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