White Papers
Abstract
Loosely coupling service requestors and service providers is a key aspect of an SOA. This article shows you how to decouple service requestors and service providers at the transport level by implementing a Web service proxy that dynamically assigns the appropriate service endpoint to the service request. This article shows you how to accomplish this goal by configuring a WebSphere DataPower SOA Appliance to subscribe to service descriptions stored in WebSphere Service Registry and Repository.
Content
A key aim of SOA is to loosely couple service requestors and service providers. Decoupling the service implementation from the service interface is one step, so that changing the provider's service implementation does not require any changes to the service requestor. But what about the service endpoint -- using a static endpoint provided by the service description (WSDL) means coupling the requestor and provider at the transport level: Every time the physical endpoint of the service provider changes, every service consumer must reflect the changes in its application logic. A better solution is to use an intermediary that intercepts a service call and routes it to the appropriate endpoint. Abstracting from transport-specific information to have a transparent intermediary layer between service consumers and providers is one aspect of the Enterprise Service Bus (ESB) pattern. The WebSphere DataPower SOA Appliance and its Web Service Proxy component can be part of an ESB implementation by acting as such an intermediary layer. Implementing this part of an ESB layer in a static way by referencing WSDL files in the WS-Proxy component and providing a static service endpoint to the consumer provides a single point of control when changes are made to the real service endpoint, thus simplifying management of the service endpoint. With this approach, the service consumer is decoupled from the provider at the transport level, but changes on the proxy side are still necessary when changes are made on the providers endpoint. Using DataPower's WebSphere Service Registry and Repository subscription feature inside the service proxy instead of statically referencing the WSDL file is the way to get a more dynamic service intermediary. DataPower can subscribe to WSDL files or to other artifacts stored in WebSphere Service Registry and Repository, and synchronize with changes either automatically by polling or manually driven from outside. Form a service endpoint management point of view, this approach provides a flexible and dynamic ESB layer functionality that reflects changes to the endpoints automatically without having to make changes on the service consumer nor on the ESB side: This article describes how to set up such an dynamic Web service proxy with WebSphere Service Registry and Repository and DataPower. The article first describes the basic configuration -- how to set up the WS-Proxy and connect it to WebSphere Service Registry and Repository to subscribe to service definitions. The article then describes fault handling, schema validation, and how they can be realized in the WS-Proxy component of DataPower. The following prerequisites are required to set up the described scenario: Before you can start to configure the WS-Proxy in DataPower, you must register the Web service you want to subscribe to in WebSphere Service Registry and Repository, as described below. To register the Web service in WSSR, upload the WSDL and all of its dependent XSDs via the administrative console, as shown below. The administrative console is provided via a Web interface -- to access it, use a browser and enter the URL of your WebSphere Service Registry and Repository installation. The URL of the administrative console has the following structure: . The minOccurs attribute of the customer and the order element is set to 1, meaning that these objects are required in every order request. Later you will use that fact to cause a validation error in the Web service proxy. Log in to the administrative console Enter the URL of your WebSphere Service Registry and Repository installation. When the login screen opens, log in with your credentials. If you don't have configured security, you will be forwarded to the administrative console: Upload the XSD files. Under Service Documents go to XSD Documents and upload Upload the WSDL file. After you have successfully uploaded the XSD documents, you can upload the WSDL file. Under Service Documents go to WSDL Documents and upload the WSDL in the same manner as you did with the XSD documents. Your WSDL Document page should show the WSDL file: You have now registered the Order Service in WSRR, so you can now query this service definition using DataPower. In this step, you configure the DataPower device. First, log in to the device and your domain (Figure 6a). Before creating the Web service proxy, you must define a Http Front Side Handler object and a WSRR Server object, which will both be used by the Web service proxy. The Http Front Side Handler object will listen on a specific URL and will route the HTTP requests sent to this URL to the Web Service Proxy service. The WSRR server object is the definition of the WSRR you want to use for the subscription of service definitions. The following section shows you how to create and configure the objects used by a Web Service Proxy service: WSRR Server Object Under the left navigation pane on the DataPower Web GUI, navigate to the Objects section and click WSRR Server in the Configuration section. A list of all WSRR server definitions opens. Click Add to define a new WSRR Server: Assign a name such as HTTP Front Side Handler It is not mandatory to define the HTTP Front Side Handler in the following way. During the creation of the Web service proxy, you will be able to choose a default HTTP Front Side Handler. You would have to change this default HTTP Frontside Handler to your requirements anyway. Under the left navigation pane on the DataPower Web GUI navigate to the Objects section and locate the HTTP Front Side Handler link in the Protocol Handlers subsection. After clicking this link a list with all HTTP Front Side Handler definitions will appear. Click add to define a new HTTP Front Side Handler. You can keep all defaults. In the name field choose for example Save your configuration on the upper right of the Web GUI: Click Save config. In order to create a new Web Service Proxy click on the Web Service Proxy Icon on the Control Panel: Your configuration now should look like this: After verifying your settings, save your configuration on the upper right of the Web GUI by clicking Save config. First examine the status of the WSRR subscription. Under Status in the left navigation pane you can find WSRR Subscription Status and WSRR Subscription Service Status under the Web Service subsection. Click on both and examine the status and the retrieved information. When all worked fine the two status tables should look like Figure 10a and 10b: Now examine if DataPower has retrieved the right endpoint information from WSRR. Return to the Status section and under the Web Service subsection click on Web Service Operations. There will be a table with all currently registered Web Service operations. The very last column on the right shows the back end address which is the service endpoint DataPower has retrieved from the service definition in WSRR. Figure 10c shows the last two columns of this table. The Web service proxy now is ready for a first test. The new external endpoint of the Web service is the Local IP Address and the Port Number of the HTTP Frontside Handler followed by the Local URI of the WSRR subscription (http://<EthernetInterfaceIP>:9080/services/OrderService). You can use any Web service client to send a valid SOAP request to the Web service proxy's endpoint. In order to get a better understanding of what happens you can use a TCP/IP monitor to examine the SOAP request and the SOAP response. For sending SOAP requests and examine the SOAP response you can also use the build in Web Service Explorer of the WebSphere Integration Developer or the Rational Application Developer. You can send any order information as long you have at least one required order object and one required customer object in your order. Now you can try sending an request without one of the following required objects. The Web service proxy will validate each SOAP request against the schema provided by the WSDL and the XSD files. When a invalid request is sent to the box the result will be an "Internal Server Error" response. To see the System Log go to Status, System Log on the right navigation pane. When you have a look in the System Log of DataPower you will see the Schema Validation Error the invalid request has caused Figure 11: When all this tests worked fine, your WS-Proxy is completely configured. For the case you have encountered any problems the next sections describes how you can debug your WS-Proxy. When your Web service proxy is not working as expected and you get runtime errors there are two options for debugging: You can have a look at the System Log like it is shown above. You can change the log level of the system log by going to the Control Panel and choosing Troubleshooting. Under Logging change the Log Level to When the System Log is not detailed enough and you can identify the component that raised the error, you can put a probe in it. To add a probe to the Web Service Proxy service, go to the Control Panel and click WSProxy => MyWebServiceProxy: Click Show Probe => Enable Probe. A detailed log for this specific Web Service Proxy object is activated: You can see this log on the current window (after you have sent the next request) when you click Refresh. For information on how to use probes in DataPower, see the documentation. Disable probes after debugging because they use significant system resources. This section describes how to do more fine-grained configuration of the Web service proxy and implement more sophisticated fault handling. The DataPower Web Service Proxy service leverages more features and configuration capabilities than just listening on specific HTTP endpoints and forwarding incoming SOAP calls. You can see the range of possibilities in the Configure Web Service Proxy section of your Web Service Proxy. As described above, the DataPower Web Service Proxy service validates an incoming request against a WSDL file. You can change this validation behavior for each Web service or even for each operation or port. It is not very meaningful sending SOAP faults in form of an internal server error back to the client. Especially when the root cause of the error is the request of the client it would be more beneficial when a more detailed fault message is returned. Giving back the validation error instead of an internal server error would give the client information about what is wrong with its request. The next section will cover how to set up the Web Service Proxy service in a way in which it sends the validation error information in a SOAP fault message back to the client. This can be achieved in adding a OnError action to the Web Service Proxy policy processing rules. You can add this OnError rule either in the default request rule or to a specific rule on a specific level of the Order Service. When there would be more then one service subscription you could add the OnError or any other action just to one of the services if necessary. Here we will add the OnError action to the default request rule of the Web Service Proxy. Adding an on-error action at a specific point in a processing rule means that the on-error action is triggered when any of the following processing steps (actions) contained in this rules raises a fault. In order to do so click on the link MyWebServiceProxy_default_request_rule. You will see this screen: Now the request rule and a new error rule has to be configured for having a kind of try and catch error handling. Now you should save your configuration and test your changes by sending the invalid SOAP request. The SOAP Fault message should not be the "Internal Server Error" anymore but detailed information about the validation error. After doing the configuration work described above, you have now a dynamic Web Service Proxy, which is able to subscribe to service descriptions stored in WebSphere Service Registry and Repository. Beyond the more flexible decoupling of service consumer and provider, the WS-Proxy component in DataPower supports many additional service intermediaries. For more information, see Related topics below. For example, WS-Proxy can act as an XML firewall, service-level monitor, and security policy enforcement point: This article described DataPower features in conjunction with WebSphere Service Registry and Repository. You can also use more sophisticated features on WebSphere Service Registry and Repository to get more flexibility. For example, you can create ontologies to abstract from technical artifacts such as WSDL and XSD files, by grouping artifacts in a "concept." DataPower can also subscribe to this concept instead of directly subscribing to service descriptions (WSDL files). For more information on these WebSphere Service Registry and Repository features, see the product documentation.Introduction



