Hi Wrapping explicit collections is a good thing IMHO and I'd encourage it. A wrapper is easier to manage, when we are talking about the new associated changes, for ex, you might want some additional info describing the collection. Without the wrapper you'll need to add a new method or modify the method to accommodate a new parameter. Explicit collections are not possible to describe in WADL - unless we create artificial wrapper names.
You might want to try using Jackson - it is probably able to read the explicit collections; buy as I said I'll apply the patch for the Jettison based provider to cope to Sergey On Fri, Jan 21, 2011 at 6:17 PM, Hardeep Singh <[email protected]>wrote: > Hi > > Thanks for the pointing out the problem. Changing the root element names > fixed the problem. > > This is how I invoke WebClient for Scopes. > _clientWrapped is an instance of WebClient created by supplying a JSON > provider with a wrapping Map and baseAddress. > > Scopes scopes = _clientWrapped.path(ScopesPath).get(Scopes.class); > > This is how I invoke WebClient for Scope. > _client is an instance of Webclient created by just giving a baseAddress. > > Scope scope = _client.path(ScopesPath + "/" + scopeId).get(Scope.class); > > If I use _clientWrapped to get Scope it would return Null values. The > wrapper map does not contain an entry for Scope, only for Scope( and other > Beans) Any idea how to get around this behavior? It is not necessary, but > just be nice to be able to use one client instance( _clientWrapped) for > both > calls. > > I am wrapping JSON's before consuming to get around the problem of not able > to unmarshall collections in root element. If there is another way to parse > Collections in Root Element pls let me know. > > I am new to this, so I don't understand what you mean by " HTTP service > backed up by the JAX-WS runtime". I am using this Webclient > org.apache.cxf.jaxrs.client.WebClient; > > Regards > Hardeep Singh > > > > On 1/21/11 2:09 AM, "Sergey Beryozkin" <[email protected]> wrote: > > > Hi > > > > Both Scopes and Scope have the same @XmlRootElement value, may be this is > > what affecting it ? > > Can you post a sample JSON sequence that needs to be consumed, the way it > > looks on the wire ? > > > > How do you use WebClient to invoke ? > > > > It apppears you're invoking on the HTTP service backed up by the JAX-WS > > runtime ? Interesting...but it should work, does not matter how the > service > > is implemented... > > > > By the way, JSONProvider (Jettison-based) can not read (as opposed to > write) > > the explicit collections - but a patch is available - I really need to > look > > into applying it, it needs a bit of refactoring as far as recall... > > > > cheers, Sergey > > > > On Fri, Jan 21, 2011 at 1:29 AM, Singh, Hardeep > > <[email protected]>wrote: > > > >> Hi > >> > >> I am using the Apache CXF for consuming rest services. I am getting the > >> Cannot cast exception. Any idea why we get this exception and way to fix > >> this? > >> > >> Regards > >> Hardeep > >> > >> The beans that I am trying to unmarshall look like this. > >> @XmlAccessorType(XmlAccessType.FIELD) > >> @XmlRootElement(name = "settings") > >> public class Scopes > >> { > >> @XmlElement(name = "settings") > >> private List<Scope> settings; > >> } > >> > >> I am using XmlType and XmlRootEelement annotationin Scope, so that i can > >> also query for an individual Scope as well as Scopes. > >> If I remove XmlRootElement from Scope then get to Scopes works but not > to > >> Scope. > >> If I remove XmlType from Scope then Scopes doesn't work but Scope does. > >> > >> @XmlAccessorType(XmlAccessType.FIELD) > >> @XmlType(name="") > >> @XmlRootElement(name="settings") > >> public class Scope > >> { > >> > >> @XmlElement(name = "attributes") > >> private Attributes attributes; > >> > >> @XmlElement(name = "id") > >> private String id; > >> > >> ........ > >> } > >> > >> > >> The webclient is created in the following way > >> I am using the wrapperMaps because I couldn't get the framework to > >> unmarshall a list in the root element. So i add a wrapper and make the > list > >> appear as a sub-element of root element. > >> > >> JSONProvider p = new JSONProvider(); > >> //p.setWrapperName("settings"); > >> Map<String,String> wrapperMap = new HashMap<String,String>(); > >> wrapperMap.put(Scopes.class.getName(), "settings"); > >> wrapperMap.put(PalDeviceInformation.class.getName(),"device"); > >> //wrapperMap.put(Scope.class.getName(),"settings"); > >> > >> p.setWrapperMap(wrapperMap); > >> p.setSupportUnwrapped(true); > >> LinkedList<JSONProvider> providerList = new > >> LinkedList<JSONProvider>(); > >> providerList.add(p); > >> _clientWrapped = WebClient.create(properties.get( > >> ConfigProperties.kUrlAddr), providerList); > >> > >> > >> Stack Trace of the Exception > >> > >> 8799 [qtp1418893-61] WARN org.apache.cxf.phase.PhaseInterceptorChain - > >> Application > >> { > >> > http://www.company.com/api/DeviceManagement/1}DeviceManagementPortTypeServi<http://www.company.com/api/DeviceManagement/1%7DDeviceManagementPortTypeServi> > >> ce#{http://www.company.com/api/DeviceManagement/1}GetScopes<http://www.company.com/api/DeviceManagement/1%7DGetScopes> > <http://www.compan > >> > y.com/api/DeviceManagement/1%7DDeviceManagementPortTypeServi%0Ace#%7Bhttp://w > >> ww.company.com/api/DeviceManagement/1%7DGetScopes>has thrown > >> exception, unwinding now > >> org.apache.cxf.interceptor.Fault: Cannot cast > >> com.company.polaris.configuration.Scope to > >> com.company.polaris.configuration.Scopes > >> at > >> > >> > org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.j > >> ava:155) > >> at > >> > >> > org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMet > >> hodInvoker.java:86) > >> at > >> > >> > org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:1 > >> 21) > >> at > >> > org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:60) > >> at > >> > >> > org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:7 > >> 5) > >> at > >> > >> > org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInt > >> erceptor.java:58) > >> at > >> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) > >> at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) > >> at java.util.concurrent.FutureTask.run(FutureTask.java:166) > >> at > >> > >> > org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.jav > >> a:37) > >> at > >> > >> > org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceIn > >> vokerInterceptor.java:106) > >> at > >> > >> > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain > >> .java:247) > >> at > >> > >> > org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationOb > >> server.java:113) > >> at > >> > >> > org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(Jett > >> yHTTPDestination.java:311) > >> at > >> > >> > org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTP > >> Destination.java:280) > >> at > >> > >> > org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler > >> .java:72) > >> at > >> > >> > org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java > >> :932) > >> at > >> > >> > org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java: > >> 870) > >> at > >> > >> > org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117 > >> ) > >> at > >> > >> > org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHand > >> lerCollection.java:245) > >> at > >> > >> > org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:1 > >> 13) > >> at org.eclipse.jetty.server.Server.handle(Server.java:351) > >> at > >> > >> > org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:59 > >> 4) > >> at > >> > >> > org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnectio > >> n.java:1059) > >> at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:764) > >> at > org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:217) > >> at > >> org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:424) > >> at > >> > >> > org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.jav > >> a:506) > >> at > >> > >> > org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:4 > >> 36) > >> at java.lang.Thread.run(Thread.java:636) > >> Caused by: java.lang.ClassCastException: Cannot cast > >> com.company.polaris.configuration.Scope to > >> com.company.polaris.configuration.Scopes > >> at java.lang.Class.cast(Class.java:3007) > >> at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:330) > >> at org.apache.cxf.jaxrs.client.WebClient.get(WebClient.java:391) > >> at > >> > >> > com.company.polaris.configuration.SystemConfig.gePScopes(SystemConfig.java:4 > >> 08) > >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > >> at > >> > >> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57 > >> ) > >> at > >> > >> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl > >> .java:43) > >> at java.lang.reflect.Method.invoke(Method.java:616) > >> at > >> > >> > org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInv > >> oker.java:173) > >> at > >> > >> > org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:8 > >> 9) > >> ... 27 more > >> > >> > >> > >> > >> This transmission is intended only for use by the intended > >> recipient(s). If you are not an intended recipient you should not read, > >> disclose copy, circulate or in any other way use the information > contained > >> in this transmission. The information contained in this transmission may > be > >> confidential and/or privileged. If you have received this transmission > in > >> error, please notify the sender immediately and delete this transmission > >> including any attachments. > > > This transmission is intended only for use by the intended > recipient(s). If you are not an intended recipient you should not read, > disclose copy, circulate or in any other way use the information contained > in this transmission. The information contained in this transmission may be > confidential and/or privileged. If you have received this transmission in > error, please notify the sender immediately and delete this transmission > including any attachments. >
