Web Service Gateway

The Web Service Gateway allows agents to access web services. Whereas agents are normally not allowed to directly access remote services, the gateway allows agents to access remote services. The gateway may perform some access control checks and regulation to limit the service access by internal components. It heavily relies on the Axis2 library to perform the bulk of the work. The gateway is merely a proxy that sits between the client and the actual web service.

API

The API is quite simple. Because most of the work is done by Axis2, the service is accessed through these libraries. The only thing that is required to access the service is a custom Axis2 ConfigurationContext which sets up the connection to the gateway as a proxy.

public interface WSGatewayService extends Service
{
  ConfigurationContext getConfigurationContext () throws AxisFault;
}

Once the configuration context has been obtained, this context can be used to initialize the connection to the proxy. The context makes sure that all requests using the http scheme will be forwarded to the gateway. The rest is up to the client using the Axis2 library.

Client example

As far as the client is concerned, all of the APIs that are used are the standard Axis2 libraries. This means support for creating SOAP messages and interacting with the web service are all handled by Axis2. There is also a source code generation mechanism which may be useful: it creates a Java client stub from a WSDL file of a service.

Generating Sources

The WSGateway example agent (org.iids.aos.services:wsgateway-client-temp) demonstrates how to use the plugin org.apache.axis2:axis2-wsdl2code-maven-plugin to generate the client code. This code is used together with the context from the Web Service Gateway API to connect to the service via the gateway. The following snippet shows how to integrate the wsdl2code into a maven project.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.axis2</groupId>
      <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
      <version>1.5.2</version>
      <executions>
        <execution>
          <goals>
            <goal>wsdl2code</goal>
          </goals>
          <configuration>
            <packageName>nl.decis.aos.ws.client.currency</packageName>
            <wsdlFile>${project.basedir}/src/main/resources/TempConvertor.wsdl</wsdlFile>
            <databindingName>adb</databindingName>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Binding to the Web Service

Using the generated sources, we can now initialize a client agent to bind via the gateway. Most of this work is done via AXIS2, only the initialization of the transport is done via the binding to the service.

WSGatewayService ws = getServiceBroker().bind(WSGatewayService.class);
ConfigurationContext ctx = ws.getConfigurationContext();
TempConvertStub stub = new TempConvertStub(ctx, lastOperation.address);

Here you see that the only relation to the service are setting up the binding (line 1) and initializing the client with the proper context from the service. Once this has been setup, the client will transport the SOAP message for interaction with the service over the AgentScape service framework.

development/service/wsgateway.txt · Last modified: 2012/05/15 13:56 by reinier