|
|
Want to know more about Packt's Article Network? Interested in contributing your article ideas? Please visit our FAQ for more information. See More BROWSE
All Titles WordPress Web Services SOA BPEL Web Graphics & Video Web Development RAW Portugues, Espanol, Italiano, French PHP/MySQL Oracle Open Source Networking & Telephony Moodle Microsoft & .NET Linux Servers jQuery Joomla! JBoss Java e-Learning e-Commerce Dynamics Drupal CRM Cookbook Content Management Beginner Guides Architecture and Analysis AJAX Future Titles Recently Published Titles |
Binding Web Services in ESB—Web Services Gateway
Web ServicesWeb services separate out the service contract from the service interface. This feature is one of the many characteristic required for an SOA-based architecture. Thus, even though it is not mandatory that we use the web service to implement an SOA-based architecture, yet it is clearly a great enabler for SOA. Web services are hardware, platform, and technology neutral The producers and/or consumers can be swapped without notifying the other party, yet the information can flow seamlessly. An ESB can play a vital role to provide this separation. Binding Web ServicesA web service's contract is specified by its WSDL and it gives the endpoint details to access the service. When we bind the web service again to an ESB, the result will be a different endpoint, which we can advertise to the consumer. When we do so, it is very critical that we don't lose any information from the original web service contract. Why Another Indirection?There can be multiple reasons for why we require another level of indirection between the consumer and the provider of a web service, by binding at an ESB. Systems exist today to support business operations as defined by the business processes. If a system doesn't support a business process of an enterprise, that system is of little use. Business processes are never static. If they remain static then there is no growth or innovation, and it is doomed to fail. Hence, systems or services should facilitate agile business processes. The good architecture and design practices will help to build "services to last" but that doesn't mean our business processes should be stable. Instead, business processes will evolve by leveraging the existing services. Thus, we need a process workbench to assemble and orchestrate services with which we can "Mix and Match" the services. ESB is one of the architectural topologies where we can do the mix and match of services. To do this, we first bind the existing (and long lasting) services to the ESB. Then leverage the ESB services, such as aggregation and translation, to mix and match them and advertise new processes for businesses to use. Moreover, there are cross service concerns such as versioning, management, and monitoring, which we need to take care to implement the SOA at higher levels of maturity. The ESB is again one way to do these aspects of service orientation. HTTPHTTP is the World Wide Web (www) protocol for information exchange. HTTP is based on character-oriented streams and is firewall-friendly. Hence, we can also exchange XML streams (which are XML encoded character streams) over HTTP. In a web service we exchange XML in the SOAP (Simple Object Access Protocol) format over HTTP. Hence, the HTTP headers exchanged will be slightly different than a normal web page interaction. A sample web service request header is shown as follows: GET /AxisEndToEnd/services/HelloWebService?WSDL HTTP/1.1 The first line contains a method, a URI and an HTTP version, each separated by one or more blank spaces. The succeeding lines contain more information regarding the web service exchanged. ESB-based integration heavily leverages the HTTP protocol due to its open nature, maturity, and acceptability. We will now look at the support provided by the ServiceMix in using HTTP. ServiceMix's servicemix-httpBinding external web services at the ESB layer can be done in multiple ways but the best way is to leverage JBI components such as the servicemix-http component within ServiceMix. We will look in detail at how to bind the web services onto the JBI bus. servicemix-http in Detailservicemix-http is used for HTTP or SOAP binding of services and components into the ServiceMix NMR. For this ServiceMix uses an embedded HTTP server based on the Jetty. The following are the two ServiceMix components:
As of today, these components are deprecated and the functionality is replaced by the servicemix-http standard JBI component. A few of the features of the servicemix-http are as follows:
Since servicemix-http can function both as a consumer and a provider, it can effectively replace the previous HttpInvoker and HttpConnector component. Consumer and Provider RolesWhen we speak of the Consumer and Provider roles for the ServiceMix components, the difference is very subtle at first sight, but very important from a programmer perspective. The following figure shows the Consumer and Provider roles in the ServiceMix ESB: The above figure shows two instances of servicemix-http deployed in the ServiceMix ESB, one in a provider role and the other in the consumer role. As it is evident, these roles are with respect to the NMR of the ESB. In other words, a consumer role implies that the component is a consumer to the NMR whereas a provider role implies the NMR is the consumer to the component. Based on these roles, the NMR will take responsibility of any format or protocol conversions for the interacting components. Let us also introduce two more parties here to make the role of a consumer and a provider clear—a client and a service. In a traditional programming paradigm, the client interacts directly with the server (or service) to avail the functionality. In the ESB model, both the client and the service interact with each other only through the ESB. Hence, the client and the service need peers with their respective roles assigned, which in turn will interact with each other. Thus, the ESB consumer and provider roles can be regarded as the peer roles for the client and the service respectively. Any client request will be delegated to the consumer peer who in turn interacts with the NMR. This is because the client is unaware of the ESB and the NMR protocol or format. However, the servicemix-http consumer knows how to interact with the NMR. Hence any request from the client will be translated by the servicemix-http consumer and delivered to the NMR. On the service side also, the NMR needs to invoke the service. But the server service is neutral of any specific vendor's NMR and doesn't understand the NMR language as such. A peer provider role will help here. The provider receives the request from the NMR, translates it into the actual format or protocol of the server service and invokes the service. Any response will also follow the reverse sequence. Service Oriented Java Business Integration
servicemix-http XBean ConfigurationThe servicemix-http components supports the XBean-based deployment. Since the servicemix-http component can be configured in both the consumer and provider roles, we have two sets of configuration parameters for the component. Let us look into the main configuration parameters:
servicemix-http Lightweight ConfigurationIn addition to the XBean-based configuration, servicemix-http can also be deployed based on the lightweight mode to use in an embedded ServiceMix. The configuration would be as follows: <sm:activationSpec> Web Service Binding SampleWe will now look at a complete sample of how to bind a web service to the ServiceMix. While doing so, we will also see how to use the Apache Axis client-side tools to generate stubs based on the binding at ServiceMix. Normally we point to the actual WSDL URL to generate client stubs, but in this example we will point the tools to the ServiceMix binding. Then the ServiceMix binding will act completely as the web service gateway visible to the external clients, thus shielding the actual web service in the background. Sample Use CaseBy using a web services gateway, you can use the intermediation to build and deploy the web services routing application. But keep in mind that the routing is just one of the various technical functionalities that you can implement at the gateway. For our sample use case, we have an external web service, deployed and hosted in a node remote to the ESB. In the ESB, we will set up a Web Services Gateway, which can proxy the remote web service. The entire setup is shown in the following figure: Along with the previous discussion, we need the servicemix-http in the consumer and provider roles. MyConsumerService is a servicemix-http component in the consumer role and IHelloWebService is a servicemix-http component in the provider role. Both of them are shown in the following figure: Let us now take a closer look at the gateway configured in the ESB. Here, we configure servicemix-http in both the consumer and provider roles and hook it to the NMR. Any client requests are intercepted by the consumer and the consumer then sends the request on behalf of the client to the NMR. From there the request will be routed to the destination web service through the provider. The message flow is marked in sequence in the following figure: Service Oriented Java Business Integration
Deploy the Web ServiceAs a first step, edit examples.PROPERTIES (you can download this file from the location http://www.packtpub.com/files//code/4404_Code.zip. Unzip the zip file and you will find examples.PROPERTIES in the folder named Chapter_10), and change the paths there to match your development environment. It also includes a README.txt file, which gives detailed steps to build and run the samples. Also all the required files mentioned in this article will be found in the same folder Chapter_10 We have a simple web service in the codebase present in the folder ch10\ServiceMixHttpBinding\01_ws. To deploy the web service, first change directory to the ch10\ServiceMixHttpBinding folder and execute the ant command as follows: cd ch10\ServiceMixHttpBinding In fact, the build.xml file will call the build in the subprojects to build the web service as well as the ServiceMix subproject. The web service is built completely and the war file can be found in the folder ch10\ServiceMixHttpBinding\01_wsdistAxisEndToEnd.war. To deploy the web service, drop this war file into your favorite web server's webapps folder and restart the web server, if necessary. Now to make sure that your web service deployment works fine, we have provided a web service test client. To invoke the test client, execute the following commands: cd ch10\ServiceMixHttpBinding\01_ws We can also check the web service deployment by accessing the WSDL from the URL: http://localhost:8080/AxisEndToEnd/services/HelloWebService?WSDL Let us list out the WSDL here, since we want to compare it with the WSDL accessed from the ServiceMix binding later to cross check the similarities. This is provided in ch10\ServiceMixHttpBinding\HelloWebService-axis.wsdl <?xml version="1.0" encoding="UTF-8"?> XBean-based servicemix-http BindingFor XBean-based deployment of servicemix-http, our xbean.xml matches the following: <beans xmlns:http="http://servicemix.apache.org/http/1.0" xmlns:test="http://AxisEndToEnd.axis.apache.binildas.com"> The previous execution of ant has already built and packaged the service assembly for the sample. Deploying and Running the SampleTo deploy the ServiceMix sample, we have the following servicemix.xml: <?xml version="1.0" encoding="UTF-8"?> To bring up the ServiceMix, change directory to ch10\ServiceMixHttpBinding and execute the ServiceMix script as follows. cd ch10\ServiceMixHttpBinding We can now test our ServiceMix deployment by using the following test client: ch10\ServiceMixHttpBinding\Client.html Access WSDL and Generate Axis Stubs to Access the Web Service RemotelyNow for the really cool stuff. As we discussed earlier, we have set up the ServiceMix as a separate web service gateway in front of the actual web service deployment. Now we have to check whether we can access the WSDL from the ServiceMix. For this, we can point our browser using the standard WSDL query string, like: http://localhost:8081/services/HelloWebService/?wsdl Note that, the above URL points to the locationURI attribute configured for the consumer component, which is http://localhost:8081/services/HelloWebService. The WSDL placed in location ch10\ServiceMixHttpBinding\HelloWebService-esb.wsdl, matches the following code: <?xml version="1.0" encoding="UTF-8"?> If we compare the two WSDL, the major difference is in the service description section. Here, ServiceMix forms the service and port name taking values from service and endpoint attributes of the consumer service—MyConsumerService and HelloWebService respectively. If we are able to retrieve the WSDL, the next step is to use the Apache Axis tools to auto-generate the client-side stubs and binding classes, using which we can write simple Java client code to access the service through HTTP channel. The Axis client classes are placed in the directory ch10\ServiceMixHttpBinding\03_AxisClient. To do that, we have to use the wsdl2java ant task. Let us first declare the task definition and execute that task to generate the stub classes. <taskdef name="wsdl2java" classname="org.apache.axis.tools.ant.wsdl.Wsdl2javaAntTask" loaderref="axis" > The task will extract the WSDL from the specified location and generate the following client-side artifacts: combinildasapacheaxisAxisEndToEndHelloWebServiceBindingStub.java The Client Java class can be written against these generated files as follows: public class Client To build the entire Axis client codebase, assuming that the ServiceMix is up and running, change directory to ch10\ServiceMixHttpBinding\03_AxisClient, which contains a build.xml file. Execute ant as shown as follows: cd ch10\ServiceMixHttpBinding\03_AxisClientant This will generate the required Axis client-side stubs and compile the client classes. Now to run the client, execute the following command: ant run SummaryWe started this article by introducing the servicemix-http JBI component. Then we looked at the samples of binding web services to ESB using the servicemix-http binding component. By doing so, we have, in fact, implemented a complete functional web services gateway at the ESB. A lot of times, we utilize this pattern to expose useful web services hosted deep inside your corporate networks protected by multiple levels of firewall. When we do so, the web services gateway is the access point for any external client. It should mock the actual web service not only in providing the functionality but also in exposing the web services contract (WSDL). Service Oriented Java Business Integration
About the AuthorBinildas A. Christudas Binil is a Sun Certified Programmer (SCJP), Developer (SCJD), Business Component Developer (SCBCD) and Enterprise Architect (SCEA), Microsoft Certified Professional (MCP) and Open Group (TOGAF8) Certified Enterprise Architecture Practitioner. He is also a Licensed Zapthink Architect (LZA) in SOA. Besides Technical Architecture Binil also practices Enterprise Architecture. When not in software, Binil spends time with wife Sowmya & daughter Ann in ‘God's Own Country’, Kerala (www. en.wikipedia.org/wiki/Kerala). Binil does long distance running and is a national medalist in Power Lifting. You may contact Binil at biniljava@yahoo.co.in or binil_christudas@infosys.com. Books from Packt |
|
| ||||||||