Hi On 18/09/12 11:03, SoulSpirit wrote:
Hello, I'm trying to implement a simple JAX-RS client passing a cusom bean as parameter, which contains an enum field:class Person{ private String name; private Title title; ... } enum Title{ MR, MS; } Server-side the implementation is like: @Path("/helloWorld") @Produces("text/plain") public class HelloWorldServiceImpl implements HelloWorldService{ @GET @Path("/personQuery") public String sayHelloTo( @QueryParam("") Person person ){ return "hello " + person.getTitle().getValue() + " " + person.getName(); } } Through an HTTP GET, the service works as expected by calling it this way: http://localhost:8080/helloWorld/personQuery?name=name&title=MR I've then tried to implement a proxy client: Person person = new Person(); person.setTitle( Title.MR ); person.setName( "name" ); HelloWorldService service = JAXRSClientFactory.create( "http://localhost:8080/", HelloWorldService.class ); String result = service.sayHelloTo( person ); But running it I get an exception when CXF tries (oddly) to create a new instance of my enum: java.lang.InstantiationException: model.Title at java.lang.Class.newInstance0(Class.java:357) at java.lang.Class.newInstance(Class.java:325) at org.apache.cxf.jaxrs.utils.InjectionUtils.handleBean(InjectionUtils.java:457) at org.apache.cxf.jaxrs.utils.InjectionUtils.handleBean(InjectionUtils.java:550) at org.apache.cxf.jaxrs.utils.JAXRSUtils.readQueryString(JAXRSUtils.java:959) at org.apache.cxf.jaxrs.utils.JAXRSUtils.createHttpParameterValue(JAXRSUtils.java:657) at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:625) at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:578) at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:238) at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:89) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262) at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:211) at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213) at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:154) at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:130) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:221) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:146) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:197) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:722) I got the stacktrace by debugging org.apache.cxf.jaxrs.utils.InjectionUtils, since the catch ignores the oiginating exception while logging a generic error (by the way, this behavior is very questionable...). It seems like InjectionUtils doesn't handle well enums, but perhaps I'm missing something... Oh, I'm running apache-cxf-2.6.2.
I think it is a bug to do with extracting bean values at the point of building the request URI - the code does not understand how to handle enums - will get that fixed, in meantime, please try WebClient...
thanks, Sergey
Thank you for any suggestion. -- View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-proxy-client-and-enums-tp5714077.html Sent from the cxf-user mailing list archive at Nabble.com.
-- Sergey Beryozkin Talend Community Coders http://coders.talend.com/ Blog: http://sberyozkin.blogspot.com
