|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
Web Services How to Develop with an Emerging Standard, Today
How to Develop with an Emerging Standard, Today
By: Mike Lehmann
Jan. 1, 2000 12:00 AM
Click here for FREE software from Oracle http://www.oracle.com/go/?&Src=1170761&Act=6
Introduction
In this paper we will hope to provide a jump-start to both these questions. We will run through the basics of building Web services using the following steps:
Web Services Overview
These standards are Internet friendly and enable easy distributed programming calls across the Internet, as compared to more internally focused protocols like J2EE RMI (Remote Method Invocation), Net9i (Oracle9i Database network protocol) and DCOM (Microsoft's distributed component model protocol). Business logic performed by Web service applications can be written in any language including Java and PL/SQL. In fact, much of the development cycle including modeling, programming, security and the underlying component model do not change with Web services. What does change is that additional steps are done to describe it (WSDL), to access it (SOAP) and to publish it (UDDI). Figure 1 provides an overview of a Web service in action.
Figure 1: Web Services with SOAP, WSDL and UDDI Web services are often touted as a radically new concept; in fact, conceptually they are very similar to other distributed programming models such as J2EE, Corba and DCOM. One important difference, however, is that Web service standards are really just an XML metadata layer on top of an application implementation, describing the underlying application. They are not standards for developing business logic or processes; they merely describe it. For example, using CORBA as an analogy, it is possible to liken the Interface Definition Language (IDL) to WSDL - both describe the services that will be implemented by the business logic and the interfaces necessary for clients to call the business logic. They are not the application logic or process. CORBA's remote invocation protocol is called Internet Inter-ORB Protocol, which is conceptually comparable to SOAP. Both provide ways of marshalling and un-marshalling arguments - in SOAP's case underlying marshalling language happens to be XML. CORBA's Naming Service (Cos Naming) and Interoperable Object References (IOR) provide a way to locate individual CORBA objects whereas the combination of WSDL and UDDI standards provide similar ways to locate Web services. What tends to be revolutionary about Web services is the ease in which they enable distributed component models to interact programmatically, particularly across the Internet using protocols like HTTP. By focusing initially on simplicity and interoperability Web services have garnered significant support, adoption and innovation across the industry. Interestingly, with simple Web services now well underway to becoming a popular development approach, much interest and impetus has been started in the area of complex Web services. Complex Web services take the foundation standards of SOAP, WSDL and UDDI and move them to higher level business processes that have requirements for long running transactions, asynchronous interactions, authentication, encryption and non-repudiation. In this area Web services vendors like Oracle are leveraging the knowledge and standards of ebXML (Electronic Business XML) and RosettaNet as well as real life business process knowledge from its E-Business Suite line, where much work has been previously done in implementing complex business processes in thousands of implementations.
Building and Assembling Web Services Web services add additional requirements on the development environment such as publishing and consuming Web services, locating and introspecting Web services and finally composing and orchestrating Web services. For maximum productivity these should be features in the standard development environment rather than separate un-integrated tools. This is the vision behind Oracle9i JDeveloper. Oracle9i JDeveloper is a Java IDE completely written in Java. It is available on Windows, Solaris and Linux. It has all the enterprise features described above for J2EE development but has combined them with rich Web service capabilities throughout the product.
Using Oracle9i JDeveloper to Build Web Services One of the important values that tools like activity modellers offer beyond visualizing the business process is the ability to extend simple Web services (e.g. remote procedure calls) into complex Web services where a series of Web services are invoked, sequenced and coordinated with other Web services and non-Web service applications. Creating complex Web services also necessitates an infrastructure that can deal with event handling, asynchronicity, parallel processing and notifications. Oracle9i JDeveloper, for example, enables developers to use its activity modeller to generate business processes with these capabilities for Web services using the workflow engine and the integration capabilities offered by Oracle9i Application Server. Figure 2 provides an example Web service scenario built in the Oracle9i JDeveloper Activity Modeller. The scenario illustrates three Web service processes: a Trip Planning Service, a Trip Costing Service and Trip Booking Service. At this stage, no details are provided behind the activities in each process; however, the rest of this paper focusses on providing a J2EE Web service centric implementation of this activity model.
Figure 2: Modeling Web Services in the Oracle9i JDeveloper Activity Modeller
Building a Web Service Based on an EJB
Figure 3: Using Oracle9i JDeveloper to Declaratively Build an EJB The implementation code of the findFlight method is provided in Listing 1. This code shows the retrieval of flights names from a TRAVEL database schema via a SQL statement that takes the origin and destination airport as parameters. This is traditional java code that a typical J2EE developer would have little difficulty constructing. Listing 1: The findFlight Method ImplementationDepending on the type of Java application developed different J2EE archive deployment options can be used: Enterprise Java Bean JAR files for EJB's, Web Archive files for web applications and ordinary JAR files for simple Java classes. Oracle9i JDeveloper makes deployment easy by providing graphical tools for configuring the J2EE descriptors and by making the actual deployment process a single mouse click. This point and click deployment is provided for the Oracle9i Application Server Containers for J2EE and other third party application servers like BEA Weblogic. Figure 4 shows the deployment options available in Oracle9i JDeveloper and Figure 5 shows the user experience deploying Enterprise Java Beans for the TravelSearchEJB built here.
Figure 4: Oracle9i JDeveloper J2EE Deployment Options
Publishing an EJB Web Service
Figure 6: Selecting the Web Service Tool
To deploy the Web service, the metadata collected by the Web service wizard has to be packaged and deployed to the application server. For Web services published to the Oracle9i Application Server Containers for J2EE, this metadata is packaged as a J2EE web.xml file and deployed using a standard WAR file. The web.xml file configures a servlet, automatically generated by Oracle9i Application Server during the deployment process, which converts incoming SOAP messages to calls to the underlying EJB and the outgoing results back into SOAP messages . The WAR deployment process is a one-click deployment as shown in Figure 10.
Figure 10: One Click Web Service Deployment to Oracle9i Application Server It is correct to conclude that with Oracle9iAS Web Services each Enterprise Java Bean has its own auto-generated servlet for marshalling and unmarshalling SOAP messages. In the case when Apache SOAP is selected, the Oracle9i JDeveloper Web service wizard will generate a deployment descriptor required to register the Web service with Apache SOAP. Unlike the Oracle9iAS Web Services, Apache SOAP uses a single generic servlet for handling SOAP messages and as such requires the descriptor to map each SOAP service's to the underlying component. Figure 11 shows the registration process for Apache SOAP Servers of the automatically generated SOAP descriptor for the TravelSearchEJB EJB.
Figure 11: One Click Apache SOAP Service Deployment from Oracle9i JDeveloper In both cases, the work required by the developer is to invoke the Web service wizard, choose the Enterprise Java Bean and methods to be published as Web services and then a single click to deploy to the Web services infrastructure. This is a simple publishing process, leaving the developer free to focus on the application itself, rather than Web service idiosyncracies.
Working with WSDL
The question is where does a developer find a WSDL file? There are a number of standard places one can get a WSDL file. For existing Web services, a common place to look is popular Web service registries like XMethods (Error! Bookmark not defined.) and SalCentral (Error! Bookmark not defined.). These sites and others often publish lists of publicly available Web services and their correspondingWSDL files as URL's and more recently have been making their Web service lists available to UDDI inquiries. For those who already have a Web services infrastructure, internal UDDI registries are where the WSDL files can be located. Oracle9i Application Server, for example, includes a UDDI Registry as a feature of its Web services implementation. For new or existing J2EE applications, like the TravelSearchEJB example used in this paper, the Oracle9i JDeveloper Web service wizard automatically generates the WSDL file. Figure 12 shows the WSDL generated for the sample Enterprise Java Bean created in this paper.
Figure 12: Editing the WSDL Generated by the Oracle9i JDeveloper Web Service Tool For Web services deployed to Oracle9i Application Server, an additional option is available to retrieve the WSDL. The servlet that is automatically created during the Web service deployment accepts a WSDL argument and will produce the WSDL on demand. For example, for the TravelSearchEJB Web service, the WSDL could be retrieved from the URL: http://localhost:8888//Travel-context-root/urn:ws.TravelSearchEJB?WSDL This can be useful for developers wanting to access the Web service WSDL stand-alone, outside of Oracle9i JDeveloper. There can be times when developers would like to fine tune a WSDL file, perhaps as part of the process defining a Web service before implementing it, or to handle complex parameters. Oracle9i JDeveloper facilitates the creation and editing of WSDL files by offering a Schema Driven XML editor and a WSDL creation tool. Oracle9i JDeveloper's XML editor allows XML Schemas to be registered such that the editor can provide code insight while editing XML Schema constrained documents. Figure 12, in addition to showing the TravelSearchEJB Web service WSDL file, shows WSDL file editing with code insight in action, the XML document structure navigator and the XML property editor functionality of Oracle9i JDeveloper. Figure 13 shows the ability to register schemas in Oracle9i JDeveloper. By default, the schema for WSDL and other common XML Schemas are pre-registered out-of-the-box.
Figure 13: Schema Driven Editor Configuration
Building a Web Service Client
Figure 14: Selecting the Web Service Stub/Skeleton Tool
The stub that is generated from the Web Service Stub/Skeleton Wizard is a simple Java class that marshals and un-marshals SOAP messages from the Web service itself, without knowing anything about the Web service implementation. In the example used in this paper, the method findFlight method of the TravelSearchEJB EJB accepts a string parameter containing the origin airport and destination airport as parameters and returns an array of matching flights. The Web service client, or stub, converts incoming Java parameters into SOAP messages to send to the Web service, and, in reverse, converts the Web service SOAP results into Java equivalents. Listing 2 shows the Java stub generated from a WSDL file.
Listing 2: An Apache SOAP Client Automatically
package ws;
public TravelSearchEJBStub()
public String[] findFlight(String origin, String dest) throws Exception
URL endpointURL = new URL(endpoint);
Response response = call.invoke(endpointURL, "");
return returnVal;
public boolean getMaintainSession()
public void setTransportProperties(Properties props)
public Properties getTransportProperties() Note, developers are not expected to maintain this Web service stub. As shown in Figure 17, Oracle9i JDeveloper can regenerate the Web service stub via a simple right mouse click, should the WSDL file ever be updated. Also, for Web services deployed to Oracle9i Application Server, an additional option is available to retrieve the stub. The servlet that is automatically created during the Oracle9i Application Server Web service deployment accepts a proxy_source argument and will produce the Java stub on demand. For example, for the TravelSearchEJB Web service, the Java stub could be retrieved from the URL: http://localhost:8888//Travel-context-root/urn:ws.TravelSearchEJB?proxy_source This second approach can be useful for developers wanting access the stub independent of Oracle9i JDeveloper.
Figure 17: One-Click Re-Generation of the SOAP Service Stub Calling this TravelSearchEJB Web service stub from within an application, Java Server Page or even an Enterprise Java Bean is the final step. Figure 18, shows calling the stub and illustrates Oracle9i JDeveloper code insight while writing the JSP scriptlet to call the TravelSearchEJB Web service.
Figure 18: Java Server Page Code Insight While Calling a Web Service in Oracle9i JDeveloper The end result of building a client, in this case a JavaServer Page, to the Web service looks remarkably like an ordinary application. Figure 19 shows the finished client returning Web service results. The differences, however, are two fold:
Figure 19: Running a Java Server Page as a Web Service Client
Incorporating 3rd Party Web Services
In this case the Trip Costing process will be implemented as a simple currency conversion activity. One approach to save time and effort would be to use an external Web service that specializes in currency conversion and then incorporate it into the application flow. Fortunately, there are several currency conversion services available on the Internet exposed as Web services. One, illustrated in Figures 20 and 21, shows how such services are published and advertised on web sites like XMethods.
Figure 20: A Currency Conversion Service on the Web Site Xmethods
The steps to incorporate the currency conversion Web service into the overall travel application are very straightforward:
Figure 22: Defining the URL location of the Currency Conversion WSDL
Then, like with the TravelSearchEJB example, the call to the currency conversion Web service can be incorporated into a JavaServer Page, or for that matter, any other J2EE component. Figure 23 shows the JavaServer Page call to the currency conversion Web service call. Figure 24 shows running a JavaServer Page combining both the TravelSearchEJB Web service and the currency conversion Web service.
Figure 24: Running the Combined Travel Service and Currency Conversion Service
More Web Service Choices
Business Components for Java is a J2EE framework built from industry best practices that helps developers rapidly construct, high quality and fast performing J2EE applications. It provides a graphical workbench for object relational mapping, declarative business logic and a presentation-binding layer for XML, JSP and Swing clients. Components developed in the framework are typically coarse-grained business objects that are deployed as Enterprise Java Beans and, as such, can be exposed as Web services using the same Oracle9i JDeveloper tools discussed in this paper. Many businesses using the Oracle Database have a significant investment in PL/SQL and are looking to Web services as a way to leverage that investment with a new audience. Oracle9i JDeveloper caters to the PL/SQL developer by providing a full PL/SQL development and debugging environment. To help expose stored procedures as Web services, Oracle9i JDeveloper also has built-in a utility called JPublisher that can, through a single mouse-click, wrap any PL/SQL stored procedure in a Java class. Once wrapped as a Java class, a PL/SQL stored procedure can be published as a Web service, again using the same Oracle9i JDeveloper Web service tools discussed in this paper.
Conclusion
Click here for FREE software from Oracle http://www.oracle.com/go/?&Src=1170761&Act=6
Web Services for J2EE: How to Develop for an Emerging Standard Today Reader Feedback: Page 1 of 1
Your Feedback
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||