November 25, 2014
Hot Topics:

Mule - The Open Source Enterprise Integration Solution

  • March 26, 2009
  • By Ayyappan Gandhirajan
  • Send Email »
  • More Articles »

The first inbound router is "axis" that exposes the component as an Axis Web Service. After deploying the service, the WSDL can be accessed from http://localhost:7070/services/PortfolioService?wsdl. Mule takes care of things that are required to expose the component as service. Hence you just configure them and leave the worries of all the plumbing works involved in web service enablement to Mule.

The second inbound router is "stdio" (stands for Standard Input and Output) that receives requests from the Windows Console. While you start the Mule server, Mule will initialize the service and start an input stream listener that will read input from a windows console. Please be aware that this listener is only available for testing purpose and not recommended for production use.

The third inbound router is "vm" (stands for virtual machine) which can receive the requests from another application that runs in the same JVM. This router deserves more explanation as it uses transformation too. The "LoginStatusToStringUsername" transformer transforms "samples.businessobjects.LoginStatus" to "java.lang.String" (i.e. username that portfolio service expects). The assumption here is that the calling application would return the 'samples.businessobjects.LoginStatus' but the receiving application, (i.e., PortfolioService) need 'java.lang.String'. Hence it demands a transformer. The java code for the transformer (LoginStatusToStringUsername) is given below:

package samples.utils;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractTransformer;
import samples.businessobjects.LoginStatus;
public class LoginStatusToStringUsername extends AbstractTransformer {
 
 public LoginStatusToStringUsername() {
  super();
  this.registerSourceType(LoginStatus.class);
  this.setReturnClass(String.class);
 }
 
 protected Object doTransform(Object src, String encoding)
   throws TransformerException {
  LoginStatus status = (LoginStatus)src;
  if( status != null ){
   return status.getUsername();
  }  
  return "";   
 }
}

Now that we understand how easy it is to expose a component as an Axis web service and how the service component can also receive input from another mule component. Finally, the output of this component is routed to a Windows console. If required, the response can be routed to another mule component using following statement within the <outbound> element.

<outbound>
 <chaining-router>
  <vm:outbound-endpoint path="another_ application_inbound_router" />                    
                         <stdio:outbound-endpoint system="OUT"/>
 </chaining-router>
</outbound>

Service Component - POJO class

The service component is a simple POJO class named "sample.services.PortfolioManager" that has a single operation nameed'getPortfolio'. The operation takes 'username' as an input. Depending on the user name, the operation will return a different portfolio. The code snippet for PortfolioManager is given below:

package samples.services;
import java.util.Hashtable;
import java.util.Map;
public class PortfolioManager implements PortfolioManagerIntf{
 private static Map portfolioMap = new Hashtable();
 static{
  String stockDetailsPER = "Name: PER, Qty: 100, BoughtPrice: 12, CurrentPrice: 13";
  String stockDetailsHPQ = "Name: HPQ, Qty: 50, BoughtPrice: 20, CurrentPrice: 30";
  String stockDetailsIBM = "Name: IBM, Qty: 100, BoughtPrice: 60, CurrentPrice: 91";
  String stockDetailsWIT = "Name: WIT, Qty: 25, BoughtPrice: 35, CurrentPrice: 7";
  String stockDetailsINFY = "Name: INFY, Qty: 25, BoughtPrice: 35, CurrentPrice: 25";
  
  portfolioMap.put( "portfolio1", new String[]{ stockDetailsPER, stockDetailsHPQ, stockDetailsIBM } );
  portfolioMap.put( "portfolio2", new String[]{ stockDetailsPER, stockDetailsWIT, stockDetailsINFY } );
  portfolioMap.put( "portfolio3", new String[]{ stockDetailsPER } ); //default
 }
 
 public String[] getPortfolio( String username ) {
  String[] portfolioBO = null;  
  if( username == null || username.equals( "" ) ) {
   portfolioBO = (String[]) portfolioMap.get("portfolio3" );
  } else if( username.charAt( 0 ) <= 'm' || username.charAt( 0 ) <= 'M' )  {
   portfolioBO = (String[]) portfolioMap.get("portfolio1" );
  } else {
   portfolioBO = (String[]) portfolioMap.get("portfolio2" );
  }
  return portfolioBO;
 }
}





Page 3 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel