Chapter 8. Router solutions using Web Services Gateway 203
Figure 8-39 Service references for Web services
6. Add client application code to invoke the Web service on the target
application.
To invoke getDeliveryDate on the target application, we added the code
shown in Example 8-6. We added this code to the
com.ibm.itso.command.WSGWW1WebServiceBean command bean in our
WSRetailWeb module.
Example 8-6 Web service client code for getDeliveryDate
package com.ibm.itso.command;
import ibmwsgw.Wholesale1;
import java.net.URL;
import javax.naming.*;
import com.ibm.itso.wholesale1.inventory.Inventory;
public class WSGWW1WebServiceBean extends CommandBean {
...
public String getDeliveryDate(String partNumber) throws Exception {
String deliveryDate = null;
204 Broker Interactions for Intra- and Inter-enterprise
try {
InitialContext initialContext = new InitialContext();
Wholesale1 inventoryWholesale1 = (Wholesale1) initialContext.lookup(
"java:comp/env/service/Wholesale1");
//Request the Service Endpoint from the Service
Inventory inventory =
inventoryWholesale1.getInventorySOAPHTTPBindingPort();
//Get the quote
deliveryDate = inventory.getDeliveryDate(partNumber);
} catch (Exception e) {
writeToLog("Exception: " + e.toString());
throw new Exception(e.toString());
}
writeToLog("Exit - getDeliveryDate");
return deliveryDate;
}
Changing the Web service endpoint URL
By default, the endpoint proxy class (InventoryServiceLocator in our example)
will use the endpoint address specified in the WSDL file when the proxy class
was originally generated. It is likely that the endpoint address used will change
over time, as the client application moves though the development, test, and
production environments, for example. You can set the endpoint address in
several ways:
1. When getting an instance of the generated endpoint class from the Service
interface, you can optionally pass an endpoint address that will override the
default address obtained from the WSDL file. Compare the following
approach with that used in Example 8-6 on page 203:
// Request the Service Endpoint from the Service
// overriding the default endpoint address
Inventory inventory = inventoryService.getInventory(new java.net.URL(
"http://localhost:9080/WSWholesale1EAR/services/Inventory"));
2. When deploying your client application to WebSphere Application Server, you
can specify the Deploy WebServices option, as shown in Figure 8-40.
WebSphere will regenerate the deployment code based on the Web services
client deployment descriptors, updating it with the current endpoint address
from the WSDL file. Similar to EJB deployment, this only needs to be
performed when the deployment details have changed.
Chapter 8. Router solutions using Web Services Gateway 205
Example 8-7 shows how the endpoint address is specified in the WSDL file
for our Inventory service.
The second option is recommended in most cases. Using this method, the
endpoint address can be specified at application packaging/deployment time
using the Web services deployment features of the application server.
Example 8-7 Setting the endpoint address in the WSDL file
...
<wsdl:service name="InventoryService">
<wsdl:port name="Inventory" binding="intf:InventorySoapBinding">
<wsdlsoap:address location="http://localhost:9080/ITSOWholesale1/services/Inventory"/>
</wsdl:port>
</wsdl:service>
...
Figure 8-40 Deploying Web services using the WebSphere administrative console
8.6.8 Best practices
This section covers best practices and recommendations.
Place all of the WSDL in one file
WebSphere Studio V5.0 creates three files for the WSDL (interface, binding,
implementation). WebSphere Studio V5.1 puts the WSDL into a single file. If you
are using WebSphere Studio prior to V5.1, it is a good idea to combine the
WSDL into one file to eliminate any problems the gateway might encounter
parsing include statements.
206 Broker Interactions for Intra- and Inter-enterprise
Handling SOAP fault messages
Example 8-8 shows the recommended way to create and return a SOAP fault
message from the GatewayFilter.filterResponse method.
Example 8-8 Creating and returning a SOAP fault message from a filterResponse method
public FilterAction filterResponse(WSIFRequest wsifRequest, WSIFResponse wsifResponse)
throws FilterException, WSGWException, RemoteException {
// Construct the fault message
WSIFMessage faultMessage = new WSIFDefaultMessage();
faultMessage.setObjectPart(WSIFConstants.SOAP_FAULT_ACTOR,"mySoapFaultActor");
faultMessage.setObjectPart(WSIFConstants.SOAP_FAULT_CODE,"mySoapFaultCode");
faultMessage.setObjectPart(WSIFConstants.SOAP_FAULT_STRING,"mySoapFaultString");
faultMessage.setObjectPart("stackTrace","myStackTraceDetails");
faultMessage.setObjectPart("otherDetails","myOtherDetails");
// repeat faultMessage.setObjectPart("aaaa","bbbb"); for each additional detail element
// Set the fault message into the wsifResponse object
wsifResponse.setFaultMessage(faultMessage);
wsifResponse.setIsFault(true);
// Return the updated response in the filterAction object
FilterAction filterAction = new FilterAction();
filterAction.setUpdatedResponse(wsifResponse);
filterAction.setContinueProcessing(false);
return filterAction;
}
Handling exceptions for the Web Services Gateway
During normal processing of a Web service invocation, a fault message might be
generated by the target service, and is passed back to the channel to be sent to
the originator. As far as the Web Services Gateway is concerned there is no
difference between processing a normal output message and processing a fault
message.
But when an exception occurs during processing of a request, the channel needs
some way to decide what to do with the exception. What is needed is a service
that provides a pluggable handler that can look at the message, exception and
other information to decide whether the exception should be thrown back to the
originator, or whether a fault message should be constructed.
This service is not provided with the Web Services Gateway, but the gateway
does contain an interface to encapsulate such a service. The ExceptionHandler
interface allows channels to call an exception handling service, and allows the
exceptions to be reported to a third party for analysis.
Chapter 8. Router solutions using Web Services Gateway 207
The Home object for this service must implement the
com.ibm.wsgw.beans.ExceptionHandlerHome interface and be located in JNDI
at websphere/WSGW/ExceptionHandlerService.
Capturing Web service invocation information
The Web Services Gateway has not implemented a service that stores
operational messages, but it does contain an interface (the MessageWarehouse
interface) to encapsulate such a service. This interface is driven by channels on
receipt of requests and before sending responses.
If you have your own system for handling (classifying, storing and retrieving)
operational messages, you can potentially use it to log the gateway's operational
messages through the MessageWarehouse interface.
The Home object for this service must implement the
com.ibm.wsgw.beans.MessageWarehouseHome interface and be located in
JNDI at websphere/WSGW/MessageWarehouse.
Monitoring SOAP messages
You can trace the XML messages exchanged between a Web service client and
the server. In this section we look at two tools:
? The TCPMon tool provided with IBM WebSphere Application Server V5.0
? The TCP/IP Monitor Server provided with WebSphere Studio Application
Developer
WebSphere TCPMon tool
The TCPMon tool allows SOAP messages to be traced by redirecting messages
from one port to another, displaying the contents as they go. The WebSphere
application server normally listens on port 9080. To trace messages sent to the
application server, TCPMon can be configured, for example, to listen on port
9088 and redirect messages to 9080. The client is modified to use port 9088 to
access the Web service.
This tool is provided with IBM WebSphere Application Server V5.0.2. It allows
you to view the contents of the SOAP messages exchange between the source
and target applications, as shown in Figure 8-41.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.12.157