Java web services client - java

I want to build a web services client that takes wsdl link as the input and generates java classes. I know we can do this directly using Netbeans IDE where we provide the wsdl location during project setup. But I want the wsdl location to be provided when the client starts running. How do I do this?

Is the location that will be provided just used to specify the SOAP endpoint (for a web service whose WSDL was known at development time), or will it be a completely arbitrary WSDL?
In the first case, the web service client that was created by Netbeans has methods that accept an alternate SOAP endpoint URL. You can call those to use the client with a server whose location is not hard-coded in the client.
If however, the WSDL describes a completely unrelated service, how are you going to write Java code against it? You cannot use any interfaces derived from the WSDL (because they are not known at development time). You could only have a very generic SOAP client, where the user almost directly types in the XML that will be sent.

Related

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.

Using a single C# SOAP webservice client access the same webservice on multiple servers

The project this concerns is about uploading structured information from Excel to a java based webserver for further processing. As the least common denominator i have chosen SOAP for the job.
For this i have written a C# add-in that accesses a SOAP service on the target server. It uses a web reference to do so. This works on a test system.
In production the client will have to access three servers and these will change over time (not daily, just normal maintenance intervals). The content of a web reference is tied to a specific server, so i will need three web references and a recompile for each server change.
My goal would be a single copy of the (restructured) web reference content so the variable content can be put in a configuration file and a server change can be effected by maintenance.
The question is the following: Has anyone of you built a solution for this? Hints and tips are welcome.

How to use WSDL

I'm working on a WSDL application. But actually I didn't understand what makes the "?wsdl" parameter and what will I do with the returned XML. For example:
https://adwords.google.com/api/adwords/cm/v201309/CampaignService?wsdl
This URL returns and XML string but what will I do with this?
I can convert schema files to java classes using jaxb (xjc) but I didn't understand correctly how to use this WSDL?
Thanks for your answers.
WSDL(Web Services Description Language) is just a contract in the form of xml defining the web services. It contains the details of input and output params of webservices. It is used between client and server to define the interface of communication. It is analogous to a method signature in a programming language. But as it is used between hetrogenous systems so xml is used to describe it.
WSDL is a XML file which contains description of a SOAP web service. WSDL file contains details regarding XML request structure, XML response structure, Web service endpoint details, Web service URL etc.WSDL file is the single most important file of a SOAP web service. The owner of a web service provides WSDL file to the client and by using the WSDL file a client interacts with the service. By using the WSDL file a client can generate client side stubs and java classes to contact with the server. Java since its release 7 supports APIs to generate client side code from a WSDL file. WSDL is created at the time of creating the web service.
When you have that URL containing the WSDL,simply use a tool like SOAPUI and generate a SOAP message and invoke web service. Web service can contain one more input elements so in that case you need to provide input element in the SOAP message.
To invoke a web service you just need a WSDL URL , you already have that. Just use a tool like SOAPUI.
WSDL is the file describing your webservices.
Meta Information about your methods, etc.
Any Web Client should understand and use WSDL files to generates all methods needed to communicate with a Web Server.

How do you intercept WSDL requests in CXF?

Backstory:
I have a WSDL that was created by the customer (non-negotiable) that mixes several web standards into a single service. This one soap service has four soap ports that refer to bindings in referenced (wsdl:import) WSDL files that import XSDs resulting in a dependency tree that is significantly complex.
Since this is done by imports, the top level WSDL isn't that big. WSDL2Java and wsimport choke on it, but I have a library of the schemas compiled into JAXB objects to work with. So I created a CXF service that has all of the required operations and I was able to test it with SoapUI (it imported the top level WSDL fine since it didn't have to make java classes).
Since all the soap ports point to the same address, and that service handles all the operations from the various ports, the client doesn't know that the server thinks all the operations belong to the same port.
Problem:
This breaks down when it comes to CXF generating the WSDL. It puts all the operations on one port with the same namespace. In the customer provided WSDL, the service, ports and bindings are not all in the same namespace. I have tried to supply the service with the WSDL using the #WebService(wsdlLocation="") annotation, but it tries to parse it and match it to the code (as it would in a sane world).
Question:
I would like to intercept/override the http://example.com/service?wsdl operation and return the customer provided wsdl. Is there a way to do this in CXF?
I ended up splitting the ports out into separate services, but I still needed a custom WSDL that had info for all the ports. The way to do this with CXF is to create an interceptor.
I followed the example of the CXF interceptor that regularly handles WSDL generation: http://grepcode.com/file/repo1.maven.org/maven2/org.apache.cxf/cxf-rt-frontend-simple/2.4.0/org/apache/cxf/frontend/WSDLGetInterceptor.java. I read in my custom WSDL and replace the placeholder hostname with the hostname that comes from the request URL.
You need to then add the custom interceptor when you make your service (I use spring for my configuration). More info on that at http://cxf.apache.org/docs/interceptors.html.

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.

Categories

Resources