Tuesday, October 29, 2013

Change Soap Request Response Header : java.lang.UnsupportedOperationException / javax.xml.ws.soap.SOAPFaultException: Fault string, and possibly fault code, not set


While testing a web service, I have encountred this error:

javax.xml.ws.soap.SOAPFaultException: Fault string, and possibly fault code, not set
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:146)
...
Caused by: java.lang.UnsupportedOperationException
at java.util.AbstractMap.put(AbstractMap.java:186)
at org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor.setSoapAction(SoapPreProtocolOutInterceptor.java:120)
at org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor.handleMessage(SoapPreProtocolOutInterceptor.java:62)
at org.apache.cxf.binding.soap.interceptor.SoapPreProtocolOutInterceptor.handleMessage(SoapPreProtocolOutInterceptor.java:46)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:516)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:265)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)


In fact, I have a client web service code trying to add a SOAP header to a request before calling the Web service.
The problem comes from this part:

BindingProvider bp = (BindingProvider) webServicePort;
bp.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,
Collections.singletonMap("Cookie", Collections
.singletonList(yourCookieString));

In fact Collections.singletonMap() is used to get an immutable map which cause a UnsupportedOperationException in the getRequestContext().put() method.
Thanks to Ridwan Nizam, we have changed the code :

BindingProvider bp= (BindingProvider) webServicePort;
Map<String, List<String>> singletonMap = new HashMap<String, List<String>>() singletonMap.put("Cookie", Collections.singletonList(yourCookieString));
bp.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,
singletonMap);

Great, the Exception is then RESOLVED ;)


Biblio:
http://blog.sanaulla.info/2012/11/28/unsupportedoperation-exception-while-using-map-in-java/

Monday, October 28, 2013

Cannot be cast to com.sun.xml.ws.developer.WSBindingProvider: Jboss5 with Metro to Jboss6 /JBoss EAP 6 with JbossWS-Stack

I was working on a migration form Jboss5 using Metro to a Jboss6.1 using the JbossWS-CXF3.4 stack which comes with Jboss.
When I run my application, I have this error :
Cannot be cast to com.sun.xml.ws.developer.WSBindingProvider

In fact, I have a code, where the Webservice Port was cast to com.sun.xml.internal.ws.developer.WSBindingProvider

 WSBindingProvider bp = (WSBindingProvider) webServicePort;

This cast works before with Metro as we use the Sun reference implementation of JAX-WS. As Jboss6.1 comes with CXF stack for web Service, this cast should be adjusted by using javax.xml.ws.BindingProvider.
So the code becomes :

BindingProvider bp = (BindingProvider) webServicePort;

Hope it helps you :)

Sunday, October 6, 2013

Java compiler level does not match the version of the installed java project facet error in eclipse

I have this Error in eclipse for my prject :

java compiler level does not match the version of the installed java project facet

I was using JDK 1.6.0 as a JRE System Library. The solution was to right clic on the project -> Properties and to fix the Project Facet according to the Java version you are using,  here it is 1.6 instead of 1.5 which I have found.


The error is then fixed :) .

Articles les plus consultés