You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by da...@apache.org on 2009/09/14 17:25:28 UTC

[DOSGi] Using a Data Object as an argument of a Remote Service

Following the various conversations in relation passing data objects to
remote OSGi Services I've enhanced the Greeter demo to show how you can do
this.

The new GreeterService API is as follows:
 public interface GreeterService {
   Map<GreetingPhrase, String> greetMe(String name); // was already there
   GreetingPhrase [] greetMe(GreeterData name) throws GreeterException; //
new!!
 }

where the GreeterData interface is defined as follows:
 public interface GreeterData {
   String getName();
   int getAge();
   boolean isException();
 }

In the demo, the client has its own GreeterDataImpl implements GreeterData
class, it can do something like this:
GreeterData gd = new GreeterDataImpl(...);
greeter.greetMe(gd);

On the server side, you can simply read values out of the GreeterData
object, like this:
  public GreetingPhrase [] greetMe(GreeterData gd) throws GreeterException {
    String n = gd.getName();
    int a = gd.getAge();
    ... etc ...
  }

Only the GreeterData interface needs to be shared, on the server side a
dynamic proxy is created that provides the behaviour. All this magic is
provided by the Aegis data binding and it's limited as follows:
Besides the standard hashCode(), equals() and toString(), only JavaBean
style setter and getter methods are supported. This means that you probably
have to design your datatypes specifically to suit the remote invocation
scenario, which is not a bad thing IMHO...

I'll be updating the greeter demo docs on the CXF Distributed OSGi Wiki over
the coming few days...

Saul Goode & Thomas Shulok I hope that this helps you with what you're
trying to do.

David