Using Apache Axis in NetBeans 5.0

August 26, 2005 on 4:33 pm | In Java |

*Introduction*

I did not want to have to install Sun Java Application Server on my computer just to use web services. So, I looked around on the Internet and, from the information I gathered here and there, managed to put together this short tutorial on how to set up NetBeans projects to use Axis for web services.

*Server-side*

  1. Create a new web application project called *AxisTest*.
  2. Register the Axis JARs as a required library for the project.
  3. Add the following to web.xml.
    
    
    org.apache.axis.transport.http.AxisHTTPSessionListener
        
    
        
            AxisServlet
            
              org.apache.axis.transport.http.AxisServlet
            
        
    
        
            AdminServlet
            
              org.apache.axis.transport.http.AdminServlet
            
            100
        
    
        
            SOAPMonitorService
            
              org.apache.axis.monitor.SOAPMonitorService
            
            
    SOAPMonitorPort
    5001
            
            100
        
    
        
            AxisServlet
            /servlet/AxisServlet
        
    
        
            AxisServlet
            *.jws
        
    
        
            AxisServlet
            /services/*
        
    
        
            SOAPMonitorService
            /SOAPMonitor
                                                                                                                                                 
    
        
            AdminServlet
            /servlet/AdminServlet
        
    
        
            30
        
    
        
        
            wsdl
            text/xml
        
    
        
            xsd
            text/xml
        
    
        
            index.html
            index.jsp
            index.jws
        
  4. Write the service class.
    /*
     * HelloService.java
     *
     * Created on 26 August 2005, 15:57
     *
     * $Id$
     * $Log$
     */
    
    package test;
    
    /**
     *
     * @author Eddy.Young
     * @version $Revision$
     */
    public class HelloService {
    
        public String sayHello(String name) {
            return "Hello, " + name;
        }
    }
    

  5. Create .deploy.wsdd and .undeploy.wsdd files in /WEB-INF/.

    _WSStuff.deploy.wsdd_

    
    
    
        
    
        
    
        
        
    
    
            urn:test
        
    

    _WSStuff.undeploy.wsdd_

    
    
        
    
    
  6. Customise and add the following to build.xml.
    
    
    
    
    
    
    
        
    
    
    
    
    
    
    
    
         
    
         
    
        
            
        
    
        
            
    
            
    
    
    
            
    
            
    
        
    
        
            
    
    
    
            
    
            
    
            
        
    
  7. Build and deploy project.

*Client-side*

The service should now be available from *http://localhost:8088/AxisTest/services*.

  1. Create a new project.
  2. Register the Axis JARs as required library for the project.
  3. Customise and add the following to build.xml.
    
    
    
    
        
    
    
    
        
    
        
            
        
    
        
            
    
            
    
    
            
    
            
                
            
    
            
            
        
    
  4. Write client code.
    package clienttest;
    
    import test.*;
    
    public class Main {
        public static void main(String[] args) throws Exception {
            HelloServiceServiceLocator sl = new HelloServiceServiceLocator();
            HelloService service = sl.getHelloService();
            System.out.println(service.sayHello(args[0]));
        }
    }

Technorati Tags: ,

Related Posts:

33 Comments »

