Custom DFS service development.

先送上一段视频

https://community.emc.com/servlet/JiveServlet/download/1723-1-1461/service_catalog_demo.exe

 

原始文章:http://www.dfsnotes.com/2007/11/14/custom-dfs-service-development-service-creation-part-1/

Some persons from EMC Documentum Forums stated that AcmeCustomService which comes with DFS SDK seems to be too complex for beginners, and “HelloWorld” service would be more understandable. I will try to show you how to create your first own simple HelloWorld like DFS service.

This tutorial will contain of 3 parts:

  • Service creation
  • Java client creation
  • .NET remote client

Before we’ll start, we should setup our build environment.

Note: You should have ant installed in order to run tutorial scripts.

1. Download attached helloworldservice.zip and extract it into emc-dfs-sdk-6.0\samples folder. It contains project template similar to AcmeCustomService. Lets assume “HelloWorldService” folder as root.

2. Open etc\dfc.properties and set host, repository name, username and password for your docbase.

3. Open build.properties and set preferred context root and module names, or leave them as they’re now.

Here is service code:

package com.service.example;

import com.emc.documentum.fs.rt.annotations.DfsPojoService;

@DfsPojoService(targetNamespace = “http://example.service.com”, requiresAuthentication = true)
public class HelloWorldService
{
public String sayHello(String name)
{
return “Hello ” + name;
}
}

@DfsPojoService annotation specifies service’s namespace, and states if service requires docbase authentication (true by default)

Place this source with appropriate package into src\service folder.

Go to root folder (HelloWorldService) and run from command line the following command:

ant artifacts package

This command converts annotated classes to DFS services and package them into ear file.

At this step, you should have example.ear deployment file in HelloWorldService\build folder. This ear file contains our service which can be deployed into Weblogic application server.

Copy this file into weblogic’s autodeploy directory. You can also set weblogic deployment dir at autodeploy.properties file and run “ant deploy” command.

With default values at build.properties, your service should be available by the path: http://host:port/services/example/HelloWorldService

That’s all for now. In the next part of tutorial I will explain how to create client and call this service remotely.

 

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.

 

It’s time to show you how to create .NET remote client for HelloWorldService.

In order to create .NET proxies for DFS service, developers should have:

  • Service’s WSDL URL.
  • DFS service-model.xml file which describes service artifacts to be generated by subsequent processes.

 

The data above is required for DFS Proxy Generator tool which creates .NET DFS proxy:

DFS Proxy Generator

After creation of proxy, it can be used for service instantiation and invocation.

Below is source code which creates and invokes HelloWorldService. As I said in my previous post DFS 6.0 SP1 is coming, Java and .NET DFS API’s are very similar to each other, there is no conceptual differences between them.

Source code:

using System;
using Client.Service;
using Emc.Documentum.FS.DataModel.Core.Context;
using Emc.Documentum.FS.Runtime.Context;

namespace Client
{
class Program
{
static void Main(string[] args)
{
string moduleName = “example”;
string contextRoot = “http://localhost:7001/services”;

ContextFactory contextFactory = ContextFactory.Instance;
IServiceContext context = contextFactory.NewContext();
RepositoryIdentity repoId = new RepositoryIdentity();
repoId.RepositoryName = “yourreponame”;
repoId.UserName = “yourusername”;
repoId.Password = “yourpwd”;

context.AddIdentity(repoId);

// Remote service invocation
IHelloWorldService mySvc;
try
{
context = contextFactory.Register(context, moduleName, contextRoot);
ServiceFactory serviceFactory = ServiceFactory.Instance;
mySvc = serviceFactory.GetRemoteService<IHelloWorldService>(context, moduleName, contextRoot);
string response = mySvc.SayHello(”John”);
Console.WriteLine(”response = ” + response);
}
catch (Exception e)
{
Console.Error.WriteLine(e.StackTrace);
}
}
}
}

This sample is also included in helloworldservice.zip.

P.S: Please note, that DFS SP1 is required in order to build this sample.

posted @ 2008-11-26 23:07  彷徨......  阅读(893)  评论(0编辑  收藏  举报