Prerequisites
WebSphere Service Registry and Repository configuration
Upload files
http://<hostname>:<port_number>/ServiceRegistry. For example: http://localhost:9080/ServiceRegistry

Item.xsd, Customer.xsd, and Order.xsd by clicking Load Document and following the instructions. Beside giving a description of the datatype you are uploading, you can provide a version number such as 1.0 (or you can leave it blank). The XSD Documents page should look like this:

WS-Proxy configuration

Preparing configuration objects

MyWSRRServer to your WSRR server. In the SOAP URL field, replace hostname and port number with the values of your WSRR installation. When your are running WSRR without security, your protocol will be HTTP. When your are running WSRR with security enabled, provide an SSL proxy profile, username, and password. For information on how to configure an SSL proxy profile, see the DataPower documentation. Click Apply. The Web GUI switches back to the WSRR server list, where your WSRR server definition should appear.MyHTTPFrontsideHandler as name of the new handler. As Local IP Address choose the IP address of one of the ethernet interfaces. You can figure out this IP address at the right navigation pane under Status, IP Network, Ethernet Interfaces. If you leave the default 0.0.0.0, you will reach the HTTP Frontside Handler on all configured ethernet interfaces. Under Port Number fill in a port which isn't already used by the DataPower device, for example 9080. If you want to be able to retrieve the new WSDL of the Order Service (generated by the WS-Proxy) with ?wsdl in your browser you have to enable the HTTP GET method, too. Here are the settings:

