4 Replies Latest reply: Dec 19, 2011 9:37 AM by Marko Strukelj RSS

problem consuming web service using Axis2 in EPP5.1.1

Andrew Cheung Newbie

Hi, all. In a portlet application inside my portal (environment details listed below), I'm trying to consume a web service, but got the error message "java.lang.NoClassDefFoundError: org/apache/axis2/client/Stub". Details as follows:

 

Environment: EPP 5.1.1

Axis2 version 1.6.1 (This is installed by downloading the zip file from the Axis2 site, exploded it and put the axis2.war folder into the server/<Nodename>/deploy folder.)

 

Web service:

-Created using .NET, running on my local machine. There are 2 web methods: HelloWorld() which returns the string "Hello World", and add(int a, int b) which returns the sum of 2 numbers.

 

Web service client generation:

I used JBoss Developer Studio 4.0.0 and generated the Service1.aar file (Configuration: Server runtime: JBoss AS 5.1; Web service runtime: Apache Axis2; Client Project: TestAdd which is a dynamic web project, client EAR project: TestAddEAR); added a services.xml file (details below); did a build and placed it in the axis2.war/WEB-INF/services folder. Added "Services.aar" into the services.list file.

 

services.xml:

<service name="TestAdd" scope="request" targetNamespace="org.tempuri">

    <Description> TestAdd web service </Description> 

    <!-- 

    <parameter name="ServiceClass" locked="xsd:false">TestAdd</parameter>

    <operation name="add">

        <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>

    </operation>

    -->

</service>

 

------------------------

Relevant code in portlet application (myClass.java) :

 

import org.tempuri.Service1Stub;

import org.apache.axis2.AxisFault;

 

public String GetToken() throws AxisFault {

 

org.tempuri.Service1Stub stub = new org.tempuri.Service1Stub();

            org.tempuri.Service1Stub.Add wsreq = new org.tempuri.Service1Stub.Add();

            wsreq.setA(2);

            wsreq.setB(3);

            org.tempuri.Service1Stub.AddResponse wsresp = stub.add(wsreq);

            System.out.println("DEBUGXXX : ADDRESULT = " + wsresp.getAddResult());

}

 

I have added references to the axis2.war/WEB-INF/lib folder (which contains the jar files that include org.apache.axis2.client.Stub) as well as copy the Services.aar file (and changed it's name to Services.jar) and put it in the lib folder for portlet application.

------------------------------

Error messages in server.log:

 

2011-12-15 16:23:49,138 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/myPortlet].[myClass]] (http-127.0.0.1-8080-3) Servlet.service() for servlet myClass threw exception

java.lang.ClassNotFoundException: org.apache.axis2.client.Stub

    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)

    at java.security.AccessController.doPrivileged(Native Method)

    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)

    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

    at java.lang.Class.forName0(Native Method)

    at java.lang.Class.forName(Class.java:247)

    at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:300)

    at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1138)

    at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:862)

    at org.jboss.classloader.spi.base.BaseClassLoader.doLoadClass(BaseClassLoader.java:502)

    at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:447)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

    at java.lang.ClassLoader.defineClass1(Native Method)

    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)

    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)

    at org.jboss.classloader.spi.base.BaseClassLoader.access$200(BaseClassLoader.java:67)

    at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:633)

    at org.jboss.classloader.spi.base.BaseClassLoader$2.run(BaseClassLoader.java:592)

    at java.security.AccessController.doPrivileged(Native Method)

    at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:591)

    at org.jboss.classloader.spi.base.BaseClassLoader.loadClassLocally(BaseClassLoader.java:568)

    at org.jboss.classloader.spi.base.BaseDelegateLoader.loadClass(BaseDelegateLoader.java:135)

    at org.jboss.classloader.spi.filter.FilteredDelegateLoader.loadClass(FilteredDelegateLoader.java:131)

    at org.jboss.classloader.spi.base.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:455)

    at org.jboss.classloader.spi.base.ClassLoaderManager.nextTask(ClassLoaderManager.java:267)

    at org.jboss.classloader.spi.base.ClassLoaderManager.process(ClassLoaderManager.java:166)

    at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:276)

    at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1138)

    at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:862)

    at org.jboss.classloader.spi.base.BaseClassLoader.doLoadClass(BaseClassLoader.java:502)

    at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:447)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

    at demo.myClass.GetToken(Unknown Source)

    at demo.myClass.processRequest(Unknown Source)

    at demo.myClass.doGet(Unknown Source)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)

    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:183)

    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:95)

    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)

    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)

    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)

    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)

    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:599)

    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:451)

    at java.lang.Thread.run(Thread.java:619)

 

 

