Hello World with Apache Axis2

This is a step by step guide by Ruchith Ferenando to hosting a simple Web service with Apache Axis2 and interacting with that service using a client based on generated code.

Date: Mon, 29th May, 2006
Level:
Reads: 102212 Comments: 53 | Login or register to post comments
Ruchith Fernando
Software Engineer
WSO2 Inc.

We will start with a simple Java class which will be turned into a service with the necessary packaging. Next a client will be created using the code generated by the WSDL2Java code which will be used to invoke the service we created. You will have to download Apache Axis2-Nightly build Satandard Binary Distribution to try this out and the source code of both client and service are available here. Now simply follow the steps below.

Step 1: A simple Java class

First we need a Web service and an operation in that service for a client to invoke. Lets develop a Web service with an operation which will echo a string value. The simplest way to do this is with a Java class as shown below:
/**
* The service implementation class
*/
public class SimpleService {

/**
* The echo method which will be exposed as the
* echo operation of the web service
*/
public String echo(String value) {
return value;
}
}
---------------------------------------------------------------
save as - SimpleService.java
---------------------------------------------------------------

Step 2: The service descriptor

Each Axis2 service must have a services.xml file which will inform Axis2 about the service. Following is the services.xml file contents for the SimpleService Web service.
<service>
<parameter name="ServiceClass"
locked="false">SimpleService</parameter>
<operation name="echo">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</operation>
</service>
The "service" element encapsulates the information about a single service. Within the "service" element there should be a parameter specifying the service implementation Java class. The parameter is specified as a "parameter" element as shown below.
<parameter name="ServiceClass" locked="false">SimpleService</parameter>
The second child element of the "service" element "operation" element describes the operation and the message receiver that is to be used for that operation. For this service we set the "name" attribute of the "operation" element to the name of the method that we wish to expose as a Web service operation. Hence we set it to "echo":
<operation name="echo">
Axis2 provides a MessageReceiver based on Java reflection and the "messageReceiver" element declaring that org.apache.axis2.rpc.receivers.RPCMessageReceiver should be used.
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>

Step 3: Packaging the service

Axis2 expects services to be packaged according to a certain format. The package must be a .jar file with the compiled Java classes and a META-INF directory which will hold the services.xml file. The jar file can be name .aar to distinguish it as an Axis2 service archive. It's important to note that the part of the file name before ".aar" is the service name. Create a temp directory in the same location where the SimpleService.java file exists
[Linux]
mkdir temp

[Windows]
md temp
Now compile the SimpleService.java class and move the SimpleService.class file to the temp directory.
javac SimpleService.java -d temp/
Create a META-INF directory within the "temp" directory and copy the service.xml file into the META-INF directory. Change directory to the "temp" directory and use the "jar" command as follows to create the service archive named SimpleService.aar.
jar -cvf SimpleService.aar *

Step 4: Hosting the service

There are a number of ways to host the service that was created in the previous step. The two main methods are:
  • Using the SimpleHTTPServer that is available in the Apache Axis2 distribution
  • Using Axis2 with Tomcat

This tutorial will use the org.apache.axis2.transport.http.SimpleHTTPServer to host the SimpleService.aar Axis2 service archives are placed in a directory named "services" in a repository directory. The structure of an example repository directory is shown below.


Now create the my-axis2-repo directory structure and copy the SimpleService.aar file into the "services" directory. This example does not require the axis2.xml to be available in the "conf" directory. Now we have to start the SimpleHTTPserver using the above my-axis2-repo directory as the repository directory. The axis2-std-SNAPSHOT-bin distribution comes with a "bin" directory which contains a Linux shell script and a Windows batch file to start the SimpleHTTPServer: http-server.sh and http-server.bat Start the server pointing to my-axis2-repo directory:

[Linux]
sh http-server.sh /path/to/my-axis2-repo

[Windows]
http-server.bat drive:\path\to\my-axis2-repo
The following output will be shown in the console:
[SimpleHTTPServer] Starting
[SimpleHTTPServer] Using the Axis2 Repository /home/ruchith/Desktop/
ibm-workshop/axis2-repo
[SimpleHTTPServer] Listening on port 8080
[JAM] Warning: You are running under a pre-1.5 JDK.
JSR175-style source annotations will not be available
[SimpleHTTPServer] Started
Now when we point a browser to http://localhost:8080/ the SimpleHTTPServer will respond with a list of available services and the SimpleService will be listed there.

Step 5: Accessing the service with a generated client

Now lets use the WSDL2Java tool generate the client side stubs to interact with the service.
[Linux]
$ sh WSDL2Java.sh -uri http://localhost:8080/axis2/services/
SimpleService?wsdl -o /path/to/my/client/code/

