Today we’ll talk about remote client creation which invokes our HelloWorldService from part 1.

Little more info about this sample:

  • Before running remote client, HelloWorldService should be built and packaged.
  • Since HelloWorldService requires authentication, the service context should be provided with at least one identity. A service context is expected to contain only one identity per repository name.
  • We invoke HelloWorldService remotely, and therefore we should provide client with connection details. This can be done through two ways:
    1. Using dfs-client.xml config file: You should have it under “resources/config” folder.
    2. Using overrided methods of ContextFactory and ServiceFactory factories, it allows to specify explicit location of service:
      IServiceContext registeredContext = ContextFactory.getInstance().register(context, moduleName, contextRoot);
      ServiceFactory.getInstance().getRemoteService(IHelloWorldService.class, registeredContext, moduleName, contextRoot);

Most common scheme of creating and invoking authorized service remotely consists of:

  1. Create service context.
  2. Fill it with identities.
  3. Register context at Context Registry Service and get “clean” context.
  4. Get required service by implemented interface.
  5. Invoke service’s method.

Below is full source code of remote client:

package com.client.example;

import com.emc.documentum.fs.datamodel.core.context.RepositoryIdentity;
import com.emc.documentum.fs.rt.ServiceException;
import com.emc.documentum.fs.rt.context.ContextFactory;
import com.emc.documentum.fs.rt.context.IServiceContext;
import com.emc.documentum.fs.rt.context.ServiceFactory;
import com.service.example.client.IHelloWorldService;

public class HelloWorldClient
{
public static void main(String[] args)
{
String moduleName = “example”;
String contextRoot = “http://localhost:7001/services/”;

ContextFactory contextFactory = ContextFactory.getInstance();
IServiceContext context = contextFactory.newContext();

RepositoryIdentity repoId = new RepositoryIdentity();

repoId.setRepositoryName(”repositoryName”);
repoId.setUserName(”userName”);
repoId.setPassword(”password”);
repoId.setDomain(”");

context.addIdentity(repoId);

try
{
IServiceContext registeredContext = contextFactory.register(context, moduleName, contextRoot);
ServiceFactory serviceFactory = ServiceFactory.getInstance();
IHelloWorldService service = serviceFactory.getRemoteService(IHelloWorldService.class, registeredContext, moduleName, contextRoot);
String response = service.sayHello(”John”);
System.out.println(”response = ” + response);
}
catch (ServiceException e)
{
e.printStackTrace();
}
}
}

I’ve updated helloworldservice.zip with remote client source code.

Next part of .NET remote client will be ready soon.