Use xfire to build a Java WebService Application

Source: Internet
Author: User

At present, there seem to be two WebService developers in Java: xfrie and axis. Of course, there may be many jwsdp of sun, But I know xfrie1.2 of myeclipse5.5.1, of course, it has never been used in practical applications. Writing it is a reference.

Xfire is a free open-source soap framework that helps you quickly develop Java-based WebService applications. Free you from tedious WebService configurations. You no longer need to understand how the WebService works. You only need to focus on how to better implement your business logic.

Now let's start our xfire application journey. First, download xfire from xfire.codehaus.org. Here we select version 1.2.6. For JDK 1.5, go to the official website of Sun (java.sum.com). For the web server, go to Tomcat .apache.org to download the latest version.

1. install Tomcat

Select default for all configurations. After installation, the Tomcat root directory is usually C:/program files/Apache Software Foundation/tomcat 6.0. Use the resource browser and navigate to the Tomcat service directory, c:/program files/Apache Software Foundation/tomcat 6.0/wabapps create your own application directory under the directory name. I name it Bos here.

2. Create business functions

For simplicity, we use the conventional helloworld. First, define an interface. This interface is used to provide external services. It can be said that it is an external interface! Then implement a class for this interface. The Code is as follows:

// Interface

Package com.hk. Bos. xfire;

Public interface ihelloworld {

Public String showmessage (string message );
}

// Implement class

Package com.hk. Bos. xfire;

Public class helloworld implement ihelloworld {

Public String showmessage (string message ){

System. Out. println ("the client message:" + message );

}
}

Now that the business functions are created, let's start xfire configuration!

3. xfire Configuration

Return to the application directory created in step 1. In this example, C:/program files/Apache Software Foundation/tomcat 6.0/wabapp/Bos.

Create two folders in this directory: classes and Lib, and then create a file named Web. xml. The content of this file is as follows:

<? XML version = "1.0" encoding = "ISO-8859-1"?>
<! -- Start snippet: webxml -->
<! Doctype web-app
Public "-// Sun Microsystems, Inc. // DTD web application 2.3 // en"
Http://java.sun.com/dtd/web-app_2_3.dtd>

<Web-app>

<Servlet>
<Servlet-Name> xfireservlet </servlet-Name>
<Display-Name> xfire servlet </display-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>

</Web-app>

Do you see anything? Yes, this is the standard configuration of servlet. It means that all prefixes are: http: // yourserver: Port/Bos/servlet/xfireservlet/and http: // yourserver: port/Bos/services requests are handled by xfireservlet, and this servlet is developed for us by xfire, so we do not have to make any modifications.

Copy all the lib packages used by your application (including all the support packages used by xfire) to the lib directory you just created.

Go to the classes directory you just created, create the following hierarchical directory META-INF/xfire directory, and then create a file named services. XML in this directory. The file content is as follows:

<Beans xmlns = "http://xfire.codehaus.org/config/1.0">
<Service>
<Name> helloworld </Name>
<Namespace> http://www.boshk.com/HelloWorld </namespace>
<Serviceclass>
Com.hk. Bos. xfire. helloworld </serviceclass>
<Implementationclass>
Com.hk. Bos. xfire. helloworld
</Implementationclass>
</Service>
</Beans>

This is the configuration information used by xfireservlet, indicating that you should know the information without saying it. Name indicates the name of a single service, which will be called externally. Namespace. Serviceclass service class, which is the external service interface we created earlier. Implementationclass Service implements class. Of course, if you need multiple services, you only need to add one more service node here. Simple enough :)

Let's test it! Start the Tomcat service. Open your browser and enter http: // yourserver: Port/Bos/services/helloworld. If no error occurs, a complete XML file is displayed on the webpage, which contains all the information for the client to call.

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.