Xfire's Introductory tutorial

Source: Internet
Author: User
Tags soap tomcat server wsdl

XFire is an open source framework provided by Codehaus, which builds a bridge between POJO and SOA, with the main feature supporting the release of POJO to Web services in a very simple way, which not only gives full play to the role of POJO, simplifies Java applications The steps and processes of WEB services also directly reduce the difficulty of SOA implementation, providing a simple and workable way for an enterprise to move to an SOA architecture.

XFire is currently the latest version of the 1.2.6, currently supported features are mainly:

L Support for important Web Service Standards-soap, WSDL, WS-I Basic profile, ws-addressing, ws-security, etc.

L High Performance SOAP Stack pluggable bindings POJOs, XMLBeans, JAXB 1.1, JAXB 2.0, and Castor support

L JSR 181 API to configure services via Java 5 and 1.4 (Commons attributes JSR 181 syntax)

L Support for many different transports-http, JMS, XMPP, IN-JVM, etc.

L Embeddable and Intuitive APIs

L Spring, Pico, Plexus, and loom support.

L JBI Support

L Client and server stub generation

L JAX-WS Early Access support

1. under XFire , download

XFire's official website is XFire.codehaus.org, after entering the homepage, find the download link on the right, click to enter the download page. The latest version 1.2.6 has four links, select the first xfire-distribution-1.2.6.zip download.

Download the unpacked directory structure as follows

A description of each directory and file corresponds to the following:

(1) API : API documentation for Xfire class libraries

(2) examples : Xfire sample source code

(3) Lib : Xfire depends on the jar package, do not have to import all, according to the project needs to choose

(4) manual : Xfire Help Document

(5) modules : Different jar packages based on xfire different characteristics

(6) Xfire-all-1.2.6.jar: xfire full jar Package

2. the HelloWorld of XFire

Here's a simple HelloWorld example with Xfire. Detailed steps are as follows:

1 Create a new Web project, named Xfire;

2) will download the Xfire Xfire-all-1.2.6.jar package and Lib under all the jar package copy to the project Lib directory, while downloading a single Xalan package online. If everyone used to do Project Xalan package, can also be directly copy over.

3) by adding in Web.xml:

<servlet> <servlet-name>XFireServlet</servlet-name> <servlet-class> Org.codehaus.xfire.transport.http.XFireConfigurableServlet </servlet-class> </servlet> < Servlet-mapping> <servlet-name>XFireServlet</servlet-name> <url-pattern>/servlet/ xfireservlet/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name> Xfireservlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping>

4 Add an implementation class for the interface and interface:

The interface code is as follows:

Public interface HelloWorldService {public String sayhello ();}

The interface implementation classes are as follows:

public class Helloworldserviceimpl implements HelloWorldService {public String SayHello () {System.out.println ("Hello Wo Rld! "); Return "Hello world!"; } }

5 in SRC under a new folder called Meta-inf, and then under Meta-inf under the new name Xfire folder, the last Xfire under the new Services.xml file, Services.xml file contents are as follows:

<beans xmlns= "http://xfire.codehaus.org/config/1.0" > <service> <name>helloworldservice</name > <namespace>http://127.0.0.1/xfire/HelloWorldService</namespace> <serviceclass>com. Helloworldservice</serviceclass> <implementationclass>com. Helloworldserviceimpl</implementationclass> </service> </beans>

The Services.xml tags function as follows:

Service: the service tag and the XML content it contains provide a complete description of the POJO that is published as a Web service.

Name: The unique name to use when the Web service is published.

namespace: The namespace that is used when the Web service is published.

ServiceClass: The full name of the Web service interface class, including the package name and class name.

Implemetationclass: The full name of the Web service implementation class, including the package name and class name.

6 in the browser URL bar input

HTTP://LOCALHOST:9999/XFIRE/SERVICES/HELLOWORLDSERVICE?WSDL, if everything works, the following pages will be returned:

Description: This is a tomcat server, if not installed, please install it yourself.

3. generation of XFire clients

There are several ways to generate a client, in this column, in two ways: one is to create a dynamic client through WSDL, and the other is to use the Ant tool to generate a client through WSDL. The following is an introduction to the specific application of the two methods.

1) Dynamic Client

public class Test {public static void main (string[] args) throws Malformedurlexception, Exception {long start = SYSTEM.C Urrenttimemillis (); Client client = new Client (new URL ("http://localhost:9999/xfire/services/HelloWorldService?wsdl")); Object[] results = Client.invoke ("SayHello", New object[]{}); System.out.println ("Call a total of flowers" + (System.currenttimemillis ()-start) + "milliseconds"); System.out.println (Results[0]); } }

In this way, you only need to know the WSDL address, and the method name and method need the required parameters.

2 Ant Build Client

Create a new Java project, under the project to create a new package called COM, and then under the root of the project to create a new build.xml, Build.xml file details are as follows:

<?xml version= "1.0" encoding= "UTF-8"?> <project default= "Genfiles" basedir= "." > <property name= "Lib" value= "Webroot/web-inf/lib"/> <path id= "Myclasspath" > <fileset dir= "${lib}" > <include name= "*.jar"/> </fileset> <pathelement location= "${genfiles}"/> </path> < Property Name= "Code_path" value= "src"/> <property name= "Wsdl_path" value= services/helloworldservice?wsdl "/> <property name=" code_package "value=" com "/> <target name=" Genfiles " description= "Generate the Files" > <echo> generating xfire clients </echo> <taskdef name= "Wsgen" Classname= " Org.codehaus.xfire.gen.WsGenTask "classpathref=" Myclasspath "/> <wsgen outputdirectory=" ${code_path} "wsdl=" $ {Wsdl_path} "package=" ${code_package} "binding= XMLBeans" overwrite= "true"/> </target </project>

Finally execute the ant build, and after successful execution, create a new HelloWorldTest class, as follows:

Public class HelloWorldTest {public static void main (string[] args) {helloworldserviceclient client = new HelloWorld ServiceClient (); Helloworldserviceporttype service = Client.gethelloworldservicehttpport (); String result = Service.sayhello (); System.out.println ("Results:" + result);}

Resources

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.