Hello World with Apache Axis2

Story :

Project :

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.

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
4.75
Average: 4.8 (4 votes)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Step 5

I'm stuck on Step 5. It says

"Now lets use the WSDL2Java tool generate the client side stubs to interact with the service.
...
[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."

What are the 2 .java files used for and where are they created, in the '/path/to/my/client/code/' subdirectory?

Re: Step 5

The two classes created are :
- org.apache.axis2.SimpleServiceCallbackHandler
- org.apache.axis2.SimpleServiceStub

And yes they are created in an "src" directory within the directory you specify after the "-o" argument when running WSDL2Java.

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 ?

Re: Some Probs

Hi,

Thanks for pointing out the issue ... When this particular service is hosted in SimpleHTTPServer from Axis2-1.0 distro it doesn't generate the wsdl types properly. This is problem is fixed now. Please try using the Axis2 snapshot. [1]. I will update the main text of the article/tutorial to update this fact.

Thanks,
Ruchith

[1] http://people.apache.org/dist/axis2/nightly/axis2-std-SNAPSHOT-bin.zip

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

Re: getting a 'DeploymentException'

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

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>

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.

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

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

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

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

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

Re: Problem in Client.java

hi Ruchith,

thank you for your response. I'll do as advised. thanks again!

-ayessa

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

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.

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

RE: hi

Hi,

REST answers your question:
http://ws.apache.org/axis2/1_0/rest-ws.html

Thanks,
Ruchith

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

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

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

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

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

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

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();
}
}
}

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?

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

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

.

Just to say that by using the latest nightly build I got the example running, but having to change setParam0 to setMessage.

hth,
tom

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

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 ...  

 

 

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.SimpleNsStreamWriter
6055 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.wire - << HTTP/1.1 500 Internal server error
6055 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.wire - << Date: Fri, 02 Mar 2007 15:29:44 GMT
6055 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.wire - << Server: Simple-Server/1.1
6055 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.wire - << Content-Length: 292
6055 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.wire - << Content-Type: text/xml; charset=UTF-8
6055 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.wire - << Connection: Close
6056 [HttpConnection-8080-1] DEBUG org.apache.axis2.transport.http.server.DefaultHttpServiceProcessor - Response sent
6056 [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 :(

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

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

Strangely...

I know nothing about SimpleHTTPServer. Anyone ready to show the light please?

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 

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

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!!

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

[

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! :(

 

 

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.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.