Setting up axis2 soap server - java

I am trying to create a simple SOAP webservice (calculator) to learn the basics of this technology. I am new to SOAP so I have already done some things but I am not sure what to do next.
I have chosen a top-down approach, which means creating a wdsl file first and then generating the code automatically.
I have created a wsdl file with the service description and used that to generate java files. I have it both in 1.1 and 2.0 format. To get 2.0 files I used the wsdl2java tool of axis2, for 1.1 I used java wsimport tool.
From the wsimport tool I got the following files:
package-info.java
ObjectFactory.java
CalculatorService.java (name of my service)
Calculator.java (name of my portType)
Input.java (name of a complex type)
The wsdl2java tool gave me the following files:
services.xml
CalculatorService.wsdl
Output.java (name of output element)
Input.java (name of input element)
cInput.jaba (name of input complex element)
ExtensionMapper.java
CalculatorServiceCallbackHandler.java
CalculatorServiceMessageReceiverInOut.java
CalculatorServiceSkeleton.java (includes implementation of interface)
CalculatorServiceSkeletonInterface.java
CalculatorServiceStub.java
In the wsdl2java files I guess I have everything I need excpept the server implementation. As for the wsimport ones they are missing an implementation and I am not sure where to add it. The server implementation is also missing.
At first I would like to run it as a local service (local server) to test that it is working and also write a client later.
I found an example of a server implementation here: In-process SOAP service server for Java.
It seems quite simple and if possible I would like to use this approach. But I am not sure if it would work with the files I have generated (wsdl2java or wsimport). I also have an Apache server installed if it would be of use. So I am looking for advice, which set of files to use to set up the server and what would be the easiest way to do it.
Also I am wondering if the namespaces used in the wsdl file affect the service availability? Becuase they have to be URI-s but I do not have one for my service at the moment. So for targetNamespace, xmlns:tns, endpoint address, etc I used random URL-s. Would it work if I am trying to run it locally or would it create issues?

Ok, I think I found the solution myself.
Used Tomcat server and eclipse axis2 plugins to get the server and client working.
This was a good tutorial in my opinion: http://eclipse.dzone.com/articles/web-services-development-with-

Related

Consume SOAP webservice in java, only WSDL in hand

I need to consume a web service in java/jsp code. Only the WSDL is available for me to start.
I understand I need to convert the WSDL into java client JAR file using AXIS2 / CXF but I cannot build the whole application on this.
Can someone provide a simple example or basic steps for me to start on this?
I am not able to join the dots here. WSDL, java client JAR, AXIS2.... All online tutorials point on 'creating' a web service.
There are a number of tools capable of doing this included in various frameworks and app servers (CXF, JBoss/Wildfly, etc.), but the JDK itself includes a tool called wsimport which can consume a WSDL file and produce the JAX-WS stubs you need to remotely-invoke the service endpoints via a Java client.
Here's one quick description: http://www.mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/; here is the Oracle documentation for the tool in JDK 7: http://docs.oracle.com/javase/7/docs/technotes/tools/share/wsimport.html.
WSDL is just the conract for the web service. You need to generate client code using it, later you can implement your code to call the web service. Like #maerics pointed out, you should use wsdl2java to generate your client code for AXIS2 and use your client to consume the web service.
You can check this link for an example of client stub generation for AXIS2.

Java SOAP client stub generation with service endpoint determined at runtime

Previously, I've written SOAP clients in Python and used the SUDS library. Without getting into the details, the "stub" generation is really quite dynamic as it's done at runtime and, with Python being so typeless, I'm able to reference the expected methods generated by the WSDL without a pre-compiled stub. I'm fine with generating a stub with something like wsimport, because it's great to have the composition of SOAP messages being handled via a nice Java object structure. So, I'm not looking for a dynamic generation mechanism akin to SUDS in python.
My problem is that all the simple JAX-WS examples I see are for what I'll call a "statically located web service". What I'm trying to do is connect to a web service with a known WSDL from which I could generate stubs at compile time but whose location is only known at runtime. For example, say I want to access Microsoft SharePoint Web Services. Wherever my application is deployed, there will a different SharePoint server (or servers) running which will need to be specified at runtime. All the simple examples I've seen have the service location URL hard-coded into the stubs through wsimport. Is there a way to generate stubs but supply the service location at runtime?
I'm really surprised not to find any examples of this because I figure what I'm trying to do should be very common as Web Services go. Perhaps the answer is that I can't be lazy and get a nice objectified version of the WSDL methods if the server location is only known at runtime. I've seen SAAJ examples but there, of course, I have to generate the SOAP messages by hand myself. That would be such a shame when the WSDL is known at compile time. Can't I have my cake and eat it too?
If I understand your question right, you want to connect to multiple web services that expose the same WSDL but are located at different addresses and your client contains only the address of the service used to generate it?
In that case have a look at this post: Changing WSDL url (endpoint) in JAX-WS client.

