четверг, 5 апреля 2012 г.

Apache CXF client on Weblogic 12c

When i am trying to deploy application with Apache CXF client on Weblogic 12c, i got error:
 java.lang.ClassCastException: weblogic.wsee.jaxws.spi.ClientInstanceInvocationHandler

Analysis of the error stack pointed to the problem on line 4

1:   import org.apache.cxf.endpoint.Client;   
2:   import org.apache.cxf.frontend.ClientProxy;   
3:   ....   
4:   Client client = ClientProxy.getClient(moderationService);   

After reading documentation, googling and debugging, i found reason of error - After reading documentation, googling and debugging, i found reason of error - Weblogic return its own implementation of javax.xml.ws.spi.Provider.

Documentation says:
The algorithm used to locate the provider subclass to use consists of the following steps:

  • If a resource with the name of META-INF/services/javax.xml.ws.spi.Provider exists, then its first line, if present, is used as the UTF-8 encoded name of the implementation class.
  • If the $java.home/lib/jaxws.properties file exists and it is readable by the java.util.Properties.load(InputStream) method and it contains an entry whose key is javax.xml.ws.spi.Provider, then the value of that entry is used as the name of the implementation class.
  • If a system property with the name javax.xml.ws.spi.Provider is defined, then its value is used as the name of the implementation class.
  • Finally, a default implementation class name is used. 
  •  

The solution is to add resource preference settings in weblogic-application.xml, to use Provider implementation from cxf-rt-frontend-jaxws-x.x.x.jar

 <prefer-application-resources>  
   <resource-name>META-INF/services/javax.xml.ws.spi.Provider</resource-name>  
 </prefer-application-resources>  

My weblogic-application.xml:

 <?xml version="1.0" encoding="UTF-8"?>  
 <weblogic-application xmlns="http://xmlns.oracle.com/weblogic/weblogic-application"  
   
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
            xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.4/weblogic-application.xsd">  
   <application-param>  
     <param-name>webapp.encoding.default</param-name>  
     <param-value>UTF-8</param-value>  
   </application-param>  
   
   <prefer-application-packages>  
     <package-name>antlr.*</package-name>  
     <package-name>org.apache.*</package-name>  
     <package-name>org.joda.time.*</package-name>  
     <package-name>org.objectweb.asm.*</package-name>  
     <package-name>org.slf4j.*</package-name>  
     <package-name>javassist.*</package-name>  
   </prefer-application-packages>  
   
   <prefer-application-resources>  
     <resource-name>META-INF/services/javax.xml.ws.spi.Provider</resource-name>  
   </prefer-application-resources>  
   
 </weblogic-application>  

1 комментарий:

  1. Thank you, it helped. For additional info see http://stackoverflow.com/questions/6364333/jax-ws-when-apache-cxf-is-installed-it-steals-default-jdk-jax-ws-implementat

    ОтветитьУдалить