Why can't it find the client.Stub definition?

 

Any help in resolving this is appreciated.

 

  -Andrew

  • 1. Re: problem consuming web service using Axis2 in EPP5.1.1
    Andrew Cheung Newbie

    Problem resolved. The resolution is to remove the Service1.jar file in the local lib folder in the .war file and reference the Service1.aar file in the axis2.war/WEB-INF/service folder.

     

    Now onto the next problem :

    server.log:

     

    2011-12-16 15:11:21,722 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/myPortlet].[myClass]] (http-127.0.0.1-8080-3) Servlet.service() for servlet myClass threw exception

    java.lang.ClassNotFoundException: org.tempuri.Service1Stub from BaseClassLoader@15ec68e9{vfszip:/C:/jbdevstudio40/jboss-eap/jboss-as/server/bres-local/deploy/myPortlet.war/}

        at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:477)

        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

        at demo.myClass.GetToken(Unknown Source)

        at demo.myClass.processRequest(Unknown Source)

        at demo.myClass.doGet(Unknown Source)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)

        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:183)

        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:95)

        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)

        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)

        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)

        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)

        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:599)

        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:451)

        at java.lang.Thread.run(Thread.java:619)

     

    Again, any help is appreciated.

     

    -Andrew

  • 2. Re: problem consuming web service using Axis2 in EPP5.1.1
    Marko Strukelj Master

    I think your problem is not really GateIn/EPP related - it could be packaging related ...

     

    I haven't played with Axis2 in a long time, but simply starting at your stacktrace I'd start by looking at the jar containing axis generated stubs for the class org.tempuri.Service1Stub.

     

    That jar should be in your myPortlet.war/lib

  • 3. Re: problem consuming web service using Axis2 in EPP5.1.1
    Andrew Cheung Newbie

    I originally had the jar that contains org.tempuri.Services1Stub (which is actually the Services1.aar file but I changed the name to be Services1.jar) inside myPortlet.war/WEB-INF/lib, but that caused different problems (please see my original post for the packaging and the errors in the log). But thanks for the pointers.

     

      -Andrew

  • 4. Re: problem consuming web service using Axis2 in EPP5.1.1
    Marko Strukelj Master

    First, I suggest you start with a simple servlet instead of portlet to get your WS consumer working.

    Second, an archive containing classes has to be called something.jar - not .aar or anything else - these are java packaging basics. This .jar if deployed as part of a .war must be located in WEB-INF/lib and nowhere else.

    Third, you need your org.tempuri.Services1Stub on your classpath otherwise you will get ClassNotFoundException, and your app won't work.

    Fourth, NoClassDefFoundError means that while loading one class, another class that is a dependency of the first class could not be found. I've seen many situations when error reporting was misleading at this point - not really spelling out the real class that was missing. You're likely missing some axis2 dependency.

     

    Put the following in your servlet / portlet:

     

    Class.forName("org.apache.axis2.client.Stub");

    Class.forName("org.tempuri.Service1Stub");

     

    Make sure both of these classes are in some jar inside your myPortlet.war/WEB-INF/lib

     

    If you get an exception it may contain a new lead on any missing dependency class.