`
zsjg13
  • 浏览: 137982 次
  • 性别: Icon_minigender_1
  • 来自: 安徽
社区版块
存档分类
最新评论

How do I develop a client?

    博客分类:
  • CXF
 
阅读更多

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:

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;
...
 
URL wsdlURL = new URL("http://localhost/hello?wsdl");
QName SERVICE_NAME = new QName("http://apache.org/hello_world_soap_http", "SOAPService");
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;
...
 
URL wsdlURL = new URL("http://localhost/hello?wsdl");
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

分享到:
评论

相关推荐

    Excel 2003 Programming with VBA

    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 ...

    Web.Client.Programming.with.Perl.Automating.Tasks.on.the.Web.pdf

    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 ...

    Expert Oracle Database Architecture 2nd 原版PDF by Kyte

    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, ...

    Great.Teams.16.Things.High.Performing.Organizations.Do.Differently.epub

    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(PACKT,2016)

    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 ...

    Professional Microsoft Windows Embedded CE 6.0

    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.

    VB编程资源大全(英文源码 网络)

    You can send messages with a client/server type setup.&lt;END&gt;&lt;br&gt;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 ...

    Pro HTML5 Programming(HTML5高级程序设计英文原版)

    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 ...

    Beginning JavaScript and CSS Development with jQuery

    enable you to rapidly develop client-side applications. I also cover the jQuery UI library, which makes redundant user-interface (UI) tasks on the client side ridiculously easy and accessible to ...

    VB编程资源大全(英文源码 数据库)

    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...

    Learning jQuery 3 - Fifth Edition

    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 ...

    Arduino: A Quick-Start Guide, 2nd Edition

    You’ll learn how to connect your Arduino to the Internet and program both client and server applications. You’ll build projects such as your own motion-sensing game controller with a three-axis ...

    angularJs by example

    By creating these applications yourself, you will find out how AngularJS manages client-server interactions and how to effectively utilize directives to develop applications further. You'll also find...

    seven web framework in seven weeks

    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 ...

    AngularJS by Example-Packt Publishing 2015

    By creating these applications yourself, you will find out how AngularJS manages client-server interactions and how to effectively utilize directives to develop applications further. You'll also find...

    Core PYTHON Programming, 2nd Edition (pdf, Python 2.5)

    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,...

    Core PYTHON Programming, 2nd Edition (epub 格式, Python 2.5)

    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,...

    Learning Ionic 2 - Second Edition

    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....

    RESTful Web Services Cookbook

    Know what and what not to do to support caching * Learn how to implement concurrency control * Deal with advanced use cases involving copying, merging, transactions, batch processing, and partial ...

Global site tag (gtag.js) - Google Analytics