wood burning stoves 2.0*
The moose likes Web Services and the fly likes how to consume a webservice using axis2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "how to consume a webservice using axis2" Watch "how to consume a webservice using axis2" New topic
Author

how to consume a webservice using axis2

ruchita mahajan
Ranch Hand

Joined: Jun 16, 2009
Posts: 33
hello,
i am new to web services.I may be asking this question wrongly.so forgive me.
In my project i have to consume a webservice using java.Could you please say me how to Create a client api in axis2 in java to consume the webservice that has been created in vb.net.
thanks in advance.
Kunal Janyani
Greenhorn

Joined: Jul 06, 2009
Posts: 1
Hi,

There are 2 approaches to WS Development, top-down and bottom-up. Consuming a WS Request is the task of the Web Service Source Code. In your case, I think you need to write a client to a Web Service already existing in VB.net code.
If you have the wsdl file with you, this is quite elementary using any IDE like IBM RAD(generally preferred for Java Development) or Netbeans.

IBM RAD provides direct facility to generate Webservice Client code from a wsdl file. All you need to do is create a new "Dynamic Web Service Project" in a RAD Workspace. Then import your wsdl file to this Project. Then, right click on that file, and select Webservices ---> Generate Client. This would allow you to configure parameters like WS Runtime which can be set to Apache Axis here. If you want to go ahead and deploy the client on an existing server instance on your local machine, the server can be specified here. Once the code is generated you can go ahead and tweak key inputs to the Web Service Request invocation to test the WS better.

A suggestion before starting would be to check the WSDL first by Right Clicking wsdl and selecting Webservices ---> Test with Web Services Explorer.

Hope this helps you...
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

It does not matter using what the web service has been written. The main thing is the wsdl uri. As said in the above post netbeans and RAD have their own tools to generate ws clients. But as per my knowledge RAD uses either jax-ws or axis 1 to generate ws clients. But as you have mentioned that you wish to use axis 2. You first need to download asix 2 library, and set the required jar files in classpath and have to change some environment variables as per their documentation. Later on you need to use the following command to generate the client stub

wsdl2java -uri <location of you wsdl file> -o <name of the folder/directory under which folder/directory generated files will be store> -p <name of the package under which the class files will go>


Swastik
ruchita mahajan
Ranch Hand

Joined: Jun 16, 2009
Posts: 33
thanks you all for your reply.
i am using eclipse IDE.Any idea you people have about creating the client api in java using eclipse ide and axis2
bye
ruchita mahajan
Ranch Hand

Joined: Jun 16, 2009
Posts: 33
i downlaoded the axis2.war and imported it and executed it in my eclipse ide.its working fine there giving me the happiness page of axis2.
but when i create the client api it is not working.
here i am sending you the client api that i have written in java to consume the webservice.
may be i am missing something.
so please i need your guidence.
thanks a lot for you guys reply



package org.apache.axis2.webapp;



import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.databinding.types.soapencoding.String;

public class Clientapi {

public static void main(String args[]) throws Exception {
ServiceClient client = new ServiceClient();
// create option object
Options opts = new Options();
//setting target EPR
opts.setTo(new EndpointReference("http://192.168.1.26/MapMakerWrapper/service1.asmx"));
//Setting action ,and which can be found from the wsdl of the service
opts.setAction("http://tempuri.org/VMM_CreateMap");
client.setOptions(opts);
//client.setOptions2(width);
//client.setOptions3(height);
OMElement res = client.sendReceive(createPayLoad());
System.out.println(res);
//System.out.println(System.getProperty("java.version"));

}

public static OMElement createPayLoad() {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://tempuri.org/", "ns1");
OMElement method = fac.createOMElement("VMM_CreateMap", omNs);
OMElement value = fac.createOMElement("24018", omNs);
value.setText("client Api");
method.addChild(value);
return method;
}

}

ruchita mahajan
Ranch Hand

Joined: Jun 16, 2009
Posts: 33
i have also downloaded all the necessary jars for this.please it is very urgent.
bye
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41073
    
  43
it is not working.

ItDoesntWorkIsUseless: TellTheDetails


Ping & DNS - my free Android networking tools app
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

Ruchita,

You need to tell us the details of the error. Its not compiling, any run time error or something else?
ruchita mahajan
Ranch Hand

Joined: Jun 16, 2009
Posts: 33
it's giving

log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisService).
log4j:WARN Please initialize the log4j system properly.
org.apache.axis2.AxisFault: The service cannot be found for the endpoint reference (EPR) http://localhost:8080/axis2/services/TemperatureConverter
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 ws.example.TemperatureConverterStub.c2FConvertion(TemperatureConverterStub.java:440)
at ws.example.TemperatureConverterServiceClient.main(TemperatureConverterServiceClient.java:14)
ruchita mahajan
Ranch Hand

Joined: Jun 16, 2009
Posts: 33
could you guys please give me the simple and very basic steps for consuming a web service using java ,axis2,,eclipse IDE .just start from very first step.
bye
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

You first need to download the axis2 library. Once you download that, you will find a readme file containing information about how to set the environment variables for axis2. In axis2 there is an utility called wsdl2java which is used to generate the required java stubs based on the wsdl uri. Once the stubs are generated you can proceed with the coding part. I haven't worked much with eclipse, but probable steps should be within your project space include the axis2 generated codes(Stubs). Write required codes to make call to the webservice methods. Include the axis2 library fies(jar files) in the project classpath.
swapnil paranjape
Ranch Hand