RSS feed for comments on this post.

  1. Thanks for this. Was really necessary for people who dont have the time (or bandwidth) to download the Sun Appserver bundle with netbeans

    Comment by Jennifer Mathew — 31 August 2005 #

  2. Why Axis create services source in folder accoring URL (localhost.axis.services.Version) and not in “test/” folder as in your example?

    Comment by ATom — 27 September 2005 #

  3. That’s just the way Axis works. I’m sure there is some option you can set to change this, but I have not looked into it.

    Comment by Eddy — 27 September 2005 #

  4. This is great!! thank you !!!
    Just a little suggestion when you are trying to use Netbeans 4.1, change the “build.classes” on axis classpath in build.xml into “build.classes.dir”.

    Thanks!!

    Comment by Andiwijaya — 28 September 2005 #

  5. I have big problem. I created own package and services class, modify your ant skript and when run it, get:

    Java2WSDL cz.atomsoft.bazartip.ws.Synchronization
    java.lang.ClassNotFoundException: cz.atomsoft.bazartip.ws.Synchronization

    But in build\web\WEB-INF\classes\cz\atomsoft\bazartip\ws\ exist compiled class Synchronization.class. How axis-java2wsdl has know where is this class?

    Comment by ATom — 28 September 2005 #

  6. Are you using 5.0 (ex-4.2) or 4.1? See the previous comment.

    Comment by Eddy — 28 September 2005 #

  7. I’m using 5.0 beta.

    Comment by ATom — 29 September 2005 #

  8. I solve it.
    build.classes.dir is right value also for Netbeans 5.0

    Comment by ATom — 29 September 2005 #

  9. If I want to just consume web services (build clients) is there anyway to get Netbeans to understand AXIS generated wsdl and do the appropriate things? When I follow the wsdl example with my own simple webservice it compiles OK but then there is some discconnect in the SOAP exchange because the test function for my getSquare() method (the only method in my simple test service) get’s this:

    unexpected element name: expected=getSquareReturn, actual={http://components.netbeans.howto}getSquareReturn

    for some reason what it expects isn’t qualified. The WSDL was generated by Macromedia ColdFusion which uses AXIS for web services. Any help greatly appreciated. I’d love to be able to use Matiisse to build GUI java apps that consume web services written in CF. It would be the best of both worlds.

    -dB

    Comment by Don — 7 October 2005 #

  10. I tried the example and when building it, I got the following error in NB 5.0 b2:
    build.xml:148: axis-admin failed with {http://schemas.xmlsoap.org/soap/envelope/}Server.userException java.net.ConnectException: Connection refused: connect

    I can’t figure out what’s happening.
    Thanks
    Nicolas

    Comment by Nicolas — 28 November 2005 #

  11. I got the same error.

    Comment by Tiago — 1 December 2005 #

  12. I got the same error.

    Processing file \AxisTest\web\WEB-INF\HelloService.undeploy.wsdd
    AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: java.net.ConnectException: Connection refused: connect

    Can anybody help us. I can’t fugure this one.

    Thanks
    Daz

    Comment by Daz — 12 January 2006 #

  13. Thanks for your comments, guys. I think this post has become obsolete with the release of NetBeans 5.0 RC1. The release candidate now supports web services for J2SE applications also and a J2EE container is no longer required. Hence, there is no longer a need for using Axis as the task of writing web services has been made even simpler.

    Daz: I think the error you’re reporting has to do with the connection. Please check through your web browser that you can access the .wsdl file. Maybe, it is protected by a password or the WS is no longer available.

    In any case, it is worth taking a look at NetBeans 5.0 RC1.

    Comment by Eddy — 12 January 2006 #

  14. Where is the HelloServiceServiceLocator class defined that is referenced in the client code?
    thanks

    Comment by Magnus — 18 January 2006 #

  15. It is generated by the Axis.

    Comment by Eddy — 18 January 2006 #

  16. I don’t understand what you mean by “has become obsolete with the release of NetBeans 5.0 RC1.” when the title of this post is “Using Apache Axis in NetBeans 5.0″…?

    Also NetBeans 5 still requires Sun Application Server to create web services with the built-in tool. I’m developing for Tomcat , so I still need Axis.

    Anyway, thanks for this tutorial!

    Comment by Andre — 9 February 2006 #

  17. I wrote this entry when NetBeans 5.0 was not yet available and this was the only good alternative to do web services.

    With NetBeans 5.0 the dependency on *any* application server for deploying/consuming web services has been removed. But it still requires that you download the correct library (which is available through the Update Centre.)

    Good luck!

    Comment by Eddy — 9 February 2006 #

  18. So it means we can generate web service clients for tomcat?

    I check the update center but was not able to find the required lib for tomcat.
    What should I download?

    Comment by Szabolcs — 16 February 2006 #

  19. Yes, you can because JAX-RPC is bundled with Tomcat 5.0. See the following as to how to go about deploying web services.

    Comment by Eddy — 16 February 2006 #

  20. I just tried netbeans 5.0 (linux). I have created a web app, using tomcat, when I try to create a web service client ( right click on project name, new web client ) , netbeans says “the current targer server for project does not support JAXRPC

    Comment by Szabolcs — 16 February 2006 #

  21. I just tried netbeans 5.0 (linux). I have created a web app, using the bundled tomcat, when I try to create a web service client ( right click on project name, new web client ) , netbeans says “the current targer server for project does not support JAXRPC so no web service clients can be created” :( No matter If I select J2EE container generated static stub stub or IDE-generated static stub. I could create a web service client for a Java Application but not for a Web application. The same method used for Java app, should also work for tomcat.
    By the way what do you mean : See the followings .. ?

    Comment by Szabolcs — 16 February 2006 #

  22. It should be able to create web services even for an application to be deployed to Tomcat. Did you select the JAX RPC as a library dependency in the project properties? If not, maybe that could be the problem. If you have, then I am afraid I have run out of ideas. I have not used the new bundled library, so I cannot really help. If all else fails, try the NetBeans community mailing lists; the guys there tend to be very helpful.

    Eddy

    Comment by Eddy — 16 February 2006 #

  23. Yes i did select the jax-rpx. According to this post It is not supposed to work at all:(

    http://www.netbeans.org/servlets/ReadMsg?list=nbusers&msgNo=64059

    Comment by Szabolcs — 16 February 2006 #

  24. That post does include a link to a KB article about how to do web services in web application with NetBeans 5.0.

    http://www.netbeans.org/kb/50/jaxws20.html

    If that does not work, I’m afraid you’ll have to ask help from the mailing list. Or, you could e-mail the Geertjan who will be happy to help, I’m sure.

    Good luck!

    Comment by Eddy — 16 February 2006 #

  25. Hi,

    Is this the same procdure used for consuming a webservice.
    I want to consume a webserivce. I have Netbeans installed on my machine.

    Is this the procedure I have to follow.

    Thanks and regards,

    Fasil.ak

    Comment by Fasil — 16 June 2006 #

  26. Fasil,

    Yes, this is the procedure that needs to be followed for consuming web services. But you may want to check out the new NetBeans documentation as support for working with WS has been improved.

    Regards,
    Eddy

    Comment by Eddy — 16 June 2006 #

  27. Hi,
    I’d deeply appreciate any hint on the problem I have, described below:

    Problem: I have a web service, deployed on Tom cat on FreeBSD, which tests OK using the test interface on Tomcat. I can also invoke the web service method successfully through a test Java prog, if compiled using javac on CLI.
    Problem: The test client I developed in NetBeans is generating a strange exception when compiling the code: The WS method takes the following data types as parameteres:
    String
    String
    String[]
    String[]
    String[]

    The compiler rejects the parameters in the invokation and requires the object type: javax.xml.soap.SOAPElement
    Here is the error:

    myWSmethod(javax.xml.soap.SOAPElement) in examples.myWSComponent cannot be applied to
    (java.lang.String,java.lang.String,java.lang.String[],java.lang.String[],java.lang.String[])

    I’ve included the AXIS and other jar files I successfully used in the CLI test in the NetBeans libraray and added the library tot he Project. And the Test Operation utility runs OK on the web service methods inside the project web references. NetBeans in ver 5.5, JDK 1.5. And all are services are running locally on the same machine.

    Could you tell me what I’m missing?

    Thanks

    Saeed

    Comment by Saeed — 10 August 2006 #

  28. Unfortunately, it is difficult to provide a solution without looking at the actual code.

    Comment by Eddy — 10 August 2006 #

  29. I tried to follow the instructions using NetBeans 5.0 and when compiling the server I got the following error:

    - Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
    Java2WSDL test.HelloService
    java.lang.ClassNotFoundException: test.HelloService
    at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1166)
    at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1107)
    at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:977)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at org.apache.tools.ant.AntClassLoader.findBaseClass(AntClassLoader.java:1197)
    at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:990)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at org.apache.axis.utils.ClassUtils$2.run(ClassUtils.java:187)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.axis.utils.ClassUtils.loadClass(ClassUtils.java:160)
    at org.apache.axis.utils.ClassUtils.forName(ClassUtils.java:100)
    at org.apache.axis.wsdl.fromJava.Emitter.setCls(Emitter.java:2079)
    at org.apache.axis.tools.ant.wsdl.Java2WsdlAntTask.execute(Java2WsdlAntTask.java:188)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
    at org.apache.tools.ant.Task.perform(Task.java:364)
    at org.apache.tools.ant.Target.execute(Target.java:341)
    at org.apache.tools.ant.Target.performTasks(Target.java:369)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
    at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:234)
    at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:287)
    at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:125)
    T:\MyProject\AxisTest\build.xml:130: Error while running org.apache.axis.tools.ant.wsdl.Java2WsdlAntTask
    BUILD FAILED (total time: 2 seconds)

    Comment by Peter V — 11 August 2006 #

  30. Peter,

    It looks like you don’t have the required Java Activation Framework in your classpath. The Apache Axis website has more details about how to get that JAR.

    Good luck.

    Eddy

    Comment by Eddy — 11 August 2006 #

  31. what version of tomcat are you guys using? I hvae the bundle tomcat with netbeans ide 5.0, tomcat 5.0, and tomcat 5.5 (latest).

    Using tomcat 5.5 or the bundle one - i get an error saying my server does not support JAXRPC. (i added libraries of whatever in the axis/lib folder to the project.

    using 5.0 tomcat (which i got from the sun jwsdp), i can add web services, but it complained “JSR-109 is only supported with J2EE 1.4.)

    If i look what version of 1.4 i have the server set to — all fo them says 1.4..

    wtf?!

    Comment by tak — 24 August 2006 #

  32. Tak,

    Notice that this post explains how to use build.xml and Apache Axis to deploy and consume web services, and does not use the features built in NetBeans for web services.

    Eddy

    Comment by Eddy — 24 August 2006 #

  33. I tried to follow the instructions using NetBeans 5.0 and when compiling the server I got the following error:

    - Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
    Java2WSDL test.HelloService
    java.lang.ClassNotFoundException: test.HelloService
    at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1166)
    at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1107)
    at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:977)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at org.apache.tools.ant.AntClassLoader.findBaseClass(AntClassLoader.java:1197)
    at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:990)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at org.apache.axis.utils.ClassUtils$2.run(ClassUtils.java:187)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.axis.utils.ClassUtils.loadClass(ClassUtils.java:160)
    at org.apache.axis.utils.ClassUtils.forName(ClassUtils.java:100)
    at org.apache.axis.wsdl.fromJava.Emitter.setCls(Emitter.java:2079)
    at org.apache.axis.tools.ant.wsdl.Java2WsdlAntTask.execute(Java2WsdlAntTask.java:188)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
    at org.apache.tools.ant.Task.perform(Task.java:364)
    at org.apache.tools.ant.Target.execute(Target.java:341)
    at org.apache.tools.ant.Target.performTasks(Target.java:369)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
    at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:234)
    at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:287)
    at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:125)

    C:\AxisTest\build.xml:102: Error while running org.apache.axis.tools.ant.wsdl.Java2WsdlAntTask

    I’ve added activation framework in my classpath using the following command and akso in libraries of the project.

    set classpath = %classpath%;c:activation.jar

    i’m also trying to build the server side using command prompt but same error is occuring.

    Comment by israr — 10 September 2006 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>





Powered by blog.mu with Pool theme design by Borja Fernandez.