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
ce#{http://www.company.com/api/DeviceManagement/1}GetScopes 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.