CXF Service Assistance - java

I have a service that was given to me, that basically searches the inventory of a future partner. The file they sent is a compiled .jar file, and a wsdl file. The read me file states that it can be used with XFire or CXF. How do I set this service up using Apache, Tomcat, Spring, or whatever else I need to do? It's a fairly broad question, but I am at a loss as to what to do here.

Your choices are as follows:
Hire a Java programmer, or
Become a Java programmer yourself.
In your shoes, I'd opt for #1. You probably have enough on your plate running your business to learn the ins and outs of coding.

Most likely the jar file you got is actually the generated java beans (jaxb) and stubs (jax ws and the likes). So you should be able to figure our an entry point class there and use that to call the webservice. But as others suggested very little information to really give an answer. JaxWS docs are here http://docs.oracle.com/javaee/5/tutorial/doc/bnayl.html

Related

Using java to generate WSDL with given parameters

I am looking for some tutorials or resources that may assist me with a problem in Web Service Composition, where I need to a generate WSDL with given inputs and parameters. I want to start from scratch like java with some "element" method that can output a basic WSDL hierarchy. Thank you.
P.S. I did spend a reasonable amount of time looking for above-mentioned stuff but I do consider the probability of encountering an open source implementation from this community.
Have a look at the tools provided in the Apache CXF project, which allows generating WSDL from Java source and vice versa. Similar functionality is provided by Apache Axis2.

How to pull detailed schema info from a WSDL based web service?

Assuming I am developing a client for a known, WSDL-based, web service (of which source code is not available to me):
Is there a way I can validate various fields (e.g. string lengths not exceeding limit) based on the inline schema in that WSDL, at runtime?
If so, how do I interact with that web service to get its inline XSD information?
If you want to make this really dynamic, than you have to assume that the URI to the WSDL is accessible to you, along with all other external references the WSDL might use, to other WSDL files and/or XSD files.
First step, you will have to download files to a temp folder, or create I/O streams to those URIs for in memory loading, to load a schema (a javax.xml.validation.Schema). I am not aware of a Java API which would make this task easy (get a schema out of WSDL reference, such as one available to developers on the .NET platform) - hopefully if there is one, someone might chime in. Otherwise, it shouldn't be that difficult to write one.
I have to warn you that many people may consider this (loading external URIs, particularly one pointing to the Internet) as a security issue in a production environment, so be careful here with your design. Since you're saying "a known, WSDL-based, web service", I would probably aquire the XSDs at design time, and bundle them as resources in my Jar files which would go with the client code.
The next thing is how do you create your XML... Let's say you're using something such as JAXB, then a post such as this one will give an idea how to tackle your problem, and what exactly do you need to validate. If you're not using JAXB, then explore what your API is doing, and how it would actually allow you to interject your validation...
I hope that this at least gives you an idea around the kind of details you need to have in this kind of question, to get a more specific answer.

Webservices :Understanding the task assigned

I am a complete newbie to web services and I am working alone. My lead mailed me a task to complete. I think he has hard coded the information and he wants me to replace the hard coded data from web services.
He has mailed me a WSDL file and said
Make the jar file from the wsdl.
What does this mean ?
There are tools which will generate Java code to talk to web services, performing serialization and deserialization effectively, so that your client code can talk in terms of Java objects rather than raw SOAP.
You should find out which of these tools is being used in your project, and apply it to the WSDL provided.
(Also, it's a good idea to get used to asking for more information when you don't understand the assignment. A good team leader - or anyone, really - should be more than happy to help you.)
Generate the Java stubs from the wsdl.
wsdl2Java
wsdl2Java
If you are familiar with eclipse, then the task can be completed easily. I think he is asking for the jar of client stub which can be produced from the wsdl.
In that case do: In eclipse, make sure you have webservices plugin. Follow this after that
You will have few .java files being exported. Try to compile them and generate the .class files. Now jar the .class files using command in command prompt
jar -cvf <Name of the jar>.jar *

Generating Java from WSDL for use on Android with ksoap2-android SOAP client?

