Custom DFS service development.

來源:互聯網
上載者:User
文章目錄
  • Related Posts
  • Related Posts

先送上一段視頻

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:

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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.