Joined: May 15, 2005
Posts: 126
Hi Ruchita,

I am also new to web service and writing my first java client to get SOAP response.


take a look at this example as a good to start with

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/SAAJ4.html

You need following jar files in your eclipse jar library


activation
axis
axis-jaxrpc
axis-wsdl-1.5.1
commons-discovery
commons-logging
mail-1.3.3
saaj

ruchita mahajan
Ranch Hand

Joined: Jun 16, 2009
Posts: 33
hello ,
i am also using the axis2 along with eclipse to create a web service client api in order to consume a webservice.
i am not at all able to figure out where i went wrong.
any help will be welcomed.
please tell me from the very start.
thanks in advance
bye
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

Did you try the steps I mentioned?
ruchita mahajan
Ranch Hand

Joined: Jun 16, 2009
Posts: 33
hello,
i downloaded the axis2.war and that is working fine.this war file is having all the required jars in it.
now say me one by one what all i need.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

It might be having all the required jars, but does it have other utilities like wsdl2java, java2wsdl etc. You need wsdl2java to generate the stub based on the wsdl uri. If the utilities are not there, you need to download the binary distribution (zip) not war. You also need to do some environmental settings like setting AXIS2_HOME variable etc.
ruchita mahajan
Ranch Hand

Joined: Jun 16, 2009
Posts: 33
Thanks swastik,
you helped me a lot and now my client api is working fine.hats off to you
ruchita mahajan
Ranch Hand

Joined: Jun 16, 2009
Posts: 33
was having the following warning on executing the client
log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisService).
log4j:WARN Please initialize the log4j system properly.


to solve this i added the file log4j.properties to the src folder of my project.
this contents of this file are:

# Set root category priority to INFO and set its only appender to A1
log4j.rootCategory=INFO, A1

# A1 is set to be a ConsoleAppender (writes to system console).
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

this worked for me n now my code is running without any warning
DhaKatta Dha
Greenhorn

Joined: Aug 25, 2009
Posts: 12
Hi Ruchita,

I have seen your question to generate a webservice stub and consume a webservice using axis.

Its very useful to me as a first timer. Can you please explain me what is "http://tempuri.org/VMM_CreateMap" I want to similar task by using eclipse,axis2 and wsdl.

I'm at a point with axis2 setup ready and wsdl2java is also ready. I want to make a call using the stub I have where are you using the generated stub?

Please explain your code.

Thank you very much
-Tankatta
ruchita mahajan wrote:i downlaoded the axis2.war and imported it and executed it in my eclipse ide.its working fine there giving me the happiness page of axis2.
but when i create the client api it is not working.
here i am sending you the client api that i have written in java to consume the webservice.
may be i am missing something.
so please i need your guidence.
thanks a lot for you guys reply



package org.apache.axis2.webapp;



import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.databinding.types.soapencoding.String;

public class Clientapi {

public static void main(String args[]) throws Exception {
ServiceClient client = new ServiceClient();
// create option object
Options opts = new Options();
//setting target EPR
opts.setTo(new EndpointReference("http://192.168.1.26/MapMakerWrapper/service1.asmx"));
//Setting action ,and which can be found from the wsdl of the service
opts.setAction("http://tempuri.org/VMM_CreateMap");
client.setOptions(opts);
//client.setOptions2(width);
//client.setOptions3(height);
OMElement res = client.sendReceive(createPayLoad());
System.out.println(res);
//System.out.println(System.getProperty("java.version"));

}

public static OMElement createPayLoad() {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://tempuri.org/", "ns1");
OMElement method = fac.createOMElement("VMM_CreateMap", omNs);
OMElement value = fac.createOMElement("24018", omNs);
value.setText("client Api");
method.addChild(value);
return method;
}

}

DhaKatta Dha
Greenhorn

Joined: Aug 25, 2009
Posts: 12
Hi Ruchita,

This is really quick which I forgot to mention earlier.

Could you please make me understand how do you conusme the webservic eusing your code may be some inline comments in your code below.

Best Regards



ruchita mahajan wrote:i downlaoded the axis2.war and imported it and executed it in my eclipse ide.its working fine there giving me the happiness page of axis2.
but when i create the client api it is not working.
here i am sending you the client api that i have written in java to consume the webservice.
may be i am missing something.
so please i need your guidence.
thanks a lot for you guys reply



package org.apache.axis2.webapp;



import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.databinding.types.soapencoding.String;

public class Clientapi {

public static void main(String args[]) throws Exception {
ServiceClient client = new ServiceClient();
// create option object
Options opts = new Options();
//setting target EPR
opts.setTo(new EndpointReference("http://192.168.1.26/MapMakerWrapper/service1.asmx"));
//Setting action ,and which can be found from the wsdl of the service
opts.setAction("http://tempuri.org/VMM_CreateMap");
client.setOptions(opts);
//client.setOptions2(width);
//client.setOptions3(height);
OMElement res = client.sendReceive(createPayLoad());
System.out.println(res);
//System.out.println(System.getProperty("java.version"));

}

public static OMElement createPayLoad() {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://tempuri.org/", "ns1");
OMElement method = fac.createOMElement("VMM_CreateMap", omNs);
OMElement value = fac.createOMElement("24018", omNs);
value.setText("client Api");
method.addChild(value);
return method;
}

}

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how to consume a webservice using axis2
 
Similar Threads
AXIS 1.4.1 compatability with Statefull Web Services
Consuming secure web-services (Axis2 + Rampart)
SpringWS Client for Axis2 webservices
consuming a webservice
applicationcontext.xml