CXF provides you with many options to build clients for your services. This guide is meant to give you a quick overview of those options and help you orient yourself quickly with CXF.
Building Clients
WSDL2Java generated Client
One of the most common scenarios is that where you have a service which you may or not manage and this service has a WSDL. In this case you'll often want to generate a client from the WSDL. This provides you with a strongly typed interface by which to interact with the service. Once you've generated a client, typical usage of it will look like so:
HelloService service = new HelloService();
Hello client = service.getHelloHttpPort(); String result = client.sayHi( "Joe" );
|
The WSDL2Java tool will generate JAX-WS clients from your WSDL. You can run WSDL2java one of three ways:
- The command line
- The Maven Plugin
- With the WSDL2Java API
For more in depth information read Developing a JAX-WS consumer or see the Hello World demos inside the distribution.
JAX-WS Proxy
Instead of using a wsdl2java-generated stub client directly, you can use Service.create to create Service instances, the following code illustrates this process:
import java.net.URL;
import javax.xml.ws.Service;
... Service service = Service.create(wsdlURL, SERVICE_NAME); Greeter client = service.getPort(Greeter. class );
String result = client.greetMe( "test" );
|
JAX-WS Dispatch APIs
JAX-WS provides the "dispatch" mechanism which makes it easy to dynamically invoke services which you have not generated a client for. Using the Dispatch mechanism you can create messages (which can be JAXB objects, Source objects, or a SAAJMessage) and dispatch them to the server. A simple example might look like this:
import java.net.URL;
import javax.xml.transform.Source;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
... Service service = Service.create(wsdlURL, new QName( "HelloService" ));
Dispatch<Source> disp = service.createDispatch( new QName( "HelloPort" ), Source. class , Service.Mode.PAYLOAD);
Source request = new StreamSource( "<hello/>" )
Source response = disp.invoke(request); |
NOTE: you can also use dispatches without a WSDL.
For more in depth information see the Hello World demos inside the distribution.
Simple Frontend Client Proxy
If you've developed a service using the simple frontend, you can use the ClientProxyFactoryBean API to create a Java proxy client for your service. This way you can use the service interface to talk to your service. For more information see the Simple Frontend documentation.
Dynamic Client
CXF includes a Client interface which allows you to invoke operations and pass parameters for those operations. For instance:
Client client = ....; Object[] result = client.invoke( "sayHi" , "Dan" );
|
There are two ways to create Clients at runtime. The first choice is to use the ClientFactoryBean or JaxWsClientFactoryBean classes. These will create proxy objects for the SEI for the service. These proxies cannot handle complex objects.
The second to use the DynamicClientFactory or one of its subclasses. The DynamicClientFactory goes the additional step of generating and compiling JAXB POJOs for complex objects described in the WSDL, for use at runtime via reflection.
This is most useful when you're using a dynamic language such as Groovy with CXF, but it is possible to use reflection directly from Java.
More Information: Dynamic Clients
相关推荐
almost any web-related task you'll find yourself thinking, "Hey, I could write a script to do that!" Unfortunately, we can't teach you everything. There are a few things that we assume that you are ...
If you learn how to develop applications based in Excel, you will be a happier person because you’ll have the opportunity to help people and create value by creating applications that allow people ...
have written a similarly titled book explaining how to develop an application using a specific language and architecture—for example, one using JavaServer Pages that speaks to Enterprise JavaBeans, ...
Delivering an average of 80 keynote speeches per year, Don was approached by his most consistent client, Microsoft, to develop a talk on what allowed some teams to play at a championship level year ...
Swift 2 by Example is a fast-paced, practical guide to help you learn how to develop iOS apps using Swift. Through the development of seven different iOS apps and one server app, you’ll find out how ...
Product Description Windows Embedded CE is a Microsoft operating... They provide examples, practical solutions, and expert education in new technologies, all designed to help programmers do a better job.
You can send messages with a client/server type setup.<END><br>57 , al40.zip Apparently, if you use AOL to connect to the Internet and you do not touch it for 45 minutes it will timeout and drop ...
Brian also led a cross-team effort to develop a DHTML rich client and a mobile client presentation layer for Oracle's Project Fusion. Brian received a BS degree in Computer Science from the ...
1 , datafile.zip "This sample demonstrates how to do file input and output using Visual Basic. The sample creates a new database file and allows you to view, add, or delete records in this database...
Create a fully featured and responsive client-side application using jQuery Explore all the latest features of jQuery 3.0 and code examples updated to reflect modern JavaScript environments Develop ...
say what you want, not how to do it, with a mixture of declarative HTML and JavaScript. Turn the web into data with Ring, and use Clojure to make data your puppet. Become a master of advanced ...
Learn how to develop your own GUI applications using Tkinter and other toolkits available for Python Improve the performance of your Python applications by writing extensions in C and other languages,...
We take a look at theming Ionic apps using the built-in SCSS setup, work with Ionic API components, and create a “Thought Journal” app that needs session and data to be managed on the client side....
By using this training guide, you will learn how to do the following. ■■ Create a project using Visual Studio Express 2012 for Web. ■■ Create a project using Blend for Visual Studio 2012. ■■ ...
In conclusion, Microsoft Outlook 2007 is not just an email client but a comprehensive platform that can be customized and extended through programming. Whether you are a beginner or an experienced ...