Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SOAP and servlets living together?

1 view
Skip to first unread message

unixhack.blogspot.com

unread,
Oct 27, 2004, 1:29:31 AM10/27/04
to
Hi,

I'm trying to develop an application that uses SOAP and servlets.
So far I have some servlets and JSP's running fine. They access
the database, modify it, display data, etc.

I want to add some SOAP functionality to the application using
Apache SOAP, but so far I haven't had much luck. I am following
the Apache SOAP docs and the Tomcat/SOAP instructions at:

http://www.onjava.com/pub/a/onjava/2002/02/27/tomcat.html

So far I have modified catalina.sh to

- add xercesImpl.jar at the beginning of the CLASSPATH
- add the path to my soap classes at the end of the CLASSPATH

This works, and I am able to deploy the sample SOAP service
from the OnJava example using the ServiceManagerClient class.

This would be fine if I didn't had to access the classes I
already wrote. Which is not the case.

So, I add the directory where my classes live at the end of
the CLASSPATH in catalina.sh. This directory look something like:

$CLASSPATH:$CATALINA_HOME/webapps/myapp/WEB-INF/classes

This allows the SOAP service to access public methods provided
by my application. However, if I now try to access my application
via the usual URL (http://my.host.com:8080/myapp), I get a 404
error!

The Tomcat log shows a somewhat cryptic stack trace:

Oct 26, 2004 6:35:58 PM org.apache.catalina.startup.HostConfig deployDirectories
SEVERE: Error deploying web application directory myapp
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)

... and so on and so forth, without any reference to any of the
classes I actually wrote. BTW this

At this point, I'm completely stumped. Any idea of how to get
SOAP and servlets to live together?

Should I ditch the whole ServiceManagerClient/ RPC router
thing and just chisel the SOAP functionality into my classes?

If this is not the best forum to ask this type of questions, could
you please recommend some other place to go?

Thanks a lot if you read this far, and thanks in advance for any help,

Ernesto

John C. Bollinger

unread,
Oct 27, 2004, 12:38:45 PM10/27/04
to
unixhack.blogspot.com wrote:

> I'm trying to develop an application that uses SOAP and servlets.
> So far I have some servlets and JSP's running fine. They access
> the database, modify it, display data, etc.

Good.

> I want to add some SOAP functionality to the application using
> Apache SOAP, but so far I haven't had much luck. I am following
> the Apache SOAP docs and the Tomcat/SOAP instructions at:
>
> http://www.onjava.com/pub/a/onjava/2002/02/27/tomcat.html

This is relatively old.

> So far I have modified catalina.sh to
>
> - add xercesImpl.jar at the beginning of the CLASSPATH
> - add the path to my soap classes at the end of the CLASSPATH

If you are using Tomcat 4 or later, neither of these should be
necessary. You should be able to just put any jars you need into
$CATLINA_BASE/shared/lib if you want them to be accessible to all
webapps, or into a particular webapp's WEB-INF/lib if you only need them
to be accessible to one webapp.

If you are running against Java 1.4 then you may well not need
xercesImpl at all, as Java 1.4 includes a built-in XML parser
implementation.

> This works, and I am able to deploy the sample SOAP service
> from the OnJava example using the ServiceManagerClient class.
>
> This would be fine if I didn't had to access the classes I
> already wrote. Which is not the case.
>
> So, I add the directory where my classes live at the end of
> the CLASSPATH in catalina.sh. This directory look something like:
>
> $CLASSPATH:$CATALINA_HOME/webapps/myapp/WEB-INF/classes

Ack! No! Never do that! The classes associated with a specific webapp
should never be in the server's base classpath.

If you are writing SOAP-based classes that depend on the classes of your
existing webapp, then very likely they belong in the same webapp. Put
them there and you will not have dependency problems. If you need to
use multiple webapps for some reason, then put those classes that are
needed by more than one webapp into appropriate subdirectories of
$CATALINA_BASE/shared/classes, or jar them up and put the jar into
$CATALINA_BASE/shared/lib.

> This allows the SOAP service to access public methods provided
> by my application. However, if I now try to access my application
> via the usual URL (http://my.host.com:8080/myapp), I get a 404
> error!
>
> The Tomcat log shows a somewhat cryptic stack trace:
>
> Oct 26, 2004 6:35:58 PM org.apache.catalina.startup.HostConfig deployDirectories
> SEVERE: Error deploying web application directory myapp
> java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
> at java.lang.ClassLoader.defineClass0(Native Method)
> at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
> at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
> 3)
> at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
> at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
> at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:289)

This is because the servlet API is not needed or included in Tomcat's
base classpath. You should not need to mess with catalina.sh; put your
classes and jars into the correct places and Tomcat will do the right
thing with them automagically.

> At this point, I'm completely stumped. Any idea of how to get
> SOAP and servlets to live together?

See above. For real reference information you would want to read some
of the Tomcat docs; a particularly relevant document (for Tomcat 4)
would be

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/class-loader-howto.html

> Should I ditch the whole ServiceManagerClient/ RPC router
> thing and just chisel the SOAP functionality into my classes?

That shouldn't be necessary.

> If this is not the best forum to ask this type of questions, could
> you please recommend some other place to go?

We get lots of questions here about web applications and related Java
technologies. Questions specific to particular server implementations
are sometimes referred to the support services of the purveyors of the
server, but otherwise we try to handle them.


John Bollinger
jobo...@indiana.edu

Bryan Castillo

unread,
Oct 28, 2004, 12:14:40 AM10/28/04
to
unix...@gmail.com (unixhack.blogspot.com) wrote in message news:<7d46b4f8.04102...@posting.google.com>...

> Hi,
>
> I'm trying to develop an application that uses SOAP and servlets.
> So far I have some servlets and JSP's running fine. They access
> the database, modify it, display data, etc.
>
> I want to add some SOAP functionality to the application using
> Apache SOAP, but so far I haven't had much luck. I am following
> the Apache SOAP docs and the Tomcat/SOAP instructions at:
>

I don't think that Apache SOAP has been updated for quite awhile and I
would reccomend you use Apache Axis. http://ws.apache.org/axis/

I was able to get Axis to work inside of a web app. It comes with a
web application, however you do need to download the JAF jar from sun
and put it into the webapps WEB-INF/lib directory. Once you get that
working its pretty easy to merge the stuff in the Axis WEB-INF/web.xml
into your own webapps web.xml. You have to copy the libs of course
and I think there is a file wsdd.config? (if you have already deployed
some services to the web-app)

For simple stuff services in Axis, check out the jws deployment (its
very cool).

unixhack.blogspot.com

unread,
Oct 30, 2004, 4:01:18 AM10/30/04
to
> I'm trying to develop an application that uses SOAP and servlets.
> So far I have some servlets and JSP's running fine. They access
> the database, modify it, display data, etc.

Thanks everybody for the responses!

-- E

0 new messages