Webservice n00b needs Axis assistance.
April 19, 2006 7:01 PM   Subscribe

So I'm trying to implement a webservice for a class project using Apache Axis, and I'm having some weird classpath (I think) issues.

The problem is as follows: I've written a servlet which runs fine by itself, and I'm wanting to implement it as a full-on webservice. The code compiles fine, the WSDL generated fine (a few minor warnings, but nothing that looks bad), but when I try to run WSDL2Java to generate the code:

java org.apache.axis.wsdl.WSDL2Java -o . -dSession -s -Strue -Nurn:phonebook phonebook phonebook.wsdl

I get this:

java.io.IOException: Type {http://http.servlet.javax}HttpServletResponse is referenced but not defined.
at org.apache.axis.wsdl.symbolTable.SymbolTable.checkForUndefined(SymbolTable.java:665)
at org.apache.axis.wsdl.symbolTable.SymbolTable.add(SymbolTable.java:545)
at org.apache.axis.wsdl.symbolTable.SymbolTable.populate(SymbolTable.java:518)
at org.apache.axis.wsdl.symbolTable.SymbolTable.populate(SymbolTable.java:495)
at org.apache.axis.wsdl.gen.Parser$WSDLRunnable.run(Parser.java:361)
at java.lang.Thread.run(Thread.java:595)


Here's the classpath (it's messy, because I've been fucking about with it, trying to make it work):

.:/home/cpsc4373:/usr/tomcat/webapps/examples/WEB-INF/classes:/home/cpsc4373/axis-1_3/lib/axis.jar:/commin/lib/saaj.jar:
/home/cpsc4373/axis-1_3/lib/commons-logging-1.0.4.jar:/home/cpsc4373/axis-1_3/lib/commons-discovery-0.2.jar:
/home/cpsc4373/axis-1_3/lib/wsdl4j-1.5.1.jar:/usr/tomcat/WEB-INF/lib/servlet.jar:/home/cpsc4373/axis-1_3/compile:
/home/cpsc4373/axis-1_3/samples/userguide/example6:/usr/tomcat/common/lib/:/usr/tomcat/common/lib/javax/servlet/http/:
/home/cpsc4373/axis-1_3/compile/phonebook

Which leaves me smack in the middle of WTFistan. Not to mention that Googling the first line of the error message turns up precisely zero responses. Which is the internet's way of saying STFU NOOB, I know. But this is for a project grade, and the damn thing gotta work.

Background: This is on a RedHat Linux server, using the latest Java, Axis (not Axis2), Tomcat, and MySQL. I'm hell and gone from being a Linux admin, but one of my counterparts is fairly well-versed. I know how to do basic command line stuff and edit a .bash_profile, not terribly much more than that.
posted by middleclasstool to Computers & Internet (6 answers total)
 
What are the warnings? You really shouldn't be getting warnings?

An are you trying to expose the doGet() or doPost() methods as web services? This isn't what is usually done in the Java space as far as web services go. Typically people write some standalone class that has some business logic in it and then use Axis' tools to generate WSDL and to generate the config files needed to install the web service into the Axis runtime environment.
posted by mmascolino at 7:59 PM on April 19, 2006


Looks like a classpath problem. The "WEB-INF/lib/servlet.jar" line looks suspect to me. If you're using Tomcat 5 (and possibly earlier versions but I don't have any of those installed) try changing /usr/tomcat/WEB-INF/lib/servlet.jar to /usr/tomcat/common/lib/servlet-api.jar.
posted by mragreeable at 8:26 PM on April 19, 2006


One other thing : I know you've read this and know this, but merely adding a directory to the classpath does not add all the jars on the classpath. Adding a directory means that it's expecting to find .class files in the proper package naming structure on the disk. Unless you've manually unzipped those jars they won't be there. I'd remove "/usr/tomcat/common/lib/:/usr/tomcat/common/lib/javax/servlet/http/" from your classpath - they're almost certainly not helping anything.

It's a weird distinction, and one that sometimes seemes especially unclear because all jar files in a war file's lib directory do get added to the classpath. When people see those jar files magically being placed on the classpath they assume, not unreasonably, that that is standard java classloader behavior. But it's not.

Anyways, every new java developer struggles with the classpath stuff for a couple of weeks and then one day look back and wonder why you found it so hard at first. It's just different than how most other languages deal with libraries, and takes some getting used to.
posted by mragreeable at 8:41 PM on April 19, 2006


Response by poster: Here are the warnings when I generated WSDL:

WARNING: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
Apr 19, 2006 5:53:28 PM org.apache.axis.wsdl.fromJava.Types isBeanCompatible
WARNING: The class javax.servlet.http.HttpServletRequest is defined in a java or javax package and cannot be converted into an xml schema type. An xml a anyType will be used to define this class in the wsdl file.
Apr 19, 2006 5:53:28 PM org.apache.axis.wsdl.fromJava.Types isBeanCompatible
WARNING: The class javax.servlet.http.HttpServletResponse is defined in a java or javax package and cannot be converted into an xml schema type. An xmlma anyType will be used to define this class in the wsdl file.


EDIT: Now that I read the warnings more closely, I see that's the problem, isn't it? I passed over them because of the mail.internet.MimeMultipart thing, which we saw when we set up Axis -- the setup test claimed it was optional and would generate some error messages. And now when I go back to check the test page, I see XML security isn't working. I'll have to look into that.

I do in fact have doGet and doPost coded into my program, as well as all of the relevant HTML. It's written as an independent servlet that you can run directly from Tomcat, but the project goal is to deploy it as a full webservice with SOAP, WSDL, UDDI, and all the trimmings. So I should recode this as a standalone with a main method and no html at all? If so, how do I handle the input?

Details: The backend app is simple. User inputs first/last name, service queries MySQL db and spits out phone number. Once we've got that running, we want to add login/password authentication.

We've got two weeks to finish coding, testing, and compile all the paperwork. So I am currently sitting in poo.

mragreeable: When I check the path manually, it is indeed listed as servlet.jar and not servlet-api.jar. And yeah, I know about naming the jar files specifically, but we've had some funky compilation issues where code wouldn't compile, and out of desperation I tried unpacking the jar files and just pointing to the relevant directory. As I said, the classpath's messy.
posted by middleclasstool at 9:13 PM on April 19, 2006


One other thing : I know you've read this and know this, but merely adding a directory to the classpath does not add all the jars on the classpath.

This little nuissance of a problem has bitten me in the ass more than once (why bother allowing directory includes, then?!) and I suggest mragreeable is on the right track.
posted by Civil_Disobedient at 11:03 PM on April 19, 2006


I suggest a standalone class that implements the functionality that you want and then you can use that class from inside the servlet or a class with a main method. I think you are going to have bad results with trying to use a HttpServletRequest and a HttpServletResponse as parameters to a web service call.
posted by mmascolino at 5:29 AM on April 20, 2006


« Older J'adore l'amour et le soup de jour.   |   Filemaker Automation/Scripting Newer »
This thread is closed to new comments.