Raymond Feng wrote:
Hi,

Welcome to Tuscany!

Let me first make sure that I understand your scenario correctly.

1) You have an external web service "MathService" developed with Axis2 and the endpoint address is http://localhost:8080/zong/services/MathService. 2) In the Calculator composite, you want to wire to the "MathService" to provide the "add" function
3) There is an interface AddService with "add" operation

Since the MathService has different operations than AddService, the Calculator component needs to wire to the MathService using an interface compatible with MathService, for example, you can define an interface for the MathService as:

@Remotable
public interface RemoteMatchService {
   public double addiere(double a,double b);
   public int aufrunden(double a);
}

And change the Calculator impl to be:

private RemoteMatchService addService;

@Reference
public void setAddService(RemoteMathService addService) {
...
}

public double add(double n1, double n2) {
     return addService.addiere(n1, n2);
}


Hmmm, that will work but requires changes to CalculatorServiceImpl.java.

The neat thing with SCA is that you can also support your scenario without a code change (but a little more assembly), as follows:

1. Create a 'mediation' component that mediates between the AddService and the MathService interfaces.

class AddMediationImpl implements AddService {

  private MathService mathService;

  @Reference
  public setMathService(MathService service) {
    this.mathService = service;
  }

  public double add(double a, double b) {
    return mathService.addiere(a, b);
  }
}

2. Put that mediation component on the path to your remote math service in your .composite.

<composite ...>

 <component name="CalculatorServiceComponent">
  <implementation.java class="calculator.CalculatorServiceImpl"/>
  <reference name="addService" target="MediationServiceComponent"/>
   ...
 </component>

 <component name="MediationServiceComponent">
  <implementation.java class="calculator.AddMediationImpl"/>
  <reference name="mathService">
<binding.ws uri="http://localhost:8080/zong/services/MathService"; />
  </reference>
 </component>
 ...
</composite>

Mediation components like that allow you to compose an application out of services that were not initially designed to fit together, by adapting their interfaces and/or behavior.

They are usually simple to write by hand, or if you have many interface mappings like that one, you can just write a simple tool that generates them for you.

Hope this helps.
--
Jean-Sebastien

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to