Is the java source code generated from "wsimport <wsdl_url>" is actual soap web service code?

I have a wsdl url http://www.webservicex.net/geoipservice.asmx?WSDL
now if i generate a java source code by
wsimport -keep http://www.webservicex.net/geoipservice.asmx?WSDL
Is it going to generate actual soap web service code or just a interface which can call web service ?
I have seen some videos on youtube and as far as i think it cannot generate the actual java source code of soap web service. Please correct me if i am wrong.
so suppose if i want to make changes in soap web service(written in java), the changes in the generated file will not serve the purpose.
May be my question seems very basic to you, but i was looking at an application code and got this confusion , so please answer my query.
The wsimport tool is used to parse an existing Web Services
Description Language (WSDL) file and generate required files (JAX-WS
portable artifacts) for web service client to access the published web
services.
wsimport generates and compile the web service artifacts needed to connect to the service. This utility does not generate the actual web service.
I know that this is an old question , but for the record if you want to generate the actual WebService from an existing WSDL file you should use wsimport sibling which called wsgen

How to connect WSDL file in my application using SOAP service?

I am doing a project using Java and BPEL. I successfully created webservices in Java and integrated them using BPEL. All i generated a single output WSDL file. Now, I have to use this output WSDL file in my application using SOAP communication. How can i do that? Is there any help out side for such scenarios? Walkthroughs are really appreciated..
Depending on the architecture of your application (Standard Java, Spring-based, ...) there might or not be a documented procedure to consume a SOAP-based webservice.
On the other hand, you're always free to pick a webservice development framework to handle that. For instance, you could pick either CXF or AXIS2 (I believe these are the two most popular frameworks for Java WebServices). Each of these frameworks provides a tool called "wsdl2java" that helps you generate client-side/server-side/both Java classes. Then, you can easily add those classes and the requireds libraries to your application.
Having used CXF in the past, It even does provide several way to consume a webservice
Generating the client-side classes
Using CXF dynamic client factory : basically, you'll retrieve an endpoint proxy from a factory object.
Hope that'll help
I start with SoapUI (or downloadable from sourceforge), that will let you consume the WSDL and fire off requests against your server. Typically I'm hitting someone else's webservice, and trying to figure out what the data looks like before I start wiring my code together, but in your case its just a verification that the services would be/are working.
Then, as #KHY said, you can automatically convert the wsdl into java with a wsdl2java and start coding (look under the Related list on the right panel of this SO screen)
If it is a Java application, then the easiest way to consume a service is using JAX-WS. It's really easy to create a Web service client from WSDL.
See this link
Once you deploy the BPEL project on server, then refer the WSDL with http://server:port/application/YourBPELProjectService?WSDL in the consuming application. You will need to write different client code based on the BPEL type - Synchronous, Asynchronous etc.

Accessing SOAP service in Java

I need to access a soap service and I have the wsdl url too. How would I go about doing this in java? Are there any good tutorials to achieve this?
Also I have an xml file generated in android to call a soap service but it isnt working. Is there any place I can paste this xml to check if the xml is correctly calling the webservice (I am using wireshark to record the xml being sent and it appears fine).
Regarding the first part of your question, you could use SoapUI ( http://www.soapui.org/ ) to load the WSDL and generate Java Client code for it ( http://nitinaggarwal.wordpress.com/2010/11/12/generating-client-java-code-for-wsdl-using-soap-ui-axis2-wsdl2java/ ). I used this way once but maybe there are better ways to do it.
The easiest is to generate a client webservice stub in netbeans. Simply create a new project and then add new web service client. Supply the WSDL and your done. Netbeans also has a great web service tutorial.
Very useful link: http://netbeans.org/kb/trails/web.html
I would suggest staying away from axis web service clients. My experience with axis is not great. wsimport used by netbeans is great so far. Uses JAX-WS.
You can use wsimport (part of JDK 6)
See documentation
CXF is both powerful and easy-to-use tool for Webservice Client Generation.
Axis does also ws client generation, but I personally had problems with it.

Categories

Resources