2008年(12)
分类: Java
2008-05-20 19:04:24
| ||
Outline | ||
1. PrefaceThis document was written using Sun Java 5, Eclipse 3.2 and MyEclipse 5.0.0. All screenshots are based upon the default user interface settings for Eclipse, MyEclipse, and Windows XP. If you experience difficulty with the instruction of this document, please see the section for how to provide feedback to the MyEclipse documentation team. | ||
2. RequirementsFollowing are the basic MyEclipse Web Services prerequisites:
| ||
3. IntroductionThis tutorial introduces the process for using MyEclipse web services feature-set to quickly develop and testing a HelloWorld web service using a "code-first" web service development strategy. The code-first strategy concentrates development priorities and effort towards developing application business logic prior to addressing the web service interfacing requirements of the service. Typcially code-first projects will design and implement the Java beans (POJOs) responsible for the core business use-cases. Once satisfied with the POJO implementation, the web service interface will be designed and implemented to expose the public POJO services. This approach is considered ad-hoc by many and is best utilized for prototyping or small standalone system of services. What is covered in this tutorial?
| ||
3.1 XFire Java SOAP Framework OverviewMyEclipse web service features are built on top of the XFire Java SOAP framework and tools. XFire was adopted because of its growing list of basic and advanced features, high performance runtime, rapidly growing community of adopters, and its generous open source license. Some of its key features include:
To view a full list of XFire features visit the site. | ||
4. Creating a Web Service Project
MyEclipse 5.0 introduces a new type of project know as a Web Services Project. This type of project extends the MyEclipse Web Project to support additional web services configuration, development and deployment concerns. This section demonstrates how to use the MyEclipse Web Services Project wizard to create and configure new web service projects. The Web Service Wizard performs the following actions:
| ||
Begin by launching the Web Service Project wizard. This wizard consists of three pages. Page-1 collects Web Project configuration details. Page-2 collects the XFire configuration details. And page-3 configures the XFire libraries on the new project's build path.
![]() Figure-1: New Project Wizard Launcher
![]() Figure-2: Page-2, Collecting web configuration details
![]() Figure-3: XFire servlet and services.xml configuration
![]() Figure-4: Selecting XFire libraries to add to new web service project buildpath
![]() Figure-5: Web services artifacts of a new web service project | ||
5.0 Creating a Web Service - Code-first StrategyThis section demonstrates use of the MyEclipse Web Service Wizard to create an example HelloWorldService using the code-first strategy. Note that we will take advantage of the XFire's built in Aegis Java-XML binding framework. This Java-XML binding strategy is convenient for handling simple type conversion. In cases where a web service operation must accept or return complex structured information additional work maybe required. Please review the Aegis binding documentation for use of Aegis class mapping files.
Method-1: Launch wizard from MyEclipse perspective toolbar
Choose the New Web Service button Method-2: Launch wizard from workbench menubar
![]() Figure-6: Launching Web Service Wizard
![]() Figure-7: Page-1 of new web service wizard
![]() Figure-8: Page-2 of new web service wizard. The wizard generates the IHelloWorldService Java interface and the HelloWorldServiceImpl Java class, and creates a ![]() Figure-9: Newly created HelloWorld interface and implementation class | ||
6.0 Deploying a Web Service ProjectBefore you can interact with you web service it must be deployed to an application server. The MyEclipse web service project is an extended version of the MyEclipse web project. This fact enables a web service to be deployed to any J2EE application server supported by MyEclipse. This section demonstrates the tools and steps to deploy the HelloWorld project to a Tomcat 5 web container. | ||
6.1 Configuring the Application Server ConnectorThe setup and configuration of the Tomcat 5 application server connector is defined in the . If you already have a configured application server connector please proceed to the next section. | ||
6.2 Deploying the HelloWorld Web Service Project
Figure-10 below provides a visual outline of the 3 steps required to deploy the HelloWorld application using the MyEclipse J2EE Application Deployer.
The new HelloWorld WAR deployment will appear under the Tomcat 5 node in the Server Manager view (see Figure 11). ![]() Figure-11: Servers Manager View depicting deployed HelloWorld web service project | ||
7. Starting the Tomcat ServerWith the HelloWorld project deployed to Tomcat, we need to launch Tomcat if it is not already running. If the server is running the HelloWorld webapp will be automatically loaded and made accessible. To launch Tomcat choose either the debug launch-mode button or the run launch-mode button (see highlighted buttons in Figure-12). We recommend that you use the debug mode as it enables you to dynamically set breakpoints and hot-swap debug the Java implementation of your web service. ![]() Figure-12: Server Manager before Tomcat 5 launch A Tomcat starts up can monitor its start up progress in the Eclipse console view. ![]() Figure-13: Eclipse console view depicting real-time Tomcat 5 status info Once Tomcat is launched and fully initialized the Server Manager will update to reflect the server's execution status and mode. ![]() Figure-14: Server Manager showing active status of Tomcat 5 | ||
8. Testing a Web Service with the Web Service ExplorerMyEclipse provides a Web Services Explorer for testing a web service. The Web Services Explorer enables you to interface with any web service given a WSDL document that describes the service.
![]() Figure-15: Web Services Explorer launch button on workbench toolbar
![]() Figure-16: Web Services Explorer testing HelloWorldService To test other online web services with the Web Services Explorer visit the . The UDDI endpoint is found at . | ||
9. Creating a Java Test ClientXFire provides a dynamic proxy framework that will read a WSDL document and create the underlying messaging services to enable a Java class to execute actions on a web service. This section provides quick outline of what is required to develop a Java web service client to the HelloWorld web service. | ||
9.1 Additional XFire Library ConfigurationFor our example client we will create the class in the HelloWorld project. If you have not done so already you need to add the XFire HTTP Client Libraries to the build-path of the project that will contain your Java test client.
![]() Figure-17: Choosing the XFire HTTP Client Libraries Select Finish | ||
9.2 Create the HelloWorldClient ClassLaunch the Java class wizard and create the class HelloWorldClient. ![]() Figure-18: HelloWorldClient defined in New Java Class Wizard. The code segment below defines the process for creating an XFire web service proxy that supports the POJO IHelloWorldService interface. Once the proxy has been constructed and cast to the IHelloWorldService it can be used like a standard Java class.
Launch and execute this class using the right-click Run As>Java Application or Debug As>JavaApplication context-menu actions. | ||
10. FAQQ1: Does XFire support WS-1 basic profile? A1: Yes, this is the default XFire configuration. Q2: What is the default XFire WISDL-SOAP binding style and encoding use mode? A2: The default XFire binding style and encoding mode is document literal wrapped. See Resources for more information. Q3: I'm using the default Aegis Java-XML binding and experience a runtime exception when I pass a complex Java object and return a list of complex Java objects to a Java bean exposed as a web service. How do I do this? A3: Aegis provides a default mapping support for Java-XML binding. But it in cases where a parameter or return value is a complex type (e.g., an aggregate object) or ambiguous (e.g., a Java Collection) you must provide Aegis additional mapping information. Please see the documentation for more information. | ||
11.
| ||
12. User FeedbackIf you have comments or suggestions regarding this document please submit them to the If you have comments or suggestions regarding this document please submit them to the MyEclipse Documentation Forum. |