I have to access a existing SOAP webservice from an Android application. I have been provided some WSDL files describing the webservice. Reading some other answers here on SO, it seems ksoap2-android is the way to go, with respect to which SOAP client to use.
The next issue is then how to generate the Java classes needed from the WSDL files, and this is where I am coming up short. As far as I can see there are the following options:
AXIS2 code generator
WSDL2ksoap
JAX-WS wsimport tool
I initially tried #1, with the AXIS2 eclipse plugin for wsdl2code generator. The wizard did successfully generate a lot of Java code, however it also changed my android project to some kind of webservice project, and I was never able to get anything that was generated to compile, let alone work with ksoap2-android. Has anybody has success with this?
I am not able to run wsdl2ksoap successfully, as it seems to require a running webservice, and all I have at the current point in time is WSDL files. Likewise from reading the webpage, it seems to be a project in its initial stages, and not really ready for prime time.
JAX-WS wsimport I have not had a chance to try yet. However I am unsure if what it generates will work with ksoap2-android?
Question: How can I generate Java files from WSDL files, for use on Android with ksoap2-android SOAP client library?
Thanks a lot in advance.
(PS: Yes, the choice is SOAP, it is suboptimal for Android use, but I cannot change that.)
I found this tool to auto generate wsdl to android code,
http://www.wsdl2code.com/example.aspx
Here is the code:
public void callWebService() {
SampleService srv1 = new SampleService();
Request req = new Request();
req.companyId = "1";
req.userName = "userName";
req.password = "pas";
Response response = srv1.ServiceSample(req);
}
I had similar situation (I had only wsdl file without working webservice). I've used
http://easywsdl.com/
to generate classes for android without any problem. This tool uses ksoap library. The great thing with this tool is that it supports WCF extensions and types like data contract with IsReference attribute or Guid.
My conclusion after quite a bit of researching is that there is no such (mature) tool available, unfortunately. Neither AXIS2 or JAX-WS will work on Android, and WSDL2ksoap is simply too immature for any real use.
However there is a proprietary tool called wsclient++ that will do the job really well. (Read update below, when put to real use, it does not stand the distance at all.) It does not use the ksoap2-android client library, it has it's own.
The client library is a bit crude as it has a hard dependency on the http transport, making (unit) testing a bit complicated. But it can be modified quite easily to allow DI, as the source is available in the distributed jar file.
The wsdl to java generator however works just perfect, and will save us tons of time.
Update
After working with wsclient++ for a while, it is clear that the generated classes are really crude, and does not handle error cases at all. (Every method declares throws Exception).
We are no longer using wsclient++, and I would not recommend anyone to use it!
We have not really found any working alternative, unfortunately. :/
In the end we converted our WSDL files using AXIS2, and then wrote a bunch of custom script to strip and transform the generated java files to something that will build on android using ksoap2-android library. Very hackish, and needs tons of manual labor to run. Unfortunately. If you find a better way, or one comes up, please provide a new answer.
I use Apache CXF tool just to create dto, and i wrote a class to perform a basic unmarshalling based on name of elements
A bit late on this, but there is a ksoap2 stub generator under development, and I successfully used it to create the stubs.
http://ksoap2-stub-gen.sourceforge.net/
Also someone made it availabe as an online service (i.e. you give your WSDL's URL and the service will return a zip file containing the stubs).
http://www.davidgouveia.net/2011/04/online-stub-generator-for-android-applications-using-ksoap2/
I have used for iPhone too some auto-generated classes I wanted to see here too.
wsdl2code is one of the similar what I have used at iPhone. Give an url with wsdl file you will get some classes to download. For me the hardest part it was to download the required parts. It took more than 2 minutes of searching :) ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar needed to download ad drag-and-drop to ADT ( Eclipse) . It is super easy, especially if you have used the counterpart at iPhone. - a similar tool I have used.
However in my case I am not happy at all with the solution, because I see I am using cannon, a set of cannons to shot a sparrow. In my case it should be used a HTTP Post and not including dependencies from other libraries.
To be honest I don't care to much, because once the server side believe we have unlimited battery power and unlimited data plan, than I close my eyes and I don't care about marshaling-unmarshaling overheads, which use the CPU ( battery ) increase the data transmitted over network.
In worse case it should be a JSON + HTTP POST not SOAP for mobiles...
I would suggest to talk at server side guys and explain for they why it will not good if they do 2 click on wizards and we do other click on forms to get the generated code. At least while the application is not a huge one, even than should be budget to optimise for mobile a few interfaces implementations.

How to create WSDL file given SOAP WSDL operations

I haven't had any experience with web service related development. So, any ideas will be greatly appreciated.
Suppose, I have a file listing draft specification of WSDL operations. Following is one example. How would I go about creating the WSDL file. Is notepad sufficient or do I need to have WSDL editor?
getHostSystemInfo
Returns detailed information about host systems specified via given IDs.
input HostSystemIdCollection(Collection of Strings)
Output HostSystemInfoCollection
HostSystemInfo
Id: mandatory
Properties: Following properties should be provided for host systems
HostSystemName
HostSystemProperty1
HostSystemProperty2
HostSystemProperty3
....
....
If the question is just "how do I create the WSDL" then you could indeed use Notepad and just write it, it's only XML after all. However, writing syntactically correct XML by hand is pretty dull, and error prone. So I would recommend using WSDL aware tooling for example an Eclipse editor
An alternative is to write some Java which expresses the interface, and from it generate the WSDL. There are many ways of doing this, including starting with an EJB and annotating it accordingly. A few googles should help you find what you need.
My experience is that simple POC situations tend to work well starting at the Java. Larger scale projects benfit from considered designs starting at the WSDL.
coding WSDL by hand is a big pain! i used a XML editor for creation of and then generated the stubs with JAXWS. It is important to understand and differences of the WSDL styles, which is not trivial (have a look at WSDL styles). a good help is to import the WSDL schema to your IDE (eclipse, idea) and then work with autocompletion.
just for interest, why are you using WSDL + SOAP. if you have a choice and you use anyway HTTP, have a look at REST. It can make implementation of web-api a LOT easier, both on server side and for api-clients.
If you haven't done any web services before, I would strongly recommend a WSDL Editor. The Netbeans has a plugin that should help.
The other way of doing it, which may be easier is by using the Java annotations defined in JSR 181.
Of course you could use the worst text editor in the world (!) but I'd seriously consider using any decent XML editor or IDE (Eclipse's WSDL support is pretty decent). This will save you a lot of pain and suffer.
Or, if this is an option, you could just annotate a Java class with JAX-WS annotations and have your WSDL dynamically generated from the Java code. Personally, I prefer the WSDL-first approach, the Java-first approach is just a suggestion to get you started.
You could use Axis2 to create that for you.

Categories