Business components : Business components : Supporting components : Remote : Tasks
  
Tasks
See also
Accessing services via HTTP
Exporting Remote services
Scope management of Remote Connection for POJO service
Remote
Accessing services via HTTP
If the citation service is exposed as an UDTT Remote–based service, you can configure a bean that proxies it using ServiceProxyFactory.
Here is an example of configuring in the client side.
<package.InterfaceName id="localService"
Instantiate="factoryElement"
FactoryClass="com.ibm.btt.remote.ServiceProxyFactory"
serviceUrl="http://${citationhost}/BTTRemoteConnector"
serviceId="remoteServiceName">
</package.InterfaceName>
The URL of the service is set through the serviceUrl property. Here, the handler is named BTTRemoteConnector and is hosted on a machine whose name is configured using a property placeholder. The tag name specifies the interface that the service implements and through which the client invokes methods on the service. serviceId specified the remote service name that defined in server side.
After finish the configuration in client side, you can call the service in the client side.
Here is an example of calling the service in the client side.
ElementFactory factory = new BasicElementFactory("jar:///client.xml");
TestServiceInterface serviceProxy = (TestServiceInterface) factory.getElement("localService");
The interaction between the client and the proxy is illustrated as follow:
This graphic is described in the surrounding text.
See also
Tasks
Exporting Remote services
Prerequisite: To export the service in server side, you should do the following steps:
1 Create the proxy:
Use a interface on the client side. Here is an example:
public interface TestServiceInterface {
public String getYear(String name);
public void setYear(String name, String year) throws TestException;
}
Implement the service interface on the server side. Here is an example:
public class TestService implements TestServiceInterface {
private Map< String, String> values = new HashMap< String, String>();
public String getYear(String name) {
return values.get(name);
}
public void setYear(String name, String year) throws TestException {
System.out.println("name: " + name + " age: " + year);
if (name.equals(year)) {
throw new TestException("name: " + name + " age: " + year);
}
values.put(name, year);
}
}
2 Configure the web container, which is the second level container on the server side. To enable Remote on the server side, you should do the following steps:
Add some parameters and a listener for the service connector. For example:
<context-param>
<description>
</description>
<param-name>elementFactoryConfigPath</param-name>
<param-value>jar:///universalFactory.xml</param-value>
</context-param>
<listener>
<description>Start BTT Server Components</description>
<display-name>BTTServerStarter</display-name>
<listener-class>com.ibm.btt.webapp.BTTServerStarter</listener-class>
</listener>
The elementFactoryConfigPath parameter indicates the path of the UDTT configuration files. The BTTServerStarter, which is provided by Remote, is a listener which can be notified when web server started
Add a servlet, which serves as the handler for the remote invocation. For example:
<servlet>
<description>BTT Remote Connector Servlet</description>
<display-name>BTTRemoteConnector</display-name>
<servlet-name>BTTRemoteConnector</servlet-name>
<servlet-class>com.ibm.btt.remote.BTTRemoteConnector</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BTTRemoteConnector</servlet-name>
<url-pattern>/BTTRemoteConnector</url-pattern>
</servlet-mapping>
After Completing This Task: 
Note Those four jars library at runtime are needed on the client side:
commons-codec-1.3.jar
commons-httpclient-3.1.jar
commons-logging-1.1.1.jar
commons-logging-api-1.1.1.jar
You can find them at: <BTTInstallationPath>\plugins\com.ibm.btt.remote.0\lib\
See also
Tasks
Scope management of Remote Connection for POJO service
The POJO service is instantiated by UDTT Element Factory on the server side. And the instance lifecycle can be specified by the configuration of the UDTT Element Factory, using a attribute named scope. UDTT Element Factory provides the following three options for the scope attribute:
singleton. It means that there is only one service instance in the server environment and only one instance for one particular id.
prototype. It means when the server receives a client request, one instance of the service is instantiated. And the instance is destroyed after the execution of the method.
session. It means the lifecycle of the instance is the same as the session in the web container, which seems shorter than the singleton but longer than the prototype.
If the scope of one service is not set, the default value will follow the global one.
See also
Singleton Remote Connection for POJO service
Prototype Remote Connection for POJO service
Session Remote Connection for POJO service
Tasks
Singleton Remote Connection for POJO service
The Singleton Remote Connection means that there is only one service instance in the server environment and only one instance for one particular id.
Perform the following procedure to set up a Singleton Remote Connection for POJO service:
1 Register the service in the Element Factory configuration XML file on the server side. Here is an example::
<service.TestService id="testService" scope=”singleton”/>
The service.TestService corresponds to the implementation of the service. The scope is valued with singleton.
2 Set the callback function for the initialization and destroy of the service instance.
<service.TestService id="testService" InitMethod="init" DestroyMethod="destroy"/>
The init method of the service instance will be invoked to execute some initialization actions after the object is created. And the destroy method of the service instance will be invoked before the object is destroyed.
3 Configure the proxy on the client side.
4 Call the service on the client side.
See also
Scope management of Remote Connection for POJO service
Prototype Remote Connection for POJO service
The prototype means when the server receives a client request, one instance of the service is instantiated. And the instance is destroyed after the execution of the method.
The process of setting up a Prototype Remote connection is the same as the Singleton Remote Connection, except for the service registration on the server side. The scope is set to prototype. For example, <service.TestService id="testService" scope=”prototype”/>
See also
Scope management of Remote Connection for POJO service
Session Remote Connection for POJO service
The session means the lifecycle of the instance is the same as the session in the web container, which seems shorter than the singleton but longer than the prototype.
The process is basic the same with Singleton Remote Connection, except two difference.
1 Registry the service in the Element Factory configuration file on the server side, set the scope to session. Here is an example:
<service.TestService id="testService" scope=”singleton”/>
2 Configure the proxy on the client side. Here is an example:
<service.TestServiceInterface id="testServiceProxy"
Instantiate="factoryElement"
FactoryClass="com.ibm.btt.remote.ServiceProxyFactory"
serviceUrl="http://localhost:9080/BTTMCATestWeb/JavaConnector"
serviceId="testService">
<ref Injection="httpClient" refId="httpClient" />
</service.TestServiceInterface>
<org.apache.commons.httpclient.HttpClient id="httpClient" />
3 Call the service on the client side. This part is the same as the Singleton Remote Connection for POJO service.
See also
Scope management of Remote Connection for POJO service