views:

927

answers:

4

I've recently had lots of issues trying to deploy a JAX-WS web servcie client on Weblogic 9.2. It turns out there is no straightforward guide on how to achieve this, so I decided to put together this short wiki entry hoping it might be useful for others.

Firstly, Weblogic 9.2 does not support web servcies using JAX-WS in general. It comes with old versions of XML-related java libraries that are incompatible with the latest JAX-WS (similar issues occur with Axis2, only Axis1 seems to be working flawlessly with Weblogic 9.x but that's a very old and unsupported library).

So, in order to get it working, some hacking is required. This is how I did it (note that we're using ant in our legacy corporate project, you probably should be using maven which should eliminate 50% of those steps below):

1.Download the most recent JAX-WS distribution from https://jax-ws.dev.java.net/ (The exact version I got was JAXWS2.2-20091203.zip)

2.Place the JAX-WS jars with the dependencies in a separate folder like lib/webservices.

3.Create a patternset in ant to reference those jars:

<?xml version="1.0"?>
<patternset id="jaxws.classpath">
<include name="webservices/jsr173_api.jar" />  
<include name="webservices/jsr181-api.jar" />       
<include name="webservices/jaxb-api.jar" />
<include name="webservices/jaxb-impl.jar" />
<include name="webservices/jaxb-xjc.jar" /> 
<include name="webservices/jaxws-tools.jar" />
<include name="webservices/jaxws-rt.jar" />       
<include name="webservices/jaxws-api.jar" />
<include name="webservices/policy.jar" />
<include name="webservices/woodstox.jar" />   
<include name="webservices/streambuffer.jar" />       
<include name="webservices/stax-ex.jar" />
<include name="webservices/saaj-api.jar" />
<include name="webservices/saaj-impl.jar" />
<include name="webservices/gmbal-api-only.jar" />   
</patternset>

4.Include the patternset in your WAR-related goal. This could look something like:

<?xml version="1.0"?>
<copy todir="${wardir.lib}" includeEmptyDirs="false" flatten="true">
<fileset dir="${libs}">
<!--lots of libs here, related to your project -->
<patternset refid="jaxws.classpath"/>
</fileset>
</copy>

(not the flatten="true" parameter - it's important as Weblogic 9.x is by default not smart enough to access jars located in a different lcoation than WEB-INF/lib inside your WAR file)

5.In case of clashes, Weblogic uses its own jars by default. We want it to use the JAX-WS jars from our application instead. This is achieved by preparing a weblogic-application.xml file and placing it in META-INF folder of the deplotyed EAR file. It should look like this:

<?xml version="1.0"?>
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
<prefer-application-packages>
    <package-name>javax.jws.*</package-name>
    <package-name>javax.xml.bind.*</package-name>
    <package-name>javax.xml.crypto.*</package-name>
    <package-name>javax.xml.registry.*</package-name>
    <package-name>javax.xml.rpc.*</package-name>
    <package-name>javax.xml.soap.*</package-name>
    <package-name>javax.xml.stream.*</package-name>
    <package-name>javax.xml.ws.*</package-name>
    <package-name>com.sun.xml.api.streaming.*</package-name>
</prefer-application-packages>
</weblogic-application>

6.Remember to place that weblogic-application.xml file in your EAR! The ant goal for that may look similar to:

<?xml version="1.0"?>
<target name="build-ear" depends="war, manifest">
    <delete dir="${dist}"/>
    <mkdir dir="${dist}"/>    
    <jar destfile="${warfile}" basedir="${wardir}"/>        
    <ear destfile="${earfile}" appxml="resources/${app.name}/application.xml">
        <fileset dir="${dist}" includes="${app.name}.war"/>
        <metainf dir="resources/META-INF"/>     
    </ear>
</target>

7.Also you need to tell weblogic to prefer your WEB-INF classes to those in distribution. You do that by placing the following lines in your WEB-INF/weblogic.xml file:

<?xml version="1.0"?>
<container-descriptor>
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>

8.And that's it for the weblogic-related configuration. Now only set up your JAX-WS goal. The one below is going to simply generate the web service stubs and classes based on a locally deployed WSDL file and place them in a folder in your app:

<?xml version="1.0"?>
<target name="generate-jaxws-client">
        <taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport"> 
            <classpath path="classpath.main"/>
        </taskdef>          
        <wsimport 
             destdir="${src}"
             package="acme.somewhere.in.your.package.tree.webservices."
             keep="true" 
             wsdl="http://localhost:8088/mockWebService?WSDL"&gt;              
        </wsimport>
    </target>   

Remember about the keep="true" parameter. Without it, wsimport generates the classes and... deletes them, believe it or not!

For mocking a web service I suggest using SOAPUI, an open source project. Very easy to deploy, crucial for web servcies intergation testing.

9.We're almost there. The final thing is to write a Java class for testing the web service, try to run it as a standalone app first (or as part of your unit tests)

10.And then try to run the same code from withing Weblogic. It should work. It worked for me. After some 3 days of frustration. And yes, I know I should've put 9 and 10 under a single bullet-point, but the title "10 steps to deploy a JAX-WS web service under Web logic 9.2 using ant" sounds just so much better.

Please, edit this post and improve it if you find something missing!

A: 

This is not really a question but a guide so I'm answering it myself just to mark it as done.

michuk
+1  A: 

Another way of dealing with web services on Weblogic 9.2 is using Apache CXF. This particularly well integrates with Spring as each web service is exposed as a bean and the actual classes don't even need to know that they are web services, it's all configuration driven.

A great guide about setting up Apache CXF on Weblogic can be found here: http://wheelersoftware.com/articles/spring-cxf-web-services.html

This works on Weblogic 9.2 as well and if you need to expose web services, not just connect to existing ones, this is by far better approach than using plain JAXWS (which is used by CXF anyway).

michuk
A: 

HI I have a question, I need to get the same working in Weblogic 10.0, what you suggest here really sounds promising. But my weblogic is running on JRocket 1.5.*, so I was required to compile using jdk 1.5. What I found is if you use the latest jax-ws, you have to compile it using jdk 1.6.

Am I right?

Do you run weblogic 9.2 with jdk 1.5 or 1.6?

Thanks a lot,

Minghui Liu

We used jrocket on wl9.2 as well and compiles using jdk 1.5 - it worked fine with the approach described. Not sure about wl10 though. Using common sense usually fails in case of WL+XML issues so I won't even guess.
michuk
A: 

Having problems with the approach outlined above. Everything works fine and I can call my webservice from the generated client fine from a jsp. Now, when I start building other things into the web app, I get errors. It seems that anything that causes this app to parse xml fails.

java.lang.ClassCastException: com.ctc.wstx.stax.WstxInputFactory
 at javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:136)
 at weblogic.servlet.internal.WebAppHelper.addListenerElements(WebAppHelper.java:244)
 at weblogic.servlet.internal.WebAppHelper$IOHelperImpl.parseXML(WebAppHelper.java:224)
 at weblogic.descriptor.DescriptorCache.parseXML(DescriptorCache.java:324)
 at weblogic.servlet.internal.WebAppHelper.registerTagLibListeners(WebAppHelper.java:174)
 Truncated. see log file for complete stacktrace

This can be as simple as adding trinidad jar into the classpath

Paul
I remember having a similar error in my project at some point. Playing with weblogic-application.xml helpe from what I remember.
michuk
Had to give up in the end. it seems that the same classloader is used to parse the web.xml as is used for the app.
Paul