IBM BPM, V8.0.1, All platforms > Programming IBM BPM > Enterprise Service Bus programming > Invocation of Services > Dynamic invocation > Dynamic endpoint selection

Custom Endpoint Lookup mediation primitive

There are situations in which the supplied Endpoint Lookup mediation primitives are not sufficiently flexible. In these circumstances, use a Custom mediation primitive. If you need to access data in a WSRR registry, use the WebSphere ESB WSRR proxy.


Example scenario

The fictional company My Airways has registered some WSDL-defined service providers in a WSRR registry, and want to retrieve the service endpoint URL that is based on a user property, which is determined from the SMO at run time. My Airways use a Custom mediation primitive to retrieve the service endpoint URL and set it in the SMO, so the service providers are called dynamically.

The Custom mediation primitive code completes three steps:

The following is the Custom mediation primitive code:

String endpointAddress = null;

// Get the factory and then get the default instance of a ServiceRegistryProxy. 
Can also use getServiceRegistryProxy("RegistryName")
com.ibm.wsspi.sibx.mediation.wsrr.client.ServiceRegistryProxy srProxy = 
com.ibm.wsspi.sibx.mediation.wsrr.client.ServiceRegistryProxyFactory.getInstance().
getDefaultServiceRegistryProxy();

try
{
		 // Set up the WSRR XPath query - this query looks for WSDL Ports that 
				have the PortType name 'MyAirwaysAccount'and the required customerType user property 		 // and the PortType namespace 'http://www.MyAirways.com/AccountManagement/'
			String customerType = smo.getString("/body/bookFlight/customerType");
		 	String query = "/WSRR/WSDLService/ports[binding(.)/portType(.)
			[@name = 'MyAirwaysAccount' "+
			 		 "and @namespace='http://www.MyAirways.com/AccountManagement/'
					  and @customerType ='" + customerType + "']]";
		 
		 // Run the query & get the results 		com.ibm.wsspi.sibx.mediation.wsrr.client.data.
		ServiceRegistryDataGraphList list = srProxy.query(query, -1, false);
		 
		 // Iterate through the results 		 Iterator<DataGraphType>  resultsIterator = list.getDataGraphs().iterator();
		 while(resultsIterator.hasNext() && endpointAddress == null)
		 {
		 		DataGraphType dgt = resultsIterator.next();
		 		BaseObject[] baseObjects = dgt.getWSRR().getArtefacts();


				com.ibm.ws.management.discovery.EndpointAddress endpointAddress = null;

		 		// Find the SOAP Address  		 		 
				for(int i=0; i<baseObjects.length; i++)
				{
		 		 		 BaseObject bo = baseObjects[i];
		 		 		 if(bo instanceof com.ibm.wsspi.sibx.mediation.wsrr.client.jaxrpc.WSDLService)
		 		 		 {
		 		 		 		com.ibm.wsspi.sibx.mediation.wsrr.client.jaxrpc.WSDLPort[] ports = ((com.ibm.
								  wsspi.sibx.mediation.wsrr.client.jaxrpc.WSDLService)bo).getPorts();
		 		 		 		 // Look for the SOAP Address in the first port	
	 		 		 		 
		 		 		 		 endpointAddress = ports[0].getSOAPAddress().getLocation();
		 		 		 		 break;		 		 		 
		 		 		 } 		 		 } 		 } } catch(ServiceRegistryProxyException e)
{
		 e.printStackTrace();} 
System.out.println(endpointAddress);

// If we have successfully retrieved an endpoint from WSRR, set it into the SMO
if(endpointAddress != null)
{
		 smo.setString("headers/SMOHeader/Target/address", endpointAddress);		 }

Dynamic endpoint selection