Setting up WS-Proxy Service


Attribute Value WSRR Subscription Name MyServiceSubscrition WSRR Server MyWSSRServer Subscription Object WSDL Document Namespace http://wsrr.integration/orderservice Object Name OrderService.wsdl Local Endpoint Handler MyHTTPFrontsideHandler Local URI /services/OrderService 
Verifying subscription status


Verifying the endpoint information

Testing the WS-Proxy
<?xml version="1.0 encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://wsrr.integration/orderservice" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <q0:placeOrder> <order> <customer> <firstName>Peter</firstName> <LastName>Jones</LastName> <id>2838382128</id> </customer> <items> <articleID>837228304</articleID> <quantity>3</quantity> </items> <items> <articleID>8272666333</articleID> <quantity>4</quantity> </items> </order> </q0:placeOrder> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
<?xml version="1.0 encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <q0:placeOrderResponse xmlns:q0="http://wsrr.integration/orderservice"> <orderID>ID_123456</orderID> </q0:placeOrder> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
<?xml version="1.0 encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://wsrr.integration/orderservice" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <q0:placeOrder> <order> <customer> <firstName>Peter</firstName> <LastName>Jones</LastName> <id>2838382128</id> </customer> </order> </q0:placeOrder> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
<?xml version="1.0 encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>General</faultcode> <faultstring>Internal Error</faultstring> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

debug and click on the Set Log Level button. Debug will be the most fine grained level:
Probe


Advanced configuration and fault handling
Configuring the validation behavior



Advanced fault handling

Stylesheet preparation
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dp="http://www.datapower.com/extensions" extensions-Element-prefixes="dp"> <xsl:variable name="error" select="dp:variable('var://service/error-message')"/> <xsl:template match="/"> <soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Header /> <soapenv:Body> <soapenv:Fault> <faultcode xmlns:p618="http://wsrr.integration/orderservice"> p618:placeOrder_orderFailurefMsg </faultcode> <faultstring>integration.wsrr.PlaceOrder_orderFailurefMsg</faultstring> <detail encodingStyle=""> <p618:placeOrder_orderFailuref xmlns:p618="http://wsrr.integration/orderservice"> <xsl:value-of select="$error"/> </p618:placeOrder_orderFailuref> </detail> </soapenv:Fault> </soapenv:Body> </soapenv:Envelope> </xsl:template> </xsl:stylesheet> 

(auto) as input of the on-error action and OUTPUT as output. Error Mode will be abort because we don't want to correct the error and continue but discard the request and send back an error to the client. Click Done: 
MyErrorRule and choose error-rule as Rule Direction. Now add a action to this rule which executes the previously created XSL stylesheet. Click the + sign on the lower right and name the action MyErrorAction. Choose xform as Action Type and use your recently uploaded stylesheet in the Transform field. Input will be INPUT and Output will be OUTPUT. You can now save all opened windows by pushing either Apply or Done. Here are the settings: 

Conclusion
Was this topic helpful?
Document Information
Modified date:
08 June 2021
UID
ibm11109343