Use of the remote API

This section explains how to use the FraSCAti remote API into your application.

You need to add a dependency to the frascati-introspection-api module to be able to load service interfaces (RemoteScaDomain, Reconfiguration and Deployment) and REST resources.


From the SCA world

Of course, the easiest way to connect to the FraSCAti remote API is to declare an SCA reference to the targeted service on the remote component. In your composite file, it will lool like:

<component name="mycomponent">
    < class="org.myorg.myapp.MyCompImpl"/>

    <service name="myservice">

    <reference name="introspection">
      < interface="org.ow2.frascati.remote.introspection.RemoteScaDomain"/>
      < uri="http://<frascati-hostname[:portnumber]>/introspection"/>
    <reference name="reconfiguration">
      < interface="org.ow2.frascati.remote.introspection.Reconfiguration"/>
      < uri="http://<frascati-hostname[:portnumber]>/reconfig"/>
    <reference name="deployment">
      < interface="org.ow2.frascati.remote.introspection.Deployment"/>
      < uri="http://<frascati-hostname[:portnumber]>/deploy"/>

You just need to define a reference to services you intend to use. Of course, <frascati-hostname[:portnumber]> has to be replaced by something like, depending on your infrastructure.

In the component implementation, you just have to declare these references:

import org.ow2.frascati.remote.introspection.RemoteScaDomain;
import org.ow2.frascati.remote.introspection.Reconfiguration;
import org.ow2.frascati.remote.introspection.Deployment;

protected RemoteScaDomain introspection;

protected Reconfiguration reconfiguration;

protected Deployment deployment;

That's all! Have a look at the general usage section to learn about remote API.

From the Java world

From the Java world, there are several ways to send remote calls to FraSCAti. For instance, you can use the URLConnection object of the SDK or use third-party libraries like Jersey, Apache CXF, etc. We will describe you how to set up and use CXF because it is really simple and it offers you automatic marshalling/unmarshalling of parameters and response. You need to add the cxf-rt-frontend-jaxrs dependency (and its transitive dependencies if you don't use Maven) in your project classpath.


Then, you need to create a dedicated JAX-RS client for the targeted service.

import org.ow2.frascati.remote.introspection.RemoteScaDomain;
import org.ow2.frascati.remote.introspection.Reconfiguration;
import org.ow2.frascati.remote.introspection.Deployment;

private static final String BINDING_URI = "http://localhost:8090";

RemoteScaDomain introspection = JAXRSClientFactory.create(BINDING_URI+"/introspection", RemoteScaDomain.class);
Reconfiguration reconfiguration = JAXRSClientFactory.create(BINDING_URI+"/reconfig", Reconfiguration.class);
Deployment deployment = JAXRSClientFactory.create(BINDING_URI+"/deploy", Deployment.class);

The BINDING_URI constant should point to the targeted FraSCAti runtime, i.e. the hostname and the port number on which FraSCAti services are running (ex:

General usage

Once references to FraSCAti remote services set-up, we are now able to do remote calls transparently through a simple Java interface. Here are some examples:

  • List composites loaded into the domain

    import org.ow2.frascati.remote.introspection.resources.Component;
    for (Component c : introspection.getDomainComposites()) {
  • Get information on a specific component

    import org.ow2.frascati.remote.introspection.resources.Component;
    Component comp = introspection.getComponent("/org.ow2.frascati.FraSCAti/component-factory/factory");
  • Query with FraSCAti FScript

    import org.ow2.frascati.remote.introspection.resources.Node;
    Collection<Node> result = reconfiguration.eval("$domain/scadescendant::component-factory/scaservice::*;");
  • Reconfigure with FraSCAti FScript

    import org.ow2.frascati.remote.introspection.resources.Node;
    Collection<Node> result;
    System.out.println("Before reconfiguration:");
    result = reconfiguration.eval("$domain/scadescendant::services;");
    reconfiguration.eval("set-state($domain/scadescendant::services, \"STOPPED\");");
    System.out.println("After reconfiguration:");
    result = reconfiguration.eval("$domain/scadescendant::services;");
  • Deploy remotely an SCA contribution

    import org.ow2.frascati.remote.introspection.FileUtil;
    String contrib = null;
    try {
        contrib = FileUtil.getStringFromFile(new File("src/test/resources/"));
    } catch (IOException e) {
        System.err.println("Cannot read the contribution!");
    System.out.println("** Trying to deploy a contribution ...");
    System.out.println("** Contribution deployed!");

    Here, we first read a Contribution file on the file system, then convert the file content to a base64 encoded String to give it as argument to the deploy method.


    The deploy method only takes SCA contribution files encoded as Base64 Strings. Have a look at the next section to know how to generate a contribution.