[Windows]
WSDL2Java.bat -uri http://localhost:8080/axis2/services/
SimpleService?wsdl -o /path/to/my/client/code/
This generates two .java files and we will be using the org.apache.axis2.SimpleServiceStub to invoke the "echo" operation of the service. Now lets create a new Client.java class which uses the org.apache.axis2.SimpleServiceStub. For simplicity lets create the Client.java file in the same package as the generated code (i.e.org.apache.axis) and save it along with the other generated code.
package org.apache.axis2;

import org.apache.axis2.SimpleServiceStub.EchoResponse;

public class Client {

public static void main(String[] args) throws Exception {

SimpleServiceStub stub = new SimpleServiceStub();

//Create the request
SimpleServiceStub.Echo request = new SimpleServiceStub.Echo();
request.setParam0("Hello world");

//Invoke the service
EchoResponse response = stub.echo(request);

System.out.println("Response : " + response.get_return());
}

}
----------------------------------------------------------------
save as - Client.java
----------------------------------------------------------------

Now to we can compile and run the client code. Its is important to note that the classpath must have all the jars in the "lib" directory of the axis2-std-1.0-RC1-bin distribution when compiling and running the client.

The following command will compile the client's source to a "temp" directory

$ javac -extdirs /path/to/axis2-RC1-std-bin/lib/ org/apache/axis2/*.java  -d temp/

We can run the client program as shown below from the "temp" directory:

$ java -Djava.ext.dirs=/path/to/axis2-RC1-std-bin/lib/ org.apache.axis2.Client

The output will be :

Response : Hello world

Step 6: Monitoring the messages

To view the request and response SOAP messages we can use the tcpmon tool. We can start the SimpleHTTPServer on port 9090 and make the tcpmon listen on port 8080 and forward the requests to port 9090. Using "-p9090" as an additional argument in starting the SimpleHTTPServer we can start it on port 9090. Example:
sh http-server.sh /path/to/my-axis2-repo -p9090

Now when we run the client once again we can view the messages.


Conclusion

This example is the most simple example one can use to start using Axis2. I hope this will be a starting point for you to explore more and more about Apache Axis2. If you have any questions please feel free to mail the axis-user mailing list, with [Axis2] as the subject prefix.

Author

Ruchith Fernando, Senior Software Engineer, WSO2 Inc. ruchith @ wso2
xrimatapolla.gmail.com's picture

Thanks Fernando,you save me a

Thanks Fernando,you save me a lot of time with your help!Good work from you. online casino
mattei.oca.eu's picture

client with axis2-1.5.3

in the step 5, i find that some argument name differ with the axis 2 version i use (axis2-1.5.3): the method use to set the argument parameter is not setParam0 but setArgs0 to be the same as in the SimpleServiceStub.java, so the code of the Client.java should now looks like this: package org.apache.ws.axis2; import org.apache.ws.axis2.SimpleServiceStub.EchoResponse; public class Client { public static void main(String[] args) throws Exception { SimpleServiceStub stub = new SimpleServiceStub(); //Create the request SimpleServiceStub.Echo request = new SimpleServiceStub.Echo(); //request.setParam0("Hello world"); request.setArgs0("Hello world"); //Invoke the service EchoResponse response = stub.echo(request); System.out.println("Response : " + response.get_return()); } }
amilaj.wso2.com's picture

Some issues when running with axis2-1.5

I found this really useful. Thank you Ruchith. But i ran into few issues when experimenting this tutorial with axis2-1.5. This is mainly due to an additional package added. The client code will not work as it is, due to this change. wsdl2java.sh will generate client code with following package - org.apache.ws.axis2. Note: "ws" is a newly added package level. (Earlier it was org.apache.axis2) Therefore now we need to write client within this package. Also we need to import stub using this new package name. E.g:- package org.apache.ws.axis2; import org.apache.ws.axis2.SimpleServiceStub.EchoResponse; public class Client { public static void main(String[] args) throws Exception { //(As same as above code) .... .... } } Also when running the client you need to add this new package level. So the command would look like, java -Djava.ext.dirs=$AXIS2_HOME/lib/ org.apache.ws.axis2.Client
christin7007.gmail.com's picture

Thanks

Great! Thanks for the great informative post and your effort. I think the above article is valuable for all concerned people. For me the Informations are really really useful. I've Bookmarked this page for future reference. Thank you Robin Jokes
Denis.fife.yahoo.com's picture

I am using the complete

I am using the complete version of Axis2 and includes samples and convenient scripts as well.This contains all the documentation in one package. The package includes the xdocs and the Java API docs of this project. But i am having problem with the following commands. %AXIS2_HOME%\bin\axis2server.bat (Windows) $AXIS2_HOME/bin/axis2server.sh (Unix) Thank you so much for nice tutorial and great information.
Denis.fife.yahoo.com's picture

I am using the complete

I am using the complete version of Axis2 and includes samples and convenient scripts as well.This contains all the documentation in one package. The package includes the xdocs and the Java API docs of this project. But i am having problem with the following commands. %AXIS2_HOME%\bin\axis2server.bat (Windows) $AXIS2_HOME/bin/axis2server.sh (Unix) Thank you so much for nice tutorial and great information. finger pulse oximeter
halloween's picture

Javac cannot find source files

Hey guys. I can't seem to compile things with: javac -extdirs /path/to/axis2-RC1-std-bin/lib/ org/apache/axis2/*.java -d temp/ i'm getting a "javac: cannot find source files" error. Any ideas? I'm pretty sure the paths are correct...
halloween's picture

Solved.

Nevermind, my bad :)
rjassal's picture

Broken link

Hi, Link to download Apache Axis2 distribution is broken (http://people.apache.org/dist/axis2/nightly/axis2-SNAPSHOT.zip), can you please fix this. Thanks, Ravi.
halloween's picture

old but nonetheless

It's been a month after your question, should i doubt it will be of any use but here's the link anyway. http://ws.apache.org/axis2/download/1_5/download.cgi Cheers
suri's picture

HelloWorld with Axis

Hi, I got stucked at 4th point itself. When I execute the axis2server.bat file, It is saying that, the JAVA_HOME environment variable is not set properly. But I have set the enviormant variables properly. I've set the Jar files directory in CLASS_PATH as well. Meanwhile, I have a doubt that, You've mentioned http-server.bat. But I couldn't found the file in the nightly build repository. Instead I've Axis2.bat and axis2server.bat. Please help me out in this.
nhoa8's picture

Problems with creating stubs

Hello!! First sorry about my English I'm trying to create the stubs for my web service in Eclipse with ant --> generate.stubs But I obtain this: [ java] org.apache.axis2.wsdl.codegen.CodeGenerationException: Error parsing WSDLjava] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:194)java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:747)java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:201)java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:104)java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)java] at java.lang.reflect.Method.invoke(Unknown Source)java] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)java] at org.apache.tools.ant.Task.perform(Task.java:348)java] at org.apache.tools.ant.Target.execute(Target.java:357)java] at org.apache.tools.ant.Target.performTasks(Target.java:385)java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)java] at org.apache.tools.ant.Project.executeTarget(Project.java:1298)java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)java] at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)java] at org.apache.tools.ant.Project.executeTargets(Project.java:1181)java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)java] Caused by: org.apache.axis2.wsdl.codegen.CodeGenerationException: Error parsing WSDLjava] at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:150)java] at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)java] at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)java] at java.lang.reflect.Method.invoke(Unknown Source)java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)java] ... 19 morejava] Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=INVALID_WSDL: IO Error: java.io.FileNotFoundException: http://localhost:8080/axis2/services/OdolplanWebService?wsdljava] at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.readInTheWSDLFile(CodeGenerationEngine.java:297)java] at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:105)java] ... 27 morejava] Caused by: java.io.FileNotFoundException: http://localhost:8080/axis2/services/OdolplanWebService?wsdljava] at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)java] at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)java] at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)java] at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)java] at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)java] at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)java] at org.apache.axis2.util.XMLUtils.newDocument(XMLUtils.java:205)java] at org.apache.axis2.util.XMLUtils.newDocument(XMLUtils.java:250)java] at org.apache.axis2.util.XMLUtils.newDocument(XMLUtils.java:233)java] at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.readInTheWSDLFile(CodeGenerationEngine.java:285)java] ... 28 morejava] --- Nested Exception ---java] org.apache.axis2.wsdl.codegen.CodeGenerationException: Error parsing WSDLjava] at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:150)java] at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)java] at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)java] at java.lang.reflect.Method.invoke(Unknown Source)java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:747)java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:201)java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:104)java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)java] at java.lang.reflect.Method.invoke(Unknown Source)java] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)java] at org.apache.tools.ant.Task.perform(Task.java:348)java] at org.apache.tools.ant.Target.execute(Target.java:357)java] at org.apache.tools.ant.Target.performTasks(Target.java:385)java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)java] at org.apache.tools.ant.Project.executeTarget(Project.java:1298)java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)java] at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)java] at org.apache.tools.ant.Project.executeTargets(Project.java:1181)java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)java] Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=INVALID_WSDL: IO Error: java.io.FileNotFoundException: http://localhost:8080/axis2/services/OdolplanWebService?wsdljava] at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.readInTheWSDLFile(CodeGenerationEngine.java:297)java] at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:105)java] ... 27 morejava] Caused by: java.io.FileNotFoundException: http://localhost:8080/axis2/services/OdolplanWebService?wsdljava] at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)java] at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)java] at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)java] at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)java] at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)java] at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)java] at org.apache.axis2.util.XMLUtils.newDocument(XMLUtils.java:205)java] at org.apache.axis2.util.XMLUtils.newDocument(XMLUtils.java:250)java] at org.apache.axis2.util.XMLUtils.newDocument(XMLUtils.java:233)java] at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.readInTheWSDLFile(CodeGenerationEngine.java:285)java] ... 28 more BUILD SUCCESSFUL Total time: 7 seconds I have already verify my classpath and all the software that it requires works perfect with another web services thas I'm trying (another examples) so I don't think what could be the problem. I'm losin a lot of hours on this, I need help   :(      Thankss!! [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [
svaens's picture

problem with client code

Hi,   I did pretty much the same thing as suggested on this website, except I am using the SimpleHTTPServer. At least, viewing my service on a browser works! What I have a problem with is creating my own client code that successfully connects and retrieves data from this server.   here is my server:   public class EmbeddedAxis2Server { public static void main(String[] args) throws Exception { ConfigurationContext context = ConfigurationContextFactory. createConfigurationContextFromFileSystem(null, null); AxisService service = AxisService.createService(caps.integration.rhos.dk.schema.astraiaservice._2008._04._15.PersonInfo.class.getName(), context.getAxisConfiguration()); context.getAxisConfiguration().addService(service); SimpleHTTPServer server = new SimpleHTTPServer(context, 8888); server.start(); }}   It seems to work fine.... The only thing that points out to me as being MAYBE not fine, is the fact that when I put in the URL that is specified in my wsdl: http://localhost:8888/services/PersonInfo it is automatically redirected to http://localhost:8888/axis2/services/ But it does seem to show me the correct information on the web page that appears: Deployed services PersonInfo Available operations getPersonInfo   HOWEVER!! :( When I attempt to connect to it using a coded client (using generated code created via wsdk2java tool) I get the following exception: org.apache.axis2.AxisFault: The service cannot be found for the endpoint reference (EPR) 127.0.0.1/services/PersonInfo  at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:486) at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:343) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:389) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:211) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163) at caps.integration.rhos.dk.schema.astraiaservice._2008._04._15.PersonInfoStub.getPersonInfo(PersonInfoStub.java:142) at com.astraia.axisclient.Client.getPersonInfo(Client.java:44) at com.astraia.axisclient.Client.main(Client.java:23) The client code is short and simple: public static void getPersonInfo(){ try { ConfigurationContext context = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null); PersonInfoStub stub =new PersonInfoStub(context);  GetPersonInfoIn req =new GetPersonInfoIn(); req.setCivilRegistrationIdentifier("CIV123"); req.setHospitalCode("HOS123"); req.setRequestId("123"); req.setUserName("sean"); GetPersonInfoOut res = stub.getPersonInfo(req); System.out.println(res.toString());  } catch(Exception e){ e.printStackTrace(); System.out.println("\n\n\n"); } }     Anyone got any idea what I am doing wrong? Does anything stick out as a possible cause? I am kinda stumped! :(    
eliassal's picture

Using the tutorial with Tomcat5.5

I saw one post indicating doing the tutorial with Tomcat and not Apache. Can you please send me the steps to do it, thanks in advance
ayessa's picture

POJO File Access

Hi,     I'm having difficulties reading from my configuration file  "properties\System.properties"... I placed the "properties" directory in CATALINA_HOME and my web service is unable to read it; although it works for plain JSP.   Am i missing something here? should i place my "properties" directory somewhere else? regards, ayessa 
amanjsingh's picture

Strangely...

I know nothing about SimpleHTTPServer. Anyone ready to show the light please?
anilchukkapalli's picture

Solution to Problems Using Tomcat

Hi, I am using Tomcat 5.5 to deploy the web service. I was unable to do so with the existing services.xml so i had to add "HelloWorld" before parameter name = service class, then it works. Thanks Anil
eliassal's picture

did you manage to do it

I saw your post and interested to see if you got it working Tomcat and not Apache. Can you please send me the steps to do it, thanks in advance
footballsoccerpainting's picture

Anonymous internal server error inside Axis2

Axis2 1.1.1 is failing to answer a request due to an internal server error. Even trace level logging only shows this:6038 [HttpConnection-8080-1] DEBUG org.apache.axis2.handlers.addressing.AddressingHandler - Addressing is disabled .....6038 [HttpConnection-8080-1] DEBUG org.apache.axis2.engine.Phase - Checking post-conditions for phase "MessageOut"6050 [HttpConnection-8080-1] DEBUG org.apache.axiom.om.util.StAXUtils - XMLStreamWriter is com.ctc.wstx.sw.SimpleNsStreamWriter6055 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.wire - << HTTP/1.1 500 Internal server error6055 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.wire - << Date: Fri, 02 Mar 2007 15:29:44 GMT6055 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.wire - << Server: Simple-Server/1.16055 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.wire - << Content-Length: 2926055 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.wire - << Content-Type: text/xml; charset=UTF-86055 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.wire - << Connection: Close6056 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.DefaultHttpServiceProcessor - Response sent6056 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.DefaultHttpConnectionManager - org.apache.axis2.transport.http.server.DefaultHttpServiceProcessor@d1b44b terminated I can get the WSDL for this service (a duplicate of the echo service) and the autogenerated stubs seem to work fine. Something bad is happening in the server, but I don't have any details :(
rrvkumar's picture

Unable to run the Code from the command Line

Hi ... Me a newBie to web service ... i got the SimpleService code downlaoded along with the Client,Created sepearte java files related to the SimpleService using the wsdl and the url path ,deployed teh service sucessfuly as service in the Tomcat and gave run the clinet from the Eclipse after loading all teh relavent jar files in the Build path . Now the problem here is when i run from the Eclipse i get the Hello Worl problem,but the when i trying to run it from the command line by going to the bin folder of axis and then using the tool axis2 and the <Client> as the java program iam getting different errors from stub .... to classnot found exception . How can i include so many jar files in my classpath to execute the program.Any immediate help appreciated ...    
rjminsha's picture

Using nightly build - SimpleServiceStub issues

I am using the following build Apache Axis2 SNAPSHOT build (September 13, 2006) When I generate the client code using WSDL2Java.bat -uri http://localhost:8080/axis2/services/SimpleService?wsdl -o c:\working\simpleWs\client\code The stub does not have the inner Echo class resulting in compile errors as described below: org/apache/ws/axis2/Client.java:3: cannot find symbol symbol : class EchoResponse location: class org.apache.ws.axis2.SimpleServiceStub import org.apache.ws.axis2.SimpleServiceStub.EchoResponse; Has this issue been resolved ? Is there something I ma missing here ? thanks, Robbie
krahd's picture

Echo Static Class not generated

Hi all. As some had already pointed out, Axis2 does not generate the static class (for the stub) from the WSDL. I'm experiencing that problem with both Axis2 1.0 and the latest (nightly)version... but I can't figure out when it does work and when it doesn't. Any clues? I've deployed two WS (the one from you tut and one made by a coworker) that are basically the same... but only one works (and it does so seamlessly..!) Any advice would be greatly appreciated. tom
krahd's picture

.

Just to say that by using the latest nightly build I got the example running, but having to change setParam0 to setMessage. hth, tom
paulyang9988.yahoo.com's picture

setMessage still doesn't do it.

Hi tom, I changed setParam0 to setMessage, but it still doesn't quite work for me. I'm using axis2 1.5.1. Any idea? Thanks. Paul
paulyang9988.yahoo.com's picture

setParam0 should be changed to setArgs0

with this change, Client.java compiles. I'm using axis2 1.5.1.
nauda01's picture

wsdl problems

After building the .aar file and moving it under the axis2/WEB-INF/services directory, the service seems to deploy correctly as i can view the services via IE Browser. However when you try to view the WSDL I get the error - Unable to generate WSDL for this service Either user has not dropped the wsdl into META-INF or operations use message receivers other than RPC. Since i followed the example, I have no deployed wsdl file but the services.xml file uses the messageReceiver class="org.apache.axis2.rpc.receivers.RPCInOutAsyncMessageReceiver" I tried one of the sample services MyService and got the exact Error. Something i discovered is that with the 1.0 war file the wsdl gets displayed when i click on the service name from the services displayed in a browser. With the nightly distribution war file 23 july the above error occurs. When i then try to generated the stub code via wsdl2java, the request/response inner classes dont generate which i believe is a known problem. Question is how can i get things to work where i can get the wsdl is automatically generated and the proper stub classes are also generated? Thoughts?
ruchith's picture

Re: wsdl problems

Hi, Do you still have this problem of not being about to generate the WSDL in the case of the nightly build? If so please file a JIRA bug : https://issues.apache.org/jira/browse/AXIS2 Thanks, Ruchith
daydreaming's picture

Need REST client example code

Hi there, Thank you for your good article. However, I would like to ask you help to provide the example code of REST client. I myself have tried to use the example from apache axis2 website, but always got the error message after running the REST client. Thank you for any response in advance. ---------------------------------------------------------------------- public class RESTClient { private static String toEpr = "http://localhost:8122/AxisWeb/rest/SimpleService/echo"; public static void main(String[] args) throws AxisFault { Options options = new Options(); options.setTo(new EndpointReference(toEpr)); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); //options.setProperty(Constants.Configuration.ENABLE_REST,Constants.VALUE_TRUE); options.setProperty(Constants.Configuration.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_GET); ServiceClient client = new ServiceClient(); client.setOptions(options); OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace("http:///xsd", "http:///xsd"); OMElement method = fac.createOMElement("echo", omNs); OMElement value = fac.createOMElement("Text", omNs); value.addChild(fac.createOMText(value, "Axis2 Echo String ")); method.addChild(value); OMElement result= client.sendReceive(method); try { XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out); result.serialize(writer); writer.flush(); } catch (XMLStreamException e) { e.printStackTrace(); } catch (FactoryConfigurationError e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }
akkachotu's picture

error while running the client program

When I run the client program Client.java I am getting below error on the client side? Any thoughts? Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: Unexpected subelement return at org.apache.ws.axis2.SimpleServiceStub.fromOM(SimpleServiceStub.java:826) at org.apache.ws.axis2.SimpleServiceStub.echo(SimpleServiceStub.java:146) at org.apache.ws.axis2.Client.main(Client.java:16) Caused by: java.lang.RuntimeException: Unexpected subelement return at org.apache.ws.axis2.SimpleServiceStub$EchoResponse$Factory.parse(SimpleServiceStub.java:758) at org.apache.ws.axis2.SimpleServiceStub.fromOM(SimpleServiceStub.java:818) ... 2 more
ayessa's picture

Problem in Client.java

hi, I had troubles in step 5 so instead, i used eclipse to generate the codes. Eclipse was able to generate SimpleServiceStub. My problem is within the lines: SimpleServiceStub.Echo request = new SimpleServiceStub.Echo(); -- in Client.java. is Echo supposed to be a class? where do i get it? i already ran into several tutorials for web services. Axis1 was easy, but its been 2 weeks and i still cant run a complete client-server in axis2. I'm still a long way from implementing ws-policy... i would very much appriciate if someone points me to the right path. thanks, Ayessa
ruchith's picture

Re: Problem in Client.java

Hi, Echo is an inner class of SimpleServiceStub class. Are you using Axis2-1.0 or the latest nightly build? With Axis2 1.0 there's a known issue where these inner classes are not generated since the generated wsdl at the service is wrong. Can you please try with the latest nightly build available here : http://people.apache.org/dist/axis2/nightly/axis2-std-SNAPSHOT-bin.zip Thanks, Ruchith
michael larkin's picture

Auto Generated SimpleServiceStub.java Missing EchoResponse Class

Dear Ruchith, I have been playing with the July 23rd Nightly Build of Axis2 and noticed that the automatically generated SimpleServiceStub.java does not contain an EchoResponse (static) class - as does the one provided in the hw-axis2/SimpleClient directory tree - thereby resulting in errors while compiling Client.java. Please let me know how I may be of assistance. Regards, Michael Larkin email: mlarkin@e2e.us
michael larkin's picture

Problem Persists in Nightly Build

Hi, Ruchith! Please be aware that the nightly build (located at http://people.apache.org/dist/axis2/nightly/axis2-std-SNAPSHOT-bin.zip) may still have a problem. WSDL2Java continues to complain: Client.java:3: cannot find symbol symbol : class EchoResponse location: class org.apache.axis2.SimpleServiceStub import org.apache.axis2.SimpleServiceStub.EchoResponse; ^ Client.java:12: cannot find symbol symbol : class Echo location: class org.apache.axis2.SimpleServiceStub SimpleServiceStub.Echo request = new SimpleServiceStub.Echo(); ^ Client.java:12: cannot find symbol symbol : class Echo location: class org.apache.axis2.SimpleServiceStub SimpleServiceStub.Echo request = new SimpleServiceStub.Echo(); ^ Client.java:16: cannot find symbol symbol : class EchoResponse location: class org.apache.axis2.Client EchoResponse response = stub.echo(request); ^ Note: SimpleServiceStub.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 4 errors The WSDL2Java command I issued was: sh WSDL2Java.sh -uri http://localhost:8080/axis2/services/SimpleService?wsdl -o /home/michael/us/e2e/SimpleService/release/ The procedure I used to "install" the Axis2 nightly build was to copy the new directories and files over the old ones. Perhaps I have made an error? Please advise. Thanks! (By the way, your example is excellent!!!) Regards, Michael Larkin
deepaknuli's picture

same problem

hey, I am facing exactly the same problem since 2days and still haven't quite figured out how to write a client to access the services runnning. Can you pls let me know if you have figured out the solution? Thanks, Deepak
pallavi291's picture

Problem in running the client

Hi! I downlaoded the axis2-1.1-SNAPSHOT.zip for running the client but continue to face compilation problem. The inner class EchoResponse is not generated in Stub class. I have included all the jars in the classpath but the problem persists. Please help. Thanks, Pallavi
ayessa's picture

Re: Problem in Client.java

hi Ruchith, thank you for your response. I'll do as advised. thanks again! -ayessa
ayessa's picture

How to get call service through web browser

hi Ruchith, I followed your advise to use the nightly build and was able to make the sample run after a few classpath adjustments. I was successfully able to call the service through the client and made another service of my own (congratulations to me =D ). The eclipse plug-in kept me stuck for 2 weeks. It seemed to generate a faulty aar. I ditched the plugin and followed your example instead. I was wondering if you happen to know how to call the service through a web browser. I was able to do that through axis 1, hoping i can do the same with axis 2. thanks, ayessa
ruchith's picture

Re: How to get call service through web browser

This is actually possible in WSO2 Tungsten 1.0 and there are a set of public instances hosted here. You can read this guide to understand how to use the hosted instances and to invoke a service using the browser.
ayessa's picture

hi,

hi, what i mean is, in axis 1, i can simply call my webservice via browser by posting http://localhost:8080/axis/services/MyService?method=someMethod and it will return a soap response. How do i do this in axis 2? I tried replacing axis with axis2 in the url... unfortunately, it didnt work hope you can help me out thanks, Ayessa
ruchith's picture

RE: hi

Hi, REST answers your question: http://ws.apache.org/axis2/1_0/rest-ws.html Thanks, Ruchith
isteele00's picture

axis 2 error: incoming message does not contain security header

Hi ruchith, I have created a web-service system in netbeans which retrieves financial information from a database and then displays it when invoked by a client a application which i have created in microsoft visual studio 2008. The client application is a very simple button layout, so each button corresponds to a different method. However when i compile and try to run it i get the error message: Client found response content type of 'multipart/related; boundary=MIMEBoundaryurn_uuid_6A4D9BBB53FB213A311240595896815; type="application/xop+xml"; start="0.urn:uuid:6A4D9BBB53FB213A311240595896816@apache.org"; start-info="text/xml"', but expected 'text/xml'. The request failed with the error message: -- --MIMEBoundaryurn_uuid_6A4D9BBB53FB213A311240595896815 Content-Type: application/xop+xml; charset=utf-8; type="text/xml" Content-Transfer-Encoding: binary Content-ID: <0.urn:uuid:6A4D9BBB53FB213A311240595896816@apache.org> <?xml version='1.0' encoding='utf-8'?>soapenv:ServerWSDoAllReceiver: Incoming message does not contain required Security header any ideas on how can i resolve this? thanks very much Ian
ayessa's picture

Service with Parameter

Hi, i know this is already beyond the hello world sample but may i ask how to implement a service which asks for a parameter then returns a value. Lets say i have a function public String getAlias(String firstName)... how do i go about in services.xml?... how do i call it through rest? any response would be appreciated =) thanks - ayessa
barbenoire's picture

wsdl parser error

Hello, I am using the tomcat axis server. I am stuck on step 5. After executing WSDL2Java.bat script, I have this specific error :"The entity "nbsp" was referenced, but not declared". Details stack trace is below. Thanks in advance for help. Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException : Error parsing WSDL at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.(CodeGenerat ionEngine.java:125) at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:32) at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:21) Caused by: WSDLException: faultCode=PARSER_ERROR: Parser SAX Error: Fatal Error: URI=http://localhost.urssaf.fr:8080/axis2/services/ Line=32: The entity "nbsp" was referenced, but not declared.: org.xml.sax.SAXException: Fatal Error: URI=ht tp://localhost.urssaf.fr:8080/axis2/services/ Line=32: The entity "nbsp" was ref erenced, but not declared. at org.apache.axis2.util.XMLUtils$ParserErrorHandler.fatalError(XMLUtils .java:361) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalErro r(ErrorHandlerWrapper.java:218) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError( XMLErrorReporter.java:386) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError( XMLErrorReporter.java:316) at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(X MLScanner.java:1438) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp l.scanEntityReference(XMLDocumentFragmentScannerImpl.java:1332) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp l$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1756) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp l.scanDocument(XMLDocumentFragmentScannerImpl.java:368) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X ML11Configuration.java:834) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X ML11Configuration.java:764) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser. java:148) at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser. java:250) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Doc umentBuilderImpl.java:292) at org.apache.axis2.util.XMLUtils.newDocument(XMLUtils.java:178) at org.apache.axis2.util.XMLUtils.newDocument(XMLUtils.java:223) at org.apache.axis2.util.XMLUtils.newDocument(XMLUtils.java:206) at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.readInTheWSDLFile( CodeGenerationEngine.java:274) at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.(CodeGenerat ionEngine.java:108) at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:32) at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:21) at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.readInTheWSDLFile( CodeGenerationEngine.java:280) at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.(CodeGenerat ionEngine.java:108) ... 2 more
krahd's picture

that's prolly happening cos

that's prolly happening cos you're not poting to the WS url. I'd say that you're pointing to it's parent folder. Perhaps a whitespace that shouldn't be there... hth. wbr, tom
aroc725's picture

now getting a ClassNotFoundException

Now I get a ClassNotFoundException on step 5: C:\axis2\bin>WSDL2Java.bat -uri http://localhost:8080/axis2/services/SimpleServi ce?wsdl -o C:\WebServices\tutorial\ClientCode Using AXIS2_HOME: C:\axis2 Using JAVA_HOME: C:\bea\jdk141_05 Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException : java.lang.RuntimeException: java.lang.ClassNotFoundException: org.apache.axis2 .schema.ExtensionUtility at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGener ationEngine.java:235) at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:32) at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:21) Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.apa che.axis2.schema.ExtensionUtility at org.apache.axis2.wsdl.codegen.extension.SimpleDBExtension.engage(Simp leDBExtension.java:52) at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGener ationEngine.java:188) ... 2 more Caused by: java.lang.ClassNotFoundException: org.apache.axis2.schema.ExtensionUt ility at java.net.URLClassLoader$1.run(URLClassLoader.java:198) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:186) at java.lang.ClassLoader.loadClass(ClassLoader.java:299) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:272) at java.lang.ClassLoader.loadClass(ClassLoader.java:255) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:140) at org.apache.axis2.wsdl.codegen.extension.SimpleDBExtension.engage(Simp leDBExtension.java:44) ... 3 more C:\axis2\bin>
ajith's picture

probably a classpath error!

This seems to be a classpath problem. Do you have the adb-codegen module (compiled version would be adb-codegen-xxxx.jar) in the classpath ? If not please do a source build and make sure that the adb-codegen jar is in the classpath.
sumedha's picture

ClassNotFoundException : ExtensionUtility

I have the same problem. The inner class org.apache.axis2.SimpleServiceStub.EchoResponse does not get generated. Then I downloaded the latest nightly build, But still it complains of this missing class. When I tried building from the source as instructed, build failed giving following errors. Attempting to download axis2-common-SNAPSHOT.jar. Error retrieving artifact from [http://cvs.apache.org/repository/axis2/jars/axis 2-common-SNAPSHOT.jar]: java.io.IOException: Unknown error downloading; status code was: 302 Error retrieving artifact from [http://www.openejb.org/maven/axis2/jars/axis2-co re-SNAPSHOT.jar]: java.io.IOException: Unknown error downloading; status code was: 302
aroc725's picture

getting a 'DeploymentException'

I'm getting a 'DeploymentException' on Step 4, using WLS8.1: Jun 19, 2006 2:01:21 PM org.apache.axis2.deployment.DeploymentEngine doDeploy SEVERE: Invalid service SimpleService.aar due to services.xml not found for service 'c:\my-axis2-repo\services\SimpleService.aar'; nested exception is: org.apache.axis2.deployment.DeploymentException: services.xml not found
ruchith's picture

Re: getting a 'DeploymentException'

Please make sure you include the services.xml file in the META-INF directory in your SimpleService.aar file
hasi's picture

Some Probs

Im using AXIS 2 rel 1 but it does generate WSDL correctly (message parts are missing in echoRequest and echoResponse). I tried with rectifying the problem in WSDL, but the stubs generated are not compliant with the sample client described here Can you give the WSDL file you get ? Or is there a stable version of Axis2 than 1.0 ?
library project main code
Learn Cloud
Learn
Cloud

The WSO2 Application Server is a reliable application server that can host your enterprise web applications. The WSO2 Application Server as a Service is offered in StratosLive, the WSO2 Platform as a Service. This article explains how a simple web application can be developed and deployed from Carbon Studio to the WSO2 Application Server...

Latest Webinar
Different groups within an organization need to monitor different Key Performance Indicators (KPIs) - An operations team will be interested in the response times of business services and loads of each service,..
Thursday, February 9th 2012, 09.00 AM (PST)

Thursday, February 9th 2012, 10.00 AM (GMT)