top-image

LATEST ARTICLES

Hi,

I would like to describe step by step how to create a DFS service and DFS client via Composer. In this post, I am not exposing neither the deployment of this DFS service on an application server, neither the configuration of DFC file on server allowing the access to Documentum Content Server.
 
First, what is DFS?
EMC Documentum Foundation Services (DFS) are a set of technologies that enable service-oriented programmatic access to the EMC Documentum Content Server platform and related products. […] The design and technical implementation of DFS is grounded in the principles of Service-Oriented Architecture (SOA).

The DFS Software Development Kit (SDK) includes Java class libraries, .NET assemblies, tools, documentation, and samples that you can use to build DFS services that extend the delivered DFS services, or to build DFS consumers using the optional C# or Java client library.

 


 

DFS Service Creation

  • Create a Documentum Project:



     
     
  • DFS Libraries
    When an Documentum Project is created it also adds all the necessary DFS resources to allow you to develop Documentum services. It will deploy a copy of the DFS SDK to your core project (incidentally this is why creating the first project in a workspace takes a little longer than you might expect) and add the DFS Services Library to your project’s java build path. And add a DFS Builder for building your services.
     
    Click on the Documentum Project and bring up its DFS Module properties:

     
    …then select Builders, you should see DFS builder:

     
    …then select the Java Build Path, then the Libraries tab you will see DFS Service Library:

     
    Some words concerning the DFS Library, If you select DFS Services Library and click on Edit… button:


     
    …OR if you click on Add Library…:



     
    As you can see there are 4 types of DFS Services Library:
    o DFS Services Library: it is the default library used in order to developing services.
    o DFS Remote Client Library with UCF/MTOM: Theses libraries are used in order to developing services consumers.
    o DFS Local Client Library: This library is also used in order to developing services consumers, however, this type of library is added to projects that are acting as “functional tests” for your services projects. Typically, you create one or more of these “functional test” projects in the same workspace as your services projects and configure them with this type of library. This then allows you to debug from the client into the service and back again without having to deploy to a server. A useful feature.

     
     
  • Building a Service
    See : EMC Documentum Documentum Foundation Services Development Guide Version 6.5. : https://www.emc.com/collateral/TechnicalDocument/docu7122.pdf
     
    There are a couple of types of DFS service; based on a POJO OR based on a BOF SBO (service-based object). They are, in fact, very similar and are just annotated java classes.
     
    o Create the com.java.lu.business.ecm.business package in the folder Web Services/src:


     
    o Create the text properties file JavaLuECMService.properties:


     
    o Create the com.java.lu.business.service.ecm.business.exception package in the folder Web Services/src:

     
    o Create the exception class JavaLuECMServiceException.java:

    package com.java.lu.business.service.ecm.business.exception;
    
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlType;
    
    import com.emc.documentum.fs.rt.ServiceException;
    import com.java.lu.business.service.ecm.business.JavaLuECMService;
    
    @XmlType(name = "JavaLuECMServiceException", namespace = "http://exception.business.ecm.service.business.lu.java.com/")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class JavaLuECMServiceException extends ServiceException {
    
    	private static final long serialVersionUID = -8678484668814217250L + JavaLuECMService.buildNumber;
    
    	public JavaLuECMServiceException() {
    		super();
    	}
    
    	public JavaLuECMServiceException(String errorCode, Throwable cause) {
    		super(errorCode, cause);
    	}
    
    	public JavaLuECMServiceException(Throwable cause) {
    		super(cause);
    	}
    }
    

     
    o Create the com.java.lu.business.service.ecm.business.result package in the folder Web Services/src:

     
    o Create the result class BinaryContent.java:

    package com.java.lu.business.service.ecm.business.result;
    
    import java.io.Serializable;
    
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlAttribute;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    
    @XmlType(name = "BinaryContent", namespace = "http://result.business.ecm.service.business.lu.java.com")
    @XmlRootElement(name = "BinaryContent")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class BinaryContent implements Serializable {
    	private static final long serialVersionUID = 8693573608799806206L;
    	@XmlElement(name = "data")
    	private byte[] data;
    	@XmlAttribute(name = "format")
    	private String format;
    
    	public BinaryContent() {
    		this(null, null);
    	}
    
    	public BinaryContent(byte[] data, String format) {
    		this.data = data;
    		this.format = format;
    	}
    
    	public void setData(byte[] data) {
    		this.data = data;
    	}
    
    	public byte[] getData() {
    		return data;
    	}
    
    	public void setFormat(String format) {
    		this.format = format;
    	}
    
    	public String getFormat() {
    		return format;
    	}
    
    	@Override
    	public String toString() {
    		return new StringBuilder().append("<").append(getClass().getSimpleName()).append(" format='").append(getFormat()).append("'>").append("<data>").append(getData()).append("</data></").append(getClass().getSimpleName()).append(">").toString();
    	}
    
    	public final static String XLS_FORMAT = "excel8book";
    	public final static String XLSX_FORMAT = "excel12book";
    	public final static String PDF_FORMAT = "pdf";
    }
    

     
    o Create the result class DocumentInfo.java:

    package com.java.lu.business.service.ecm.business.result;
    
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlAttribute;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    
    
    @XmlType(name = "DocumentInfo", namespace = "http://result.business.ecm.service.business.lu.java.com")
    @XmlRootElement(name = "DocumentInfo")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class DocumentInfo implements Serializable {
    	private static final long serialVersionUID = -8343058576424166034L;
    	@XmlAttribute(name = "objectId")
    	private String objectId;
    	@XmlAttribute(name = "objectName")
    	private String objectName;
    	@XmlElement(name = "content")
    	private BinaryContent content;
    	@XmlElement(name = "errors")
    	private List<ServiceError> errors;
    
    	
    	public DocumentInfo() {
    	}
    
    	public String getObjectName() {
    		return objectName;
    	}
    
    	public void setObjectName(String objectName) {
    		this.objectName = objectName;
    	}
    
    	public String getObjectId() {
    		return objectId;
    	}
    
    	public void setObjectId(String objectId) {
    		this.objectId = objectId;
    	}
    
    	public BinaryContent getContent() {
    		return content;
    	}
    
    	public void setContent(BinaryContent content) {
    		this.content = content;
    	}
    
    	public final List<ServiceError> getErrors() {
    		if (errors == null)
    			errors = new ArrayList<ServiceError>();
    		return errors;
    	}
    
    	public final void setErrors(List<ServiceError> errors) {
    		this.errors = errors;
    	}
    
    	public final void addError(ServiceError error) {
    		this.errors.add(error);
    	}
    
    	public final void addErrors(List<ServiceError> errors) {
    		this.errors.addAll(errors);
    	}
    	
    	@Override
    	public String toString() {
    		StringBuilder sb = new StringBuilder();
    		sb.append("<").append(getClass().getSimpleName());
    		sb.append(" objectId='").append(objectId).append("'");
    		sb.append(" objectName='").append(objectName).append("'");
    		sb.append(">");
    		if (content != null) {
    			sb.append("<content>").append(content).append("</content>");
    		}
    		sb.append(super.toString());
    		sb.append("</").append(getClass().getSimpleName()).append(">");
    		return sb.toString();
    	}
    }
    

     
    o Create the result error class ServiceError.java:

    package com.java.lu.business.service.ecm.business.result;
    
    import java.io.PrintWriter;
    import java.io.Serializable;
    import java.io.StringWriter;
    
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlAttribute;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    
    @XmlType(name = "ServiceError", namespace = "http://result.business.ecm.service.business.lu.java.com")
    @XmlRootElement(name = "ServiceError")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class ServiceError implements Serializable {
    
    	private static final long serialVersionUID = -2515772948068877071L;
    
    	@XmlAttribute(name = "code")
    	private int code;
    	@XmlAttribute(name = "message")
    	private String message;
    	@XmlElement(name = "trace")
    	private String trace;
    
    	public final static int UNDEFINED = 0;
    
    	private static String getStackTraceAsString(Throwable t) {
    		String result = "";
    
    		if (t != null) {
    			StringWriter sw = new StringWriter();
    			PrintWriter pw = new PrintWriter(sw);
    			t.printStackTrace(pw);
    			pw.flush();
    			result = sw.toString();
    		}
    
    		return result;
    	}
    
    	public ServiceError() {
    		this(UNDEFINED, null, null);
    	}
    
    	public ServiceError(int code, String message, String trace) {
    		super();
    		this.code = code;
    		this.message = message;
    		this.trace = trace;
    	}
    
    	public ServiceError(String message) {
    		this(UNDEFINED, message, null);
    	}
    
    	public ServiceError(String message, Throwable trace) {
    		this(UNDEFINED, message, getStackTraceAsString(trace));
    	}
    
    	public int getCode() {
    		return code;
    	}
    
    	public String getMessage() {
    		return message;
    	}
    
    	public String getTrace() {
    		return trace;
    	}
    
    	public void setCode(int code) {
    		this.code = code;
    	}
    
    	public void setMessage(String message) {
    		this.message = message;
    	}
    
    	public void setTrace(String trace) {
    		this.trace = trace;
    	}
    
    	public void setTrace(Throwable trace) {
    		setTrace(getStackTraceAsString(trace));
    	}
    
    	@Override
    	public String toString() {
    		return new StringBuilder().append("<").append(getClass().getSimpleName()).append(" code='").append(getCode()).append("'").append(" message='").append(getMessage()).append("'>").append("<trace>").append(getTrace()).append("</trace>").append("</").append(getClass().getSimpleName()).append(">").toString();
    	}
    }
    

     
    o Create the service class JavaLuECMService.java with a method getDocumentInfo returning a DocumentInfo POJO from a r_object_id of document:

     

    package com.java.lu.business.service.ecm.business;
    
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.Serializable;
    import java.text.MessageFormat;
    import java.util.Properties;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    import org.apache.commons.io.IOUtils;
    import org.apache.log4j.Logger;
    
    import com.documentum.fc.client.DfClient;
    import com.documentum.fc.client.IDfClient;
    import com.documentum.fc.client.IDfDocument;
    import com.documentum.fc.client.IDfSession;
    import com.documentum.fc.client.IDfSessionManager;
    import com.documentum.fc.common.DfException;
    import com.documentum.fc.common.DfLoginInfo;
    import com.documentum.fc.common.IDfLoginInfo;
    import com.documentum.fc.common.impl.MessageHelper;
    import com.emc.documentum.fs.datamodel.core.properties.NumberProperty;
    import com.emc.documentum.fs.datamodel.core.properties.PropertySet;
    import com.emc.documentum.fs.datamodel.core.properties.StringProperty;
    import com.emc.documentum.fs.rt.AuthenticationException;
    import com.emc.documentum.fs.rt.annotations.DfsPojoService;
    import com.java.lu.business.service.ecm.business.exception.JavaLuECMServiceException;
    import com.java.lu.business.service.ecm.business.result.BinaryContent;
    import com.java.lu.business.service.ecm.business.result.DocumentInfo;
    import com.java.lu.business.service.ecm.business.result.ServiceError;
    
    
    @DfsPojoService(requiresAuthentication = false, targetNamespace = "http://business.ecm.service.business.lu.java.com", useDeprecatedExceptionModel = false)
    public class JavaLuECMService implements Serializable {
    	
    	private final static Logger logger = Logger.getLogger(JavaLuECMService.class);
    	private final static PropertySet versionProperties;
    	private static final long serialVersionUID;
    	public static final long buildNumber;
    	
    	static {
    		try {
    			versionProperties = new PropertySet();
    			Properties properties = new Properties();
    			InputStream inputStream = JavaLuECMService.class.getResourceAsStream(JavaLuECMService.class.getSimpleName() + ".properties");
    			try {
    				if(inputStream!=null){
    					properties.load(inputStream);
    					buildNumber = Long.parseLong(properties.getProperty("Build-Number"));
    					serialVersionUID = 1768427593645267965L + buildNumber;
    					for (java.util.Map.Entry<Object, Object> entry : properties.entrySet()) {
    						versionProperties.set(new StringProperty(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())));
    					}
    					versionProperties.set(new NumberProperty("serialVersionUID", serialVersionUID));
    				}else{
    					buildNumber = 1;
    					serialVersionUID = 1768427593645267965L;
    				}
    			} finally {
    				if(inputStream!=null){
    					inputStream.close();
    				}
    			}
    		} catch (IOException e) {
    			throw new RuntimeException(e);
    		}
    	}
    	
    	/**
    	 * Returns various properties set at packaging time.
    	 * 
    	 * @return 
    	 */
    	public PropertySet getVersionProperties() {
    		return versionProperties;
    	}
    	
    	
    	public DocumentInfo getDocumentInfo(String documentId) throws JavaLuECMServiceException, AuthenticationException {
    		if (logger.isDebugEnabled()) {
    			logger.debug(MessageFormat.format("getDocumentInfo(documentId={0}) - START", documentId));
    		}
    		DocumentInfo result;
    		try {
    			//String docbase = com.documentum.services.config.util.DocbaseUtils.getDocbaseNameFromId(documentId);
    			//if (StringUtils.isBlank(docbase)) {
    			//	throw new Exception(MessageFormat.format("Cannot determine repository from objectId {0}", documentId));
    			//}
    			String docbase = "MY_HUO_DOCBASE";			
    			String user = "huoadm";
    			String passwd = "password_4huoadm";
    			
    			IDfSession dfSession = getDfSession(user, passwd, docbase);
    			try {
    				result = new DocumentInfo();
    				// IDfDocument dfDocument = (IDfDocument) dfSession.getObject(new DfId(documentId));
    				IDfDocument dfDocument;
    				{
    					String qualification = getDocumentQualification(documentId);
    					dfDocument = (IDfDocument) dfSession.getObjectByQualification(qualification);
    					if (dfDocument == null) {
    						throw new DfException("Unable to find document for user " + dfSession.getLoginUserName() + " with qualification " + qualification);
    					}
    				}
    
    				// result.setObjectId(dfDocument.getObjectId().getId());
    				result.setObjectId(dfDocument.getChronicleId().getId());
    				result.setObjectName(dfDocument.getObjectName());
    				ByteArrayInputStream input = dfDocument.getContent();
    				try {
    					ByteArrayOutputStream output = new ByteArrayOutputStream();
    					try {
    						IOUtils.copy(input, output);
    						BinaryContent binaryContent = new BinaryContent();
    						binaryContent.setData(output.toByteArray());
    						binaryContent.setFormat(dfDocument.getContentType());
    						result.setContent(binaryContent);
    					} finally {
    						IOUtils.closeQuietly(output);
    					}
    				} finally {
    					IOUtils.closeQuietly(input);
    				}
    			} finally {
    				releaseSession(dfSession);
    			}
    		} catch (Throwable e) {
    			logger.fatal(e.getMessage(), e);
    			result = new DocumentInfo();
    			result.getErrors().add(new ServiceError(ServiceError.UNDEFINED, e.getMessage(), MessageHelper.getStackTraceAsString(e)));
    		}
    		return result;
    	}	
    
    	private IDfSession getDfSession(String user, String passwd, String docbase) throws Exception {
    		IDfLoginInfo login = new DfLoginInfo();
    		login.setUser(user);
    		login.setPassword(passwd);
    		IDfClient client = DfClient.getLocalClient(); // new DfClient();
    		IDfSessionManager sessMgr = client.newSessionManager();
    		sessMgr.setIdentity(docbase, login);
    		IDfSession idfSession = sessMgr.getSession(docbase);
    		if (idfSession != null)
    			System.out.println("Session created successfully");
    
    		return idfSession;
    	}
    	
    	private void releaseSession(IDfSession dfSession) throws Exception {
    		dfSession.getSessionManager().release(dfSession);
    	}
    	
    	private String getDocumentQualification(String documentId) {
    		Pattern pattern = Pattern.compile("^(([a-f0-9]{2})([a-f0-9]{6})([a-f0-9]{8}))$");
    		Matcher matcher = pattern.matcher(documentId);
    		if (!matcher.matches()) {
    			throw new RuntimeException(documentId + " is not a valid objectId");
    		}
    		StringBuilder dql = new StringBuilder();
    		dql.append(" dm_document WHERE r_object_id IN (");
    		dql.append("  SELECT r_object_id");
    		dql.append("  FROM my_huo_document");
    		dql.append("  WHERE ").append("i_chronicle_id").append(" = ID('").append(matcher.group(1)).append("')");
    		dql.append(")");
    		;
    		return dql.toString();
    	}
    	
    
    }
    

     
    o Assuming that you have automatic build turned on from project menu in composer, you should see the DFS Builder leap into life and attempt to build the service. In your Console view you’ll get a build report:

    Buildfile: C:\Workspaces\DocumentumCoreProject\dfs6.7\dfs-build.xml
    …
    
    generate:
    [generateModel] Creating 'myservices-mybusiness-service-model.xml'
    [generateArtifacts] Log4j not found. In order to avoid error messages during build process, please include log4j.jar into your classpath or copy it into $ANT_HOME/lib folder
    [generateArtifacts] Generating DFS artifacts
    [generateArtifacts] Generating JAXWS artifacts (wsgen & wsimport)
    [generateArtifacts] Note: C:\Users\HUSEYI~1\AppData\Local\Temp\dfs-sdk-3247901826753623178-server-artifacts-generator\wsimport\wsgen\generated\src\com\java\lu\business\service\ecm\business\ws\JavaLuECMServiceWebService.java uses unchecked or unsafe operations.
    [generateArtifacts] Note: Recompile with -Xlint:unchecked for details.
    [generateArtifacts] fdir.getAbsolutePath() = C:\Users\HUSEYI~1\AppData\Local\Temp\dfs-sdk-3247901826753623178-server-artifacts-generator\wsimport\wsgen\wsdl\com.java.lu.business.service.ecm.business.ws
    [generateArtifacts] ------------------------------------------------------------
    [generateArtifacts] SerializableExceptionPostProcessor.addSerializableException
    [generateArtifacts] file = C:\Users\HUSEYI~1\AppData\Local\Temp\dfs-sdk-3247901826753623178-server-artifacts-generator\wsimport\src\com\java\lu\business\service\ecm\business\ws\JavaLuECMServicePort.java
    [generateArtifacts] ------------------------------------------------------------
    BUILD SUCCESSFUL
    Total time: 22 seconds
    

     
    o After building, the Web Services/bin/gen-src folder contains a set of generated sources from the POJO service : jax-ws web service sources, a set of classes and wsdl.

     
     

  • Export/Test the service
     
    There are two approaches to test our service:
     
    o The first approach is to create a parallel test project with Junit tests that exercise your service. To facilitate this your test project would be configured with the local client library, as described above, so that it can make local invocations to your service. This project should of course be placed under the same version control as your services project.
     
    o The second approach is to export your services as an ear, deploy it to an application server and exercise your service again via another project capable of making remote service invocations. The service’s context root and module name affect the URL of service, these informations must be set via right-click on the project and select Properties->Documentum Project->DFS Module:


     
    Here, we use the second approach:
     
    o Right-click on the project and select Export…, then Documentum >> Export Service Archive to generate ear of service and client reference library:

     

    o Select the output folder and uncheck the Generate Publish Manifest checkbox:

    Tips: To avoid re-entering the destination directory each time, change the Export Directory setting in Preferences in COMPOSER:

     

    o Click on Finish button to launch the generation:


     

    Override ignored for property "TODAY"
        [mkdir] Created dir: C:\temp\dfs6.7sp2\20171109141738
         [copy] Copying 1 file to C:\temp\dfs6.7sp2\20171109141738
         [copy] Copying C:\temp\dfs6.7sp2\mybusiness.ear to C:\temp\dfs6.7sp2\20171109141738\DOCmybusiness-1.3.141.ear
         [copy] Copying 1 file to C:\temp\dfs6.7sp2\20171109141738
         [copy] Copying C:\temp\dfs6.7sp2\mybusiness-remote.jar to C:\temp\dfs6.7sp2\20171109141738\mybusiness-remote.jar
         [move] Moving 1 file to C:\temp\dfs6.7sp2
         [move] Attempting to rename: C:\temp\dfs6.7sp2\mybusiness.ear to C:\temp\dfs6.7sp2\DOCmybusiness-1.3.141.ear
         [move] Moving 1 file to C:\temp\dfs6.7sp2
         [move] Skipping self-move of C:\temp\dfs6.7sp2\mybusiness-remote.jar
    BUILD SUCCESSFUL
    
    BUILD SUCCESSFUL
    Total time: 1 minute 4 seconds
    

     
     

  • This will produce:
    o an ear file which can be deploy onto an application server (websphere, tomcat…) : mybusiness.ear
    o a jar file containing the client classes : mybusiness-remote.jar
     
    The output folder contains the ear file (service) and the jar (remote) and a subfolder “YYYYMMDDHHMISS” with the previous ear.


     
    Note : The naming of ear file is configurable in dfs6.7 folder of DocumentumCoreProject project:
    dfs-build.xml:

    <property name="ear.filename.new" value="DOC${module.name}-${build.version}.ear" />
    <property name="build.version" value="${application.version}.${release.version}.${build.number}" />
    

    dfs-build.properties:

    module.name=module-name
    application.version=1
    release.version=3
    build.number=141
    

     
     

  • Deployment of EAR on Application Server
    Once EAR file deployed, you can perform a quick sanity check by requesting the service’s WSDL document: http://localhost:9080/myservices/mybusiness/JavaLuECMService

     
    The WSDL is available http://localhost:9080/myservices/mybusiness/JavaLuECMService?wsdl

    This XML file does not appear to have any style information associated with it. The document tree is shown below.
    <!--
     Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.7-b01-. 
    -->
    <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.business.ecm.service.business.lu.java.com/"xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="JavaLuECMService" targetNamespace="http://ws.business.ecm.service.business.lu.java.com/">
    <types>
    <xsd:schema>
    <xsd:import namespace="http://ws.business.ecm.service.business.lu.java.com/" schemaLocation="http://localhost:9080/myservices/mybusiness/JavaLuECMService?xsd=1"/>
    </xsd:schema>
    <xsd:schema>
    <xsd:import namespace="http://rt.fs.documentum.emc.com/" schemaLocation="http://localhost:9080/myservices/mybusiness/JavaLuECMService?xsd=2"/>
    </xsd:schema>
    <xsd:schema>
    <xsd:import namespace="http://result.business.ecm.service.business.lu.java.com" schemaLocation="http://localhost:9080/myservices/mybusiness/JavaLuECMService?xsd=3"/>
    </xsd:schema>
    <xsd:schema>
    <xsd:import namespace="http://properties.core.datamodel.fs.documentum.emc.com/" schemaLocation="http://localhost:9080/myservices/mybusiness/JavaLuECMService?xsd=4"/>
    </xsd:schema>
    <xsd:schema>
    <xsd:import namespace="http://core.datamodel.fs.documentum.emc.com/" schemaLocation="http://localhost:9080/myservices/mybusiness/JavaLuECMService?xsd=5"/>
    </xsd:schema>
    <xsd:schema>
    <xsd:import namespace="http://content.core.datamodel.fs.documentum.emc.com/" schemaLocation="http://localhost:9080/myservices/mybusiness/JavaLuECMService?xsd=6"/>
    </xsd:schema>
    </types>
    <message name="getVersionProperties">
    <part element="tns:getVersionProperties" name="parameters"/>
    </message>
    <message name="getVersionPropertiesResponse">
    <part element="tns:getVersionPropertiesResponse" name="parameters"/>
    </message>
    <message name="ServiceException">
    <part xmlns:ns1="http://rt.fs.documentum.emc.com/" element="ns1:ServiceException" name="fault"/>
    </message>
    <message name="getDocumentInfo">
    <part element="tns:getDocumentInfo" name="parameters"/>
    </message>
    <message name="getDocumentInfoResponse">
    <part element="tns:getDocumentInfoResponse" name="parameters"/>
    </message>
    <message name="AuthenticationException">
    <part element="tns:AuthenticationException" name="fault"/>
    </message>
    <message name="JavaLuECMServiceException">
    <part element="tns:JavaLuECMServiceException" name="fault"/>
    </message>
    <portType name="JavaLuECMServicePort">
    <operation name="getVersionProperties">
    <documentation>
    Returns various properties set at packaging time. @return
    </documentation>
    <input message="tns:getVersionProperties"/>
    <output message="tns:getVersionPropertiesResponse"/>
    <fault message="tns:ServiceException" name="ServiceException"/>
    </operation>
    <operation name="getDocumentInfo">
    <input message="tns:getDocumentInfo"/>
    <output message="tns:getDocumentInfoResponse"/>
    <fault message="tns:AuthenticationException" name="AuthenticationException"/>
    <fault message="tns:JavaLuECMServiceException" name="JavaLuECMServiceException"/>
    <fault message="tns:ServiceException" name="ServiceException"/>
    </operation>
    </portType>
    <binding name="JavaLuECMServicePortBinding" type="tns:JavaLuECMServicePort">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="getVersionProperties">
    <soap:operation soapAction=""/>
    <input>
    <soap:body use="literal"/>
    </input>
    <output>
    <soap:body use="literal"/>
    </output>
    <fault name="ServiceException">
    <soap:fault name="ServiceException" use="literal"/>
    </fault>
    </operation>
    <operation name="getDocumentInfo">
    <soap:operation soapAction=""/>
    <input>
    <soap:body use="literal"/>
    </input>
    <output>
    <soap:body use="literal"/>
    </output>
    <fault name="AuthenticationException">
    <soap:fault name="AuthenticationException" use="literal"/>
    </fault>
    <fault name="JavaLuECMServiceException">
    <soap:fault name="JavaLuECMServiceException" use="literal"/>
    </fault>
    <fault name="ServiceException">
    <soap:fault name="ServiceException" use="literal"/>
    </fault>
    </operation>
    </binding>
    <service name="JavaLuECMService">
    <port binding="tns:JavaLuECMServicePortBinding" name="JavaLuECMServicePort">
    <soap:address location="http://localhost:9080/myservices/mybusiness/JavaLuECMService"/>
    </port>
    </service>
    </definitions>
    

     
     

 


 

DFS Service Client Creation

  • Create a Documentum Project:

     
  • Change the default DFS Services Library to DFS Local Client Library:

     
  • Add the jar xxxx-remote.jar previously generated in the Java Build Path of Client project:


     

  • Create a new package com.java.lu.test in the folder src / com.java.lu.test:

     
  • Create a class JavaLuECMServiceClient:

     

    package com.java.lu.test;
    
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Set;
    import java.util.TreeSet;
    
    import javax.xml.bind.JAXBContext;
    import javax.xml.namespace.QName;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.soap.SOAPEnvelope;
    import javax.xml.soap.SOAPFactory;
    import javax.xml.soap.SOAPHeader;
    import javax.xml.ws.handler.Handler;
    import javax.xml.ws.handler.HandlerResolver;
    import javax.xml.ws.handler.MessageContext;
    import javax.xml.ws.handler.PortInfo;
    import javax.xml.ws.handler.soap.SOAPHandler;
    import javax.xml.ws.handler.soap.SOAPMessageContext;
    
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    
    import com.emc.documentum.fs.datamodel.core.context.BasicIdentity;
    import com.emc.documentum.fs.datamodel.core.context.ServiceContext;
    import com.java.lu.business.service.ecm.business.result.DocumentInfo;
    import com.java.lu.business.service.ecm.business.ws.JavaLuECMService;
    import com.java.lu.business.service.ecm.business.ws.JavaLuECMServicePort;
    import com.sun.xml.internal.bind.api.JAXBRIContext;
    
    public class JavaLuECMServiceClient {
    
    	public static void main(String[] args) {
    		try {
    			final JavaLuECMServicePort service = registerToDocumentum("http://localhost:9080/myservices/mybusiness/JavaLuECMService?wsdl", "huoadm", " password_4huoadm");
    			DocumentInfo documentInfo = service.getDocumentInfo("0902xxxxxxe14");
    			System.out.println(documentInfo.getObjectId());
    			System.out.println(documentInfo.getObjectName());
    			System.out.println(documentInfo.getContent().getFormat());
    			System.out.println(documentInfo.getContent().getData().length);
    
    		} catch (Throwable e) {
    			e.printStackTrace();
    		}
    	}
    
    	private static JavaLuECMServicePort registerToDocumentum(String urlWS, String user, String pwd) {
    		try {
    			ServiceContext serviceContext = new ServiceContext();
    			BasicIdentity basicIdentity = new BasicIdentity();
    			basicIdentity.setUserName(user);
    			basicIdentity.setPassword(pwd);
    			serviceContext.getIdentities().add(basicIdentity);
    			JAXBContext j = JAXBRIContext.newInstance(ServiceContext.class);
    			Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    			j.createMarshaller().marshal(serviceContext, document);
    			final Element wsseSecurity = document.getDocumentElement();
    			
    			JavaLuECMService yourWebService = new JavaLuECMService(new URL(urlWS), new QName("http://ws.business.ecm.service.business.lu.java.com/", "JavaLuECMService"));
    			yourWebService.setHandlerResolver(new HandlerResolver() {
    				public List<Handler> getHandlerChain(PortInfo portInfo) {
    					List<Handler> handlerList = new ArrayList<Handler>();
    					handlerList.add(new SOAPHandler<SOAPMessageContext>() {
    						public void close(MessageContext context) {
    						}
    
    						public Set<QName> getHeaders() {
    							return new TreeSet<QName>();
    						}
    
    						public boolean handleFault(SOAPMessageContext context) {
    							throw new UnsupportedOperationException("Not supported yet.");
    						}
    
    						public boolean handleMessage(SOAPMessageContext context) {
    							Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    							if (outboundProperty.booleanValue()) {
    								try {
    									SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
    									SOAPHeader header = envelope.addHeader();
    									header.addChildElement(SOAPFactory.newInstance().createElement(wsseSecurity));
    								} catch (Exception e) {
    									System.out.println("Exception in handler: " + e);
    								}
    							} else {
    								// inbound
    							}
    							return true;
    						}
    					});
    					return handlerList;
    				}
    			});
    			return yourWebService.getJavaLuECMServicePort();
    
    		} catch (Exception e) {
    			throw new RuntimeException(e);
    		}
    	}	
    }
    

     
     

  • Execute this client class:
    0902xxxxxxe14
    My doc name
    excel12book
    8739
    

That’s all!!!

Huseyin OZVEREN

Hi,

Here, a very useful class exposing a lot of functionalities of Documentum (found on the Internet https://worldofchaitu.wordpress.com/2012/11/08/documentum-dfc-standalone-sample-program/):

  • To get a list of available docbase
  • To create a cabinet (dm_cabinet) in docbase
  • To create a folder (dm_folder object) in docbase
  • To create a document (dm_document object) in docbase
  • To check out a document from docbase using IDfOperations
  • To check in a document to docbase using IDfOperations making use of IAPI methods
  • To import a document into docbase
  • To cancelcheckout a document into docbase
  • To check out a document from docbase
  • To check in a document to docbase
  • To delete a document from docbase
  • To update document’s in docbase
  • To retrieve document’s attributes from docbase
  • To create a virtual document in docbase
  • To export a virtual document from docbase
  • To view virtual document from docbase
  • To retrieve document from document using IDQL
  • To create and start workflow
  • To view task in inbox
  • To attach a lifeCycle to a document in docbase
  • To promote a lifeCycle state of a document
  • To demote a lifeCycle state of a document
  • To expire a lifeCycle state of a document
  • To resume a lifeCycle state of a document
  • To assign a ACL to a document
package com.huo.test.ecm.test1;

import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.StringTokenizer;

import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
import com.documentum.fc.client.DfClient;
import com.documentum.fc.client.DfQuery;
import com.documentum.fc.client.IDfACL;
import com.documentum.fc.client.IDfActivity;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfCollection;
import com.documentum.fc.client.IDfDocbaseMap;
import com.documentum.fc.client.IDfDocument;
import com.documentum.fc.client.IDfFolder;
import com.documentum.fc.client.IDfProcess;
import com.documentum.fc.client.IDfQuery;
import com.documentum.fc.client.IDfQueueItem;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.client.IDfSysObject;
import com.documentum.fc.client.IDfType;
import com.documentum.fc.client.IDfTypedObject;
import com.documentum.fc.client.IDfVirtualDocument;
import com.documentum.fc.client.IDfVirtualDocumentNode;
import com.documentum.fc.client.IDfWorkflow;
import com.documentum.fc.client.IDfWorkflowBuilder;
import com.documentum.fc.client.IDfWorkitem;
import com.documentum.fc.common.DfList;
import com.documentum.fc.common.DfLoginInfo;
import com.documentum.fc.common.IDfAttr;
import com.documentum.fc.common.IDfId;
import com.documentum.fc.common.IDfList;
import com.documentum.fc.common.IDfLoginInfo;
import com.documentum.operations.IDfCancelCheckoutNode;
import com.documentum.operations.IDfCancelCheckoutOperation;
import com.documentum.operations.IDfCheckinNode;
import com.documentum.operations.IDfCheckinOperation;
import com.documentum.operations.IDfCheckoutNode;
import com.documentum.operations.IDfCheckoutOperation;
import com.documentum.operations.IDfExportNode;
import com.documentum.operations.IDfExportOperation;
import com.documentum.operations.IDfImportNode;
import com.documentum.operations.IDfImportOperation;
import com.documentum.operations.IDfOperation;
import com.documentum.operations.IDfOperationError;

/**
 See https://webcache.googleusercontent.com/search?q=cache:MW2FjC-Rg7YJ:https://worldofchaitu.wordpress.com/2012/11/08/documentum-dfc-standalone-sample-program/+&cd=3&hl=en&ct=clnk&gl=lu
 Documentum DFC Standalone Sample Program


 This blog contains sample DFC code snippet of all basic functionalities of Documentum

 To get a list of available docbase
 To create a cabinet (dm_cabinet) in docbase
 To create a folder (dm_folder object) in docbase
 To create a document (dm_document object) in docbase
 To check out a document from docbase using IDfOperations
 To check in a document to docbase using IDfOperations making use of IAPI methods
 To import a document into docbase
 To cancelcheckout a document into docbase
 To check out a document from docbase
 To check in a document to docbase
 To delete a document from docbase
 To update document's in docbase
 To retrieve document's attributes from docbase
 To create a virtual document in docbase
 To export a virtual document from docbase
 To view virtual document from docbase
 To retrieve document from document using IDQL
 To create and start workflow
 To view task in inbox
 To attach a lifeCycle to a document in docbase
 To promote a lifeCycle state of a document
 To demote a lifeCycle state of a document
 To expire a lifeCycle state of a document
 To resume a lifeCycle state of a document
 To assign a ACL to a document
**/

public class DFCWorkShop {

	IDfSysObject sysObject = null;
	IDfSession idfSession = null;
	IDfSessionManager sessMgr = null;

	public DFCWorkShop(String user, String passwd, String docbase) throws Exception {
		getDfSession(user, passwd, docbase);
	}

	public IDfSession getDfSession(String args1, String args2, String args3)
			throws Exception {
		
		IDfLoginInfo login = new DfLoginInfo();
		login.setUser(args1);
		login.setPassword(args2);
		IDfClient client = DfClient.getLocalClient(); //new DfClient();
		sessMgr = client.newSessionManager();
		sessMgr.setIdentity(args3, login);
		idfSession = sessMgr.getSession(args3);

		if (idfSession != null)
			System.out.println("Session created successfully");

		return idfSession;
	}


	public void releaseSession() throws Exception {
		sessMgr.release(idfSession);
	}
	
	public void getAllDocbases() throws Exception {

		IDfClient client = DfClient.getLocalClient();
		IDfDocbaseMap docbaseMap = client.getDocbaseMap();
		for (int i = 0; i < docbaseMap.getDocbaseCount(); i++) {
			System.out.println("Docbase Name : " + docbaseMap.getDocbaseName(i));
			System.out.println("Docbase Desc : " + docbaseMap.getDocbaseDescription(i));
		}
	}

	public void createCabinet() throws Exception {

		IDfFolder cabinet = (IDfFolder) idfSession.newObject("dm_cabinet");
		if (cabinet != null) {
			cabinet.setObjectName("Training Cabinet XXX");
			cabinet.save();
		}
	}

	public void createFolder() throws Exception {

		IDfFolder folder = (IDfFolder) idfSession.newObject("dm_folder");
		if (folder != null) {
			folder.setObjectName("Folder Level 2");
			folder.link("/Training Cabinet XXX");
			folder.save();
		}
	}

	public IDfDocument createDocument() throws Exception {

		IDfDocument document = (IDfDocument) idfSession
				.newObject("dm_document");
		if (document != null) {
			document.setObjectName("Test-Document");
			document.setContentType("crtext");
			document.setFile("C:\\Documentum\\config\\dfc.properties");
			document.link("/Training Cabinet XXX/Folder Level 1");
			document.save();
		}
		return document;
	}

	public void updateAttributes() throws Exception {

		sysObject = (IDfSysObject) idfSession
				.getObjectByPath("/Training Cabinet XXX/Folder Level 1/New Document");
		sysObject.setString("object_name", "New Document");
		sysObject.setString("authors", "Prasad");
		sysObject.setRepeatingString("authors", 1, "RamKumar");
		sysObject.save();
	}

	public void getAttributes() throws Exception {

		sysObject = (IDfSysObject) idfSession
				.getObjectByPath("/Training Cabinet XXX/Folder Level 1/New Document");
		if (sysObject != null) {
			System.out.println("objectName "
					+ sysObject.getString("object_name"));
			// System.out.println("authors " + sysObject.getString("authors"));
			String authors = sysObject.getAllRepeatingStrings("authors", ",");

			List list = new ArrayList();
			StringTokenizer st = new StringTokenizer(authors, ",");
			System.out.println("length of st " + st.countTokens());
			while (st.hasMoreTokens()) {
				list.add(st.nextElement());
			}
			System.out.println("length " + list.size());

			for (int i = 0; i < list.size(); i++) {
				System.out.println("Author[" + i + "] " + list.get(i));
			}
		}
	}

	public void getTypeAttributes() throws Exception {

		IDfType type = (IDfType) idfSession.newObject("dm_document");
		for (int i = 0; i < type.getAttrCount(); i++) {
			IDfAttr attr = type.getAttr(i);
			System.out.println("Name " + attr.getName());
			System.out.println("Datatype " + attr.getDataType());
			System.out.println("Length " + attr.getLength());
			System.out.println("IS Repeating Attr " + attr.isRepeating());
		}
	}

	public void checkoutDoc() throws Exception {

		sysObject = (IDfSysObject) idfSession
				.getObjectByPath("/Training Cabinet XXX/Folder Level 1/");
		if (!sysObject.isCheckedOut()) // if it is not checked out
			sysObject.checkout();

		System.out.println("is Check out " + sysObject.isCheckedOut());
	}

	public void checkinDoc() throws Exception {

		sysObject = (IDfSysObject) idfSession
				.getObjectByPath("/Training Cabinet XXX/Folder Level 1/Test-Document");

		if (sysObject.isCheckedOut()) { // if it is checked out
			sysObject.checkin(false, "CURRENT");
		}
	}

	public void deleteDoc() throws Exception {

		sysObject = (IDfSysObject) idfSession
				.getObjectByPath("/Training Cabinet XXX/Folder Level 1/Test-Document");
		if (sysObject != null) {
			sysObject.destroyAllVersions(); // delete all versions
			System.out.println("object destroyed…..");
		}
	}

	public void createVirtualDocument() throws Exception {

		IDfSysObject pSys = (IDfSysObject) idfSession
				.getObjectByPath("/Training Cabinet XXX/Folder Level 2/log4j.properties");
		IDfSysObject cSys = (IDfSysObject) idfSession
				.getObjectByPath("/Training Cabinet XXX/Folder Level 1/trace.log");

		pSys.setIsVirtualDocument(true);
		pSys.save();
		IDfVirtualDocument vDoc = pSys.asVirtualDocument("CURRENT", false);
		IDfVirtualDocumentNode pNode = vDoc.getRootNode();
		pSys.checkout();

		IDfVirtualDocumentNode nodeChild1 = vDoc.addNode(pNode, null, cSys
				.getChronicleId(), "CURRENT", false, false);

		pSys.checkin(false, "CURRENT");
	}

	public void viewVirtualDocument() throws Exception {

		IDfSysObject pSys = (IDfSysObject) idfSession
				.getObjectByPath("/Training Cabinet XXX/Folder Level 2/log4j.properties");
		if (pSys.isVirtualDocument()) {
			System.out.println("virtual document –> true");
			IDfVirtualDocument vDoc = pSys.asVirtualDocument("CURRENT", false);
			IDfVirtualDocumentNode pNode = vDoc.getRootNode();

			System.out.println("Iterating thru the lis to get the child nodes");
			for (int i = 0; i < pNode.getChildCount(); i++) {
				IDfVirtualDocumentNode cNode = pNode.getChild(i);
				System.out.println("Child Name "
						+ cNode.getSelectedObject().getObjectName());
			}
		}
	}

	public void exportVirtualDocument() throws Exception {

		System.out.println("exporting virtual document");

		IDfClientX clientx = new DfClientX();
		IDfExportOperation expOperation = clientx.getExportOperation();

		IDfSysObject sysObject = (IDfSysObject) idfSession
				.getObjectByPath("/Training Cabinet XXX/Folder Level 2/log4j.properties");
		if (sysObject.isVirtualDocument()) {
			IDfVirtualDocument Vdoc = sysObject.asVirtualDocument("CURRENT",
					false);
			IDfExportNode expNode = (IDfExportNode) expOperation.add(sysObject);
			expOperation.setDestinationDirectory(expOperation
					.getDefaultDestinationDirectory());
			boolean flag = expOperation.execute();
			displayError(expOperation, flag);
		}
	}

	public void cancelCheckoutDocument() throws Exception {

		IDfClientX clientx = new DfClientX();
		IDfCancelCheckoutOperation cancelcheckoutOper = clientx
				.getCancelCheckoutOperation();
		sysObject = (IDfSysObject) idfSession
				.getObjectByPath("/Training Cabinet XXX/Folder Level 2/log4j.properties");

		IDfCancelCheckoutNode node = (IDfCancelCheckoutNode) cancelcheckoutOper
				.add(sysObject);
		boolean flag = cancelcheckoutOper.execute();
		displayError(cancelcheckoutOper, flag);
	}

	public void checkoutDocument() throws Exception {

		IDfClientX clientx = new DfClientX();
		IDfCheckoutOperation checkoutOper = clientx.getCheckoutOperation();

		System.out.println("Checkout Dir "
				+ checkoutOper.getDefaultDestinationDirectory());
		checkoutOper.setDestinationDirectory(checkoutOper
				.getDefaultDestinationDirectory());

		sysObject = (IDfSysObject) idfSession
				.getObjectByPath("/Training Cabinet XXX/Folder Level 2/log4j.properties");

		IDfCheckoutNode node = (IDfCheckoutNode) checkoutOper.add(sysObject);
		boolean flag = checkoutOper.execute();
		displayError(checkoutOper, flag);

	}

	public void checkinDocument() throws Exception {

		IDfClientX clientx = new DfClientX();
		IDfCheckinOperation checkinOper = clientx.getCheckinOperation();

		IDfCheckinNode node = (IDfCheckinNode) checkinOper.add(sysObject);
		System.out.println("Flag —->" + checkinOper.execute());
	}

	public void importDocument() throws Exception {

		IDfSysObject sysObject = (IDfFolder) idfSession
				.getObjectByPath("/Training Cabinet XXX/Folder Level 2");
		System.out.println("Object ID " + sysObject.getObjectId());

		IDfClientX clientx = new DfClientX();
		IDfImportOperation importOper = clientx.getImportOperation();
		importOper.setSession(idfSession);

		if (importOper == null)
			System.out.println("operation object is null");

		importOper.setDestinationFolderId(sysObject.getObjectId());
		importOper.setVersionLabels("imported using operation");

		IDfImportNode node = (IDfImportNode) importOper
				.add("C:\\Documentum\\config\\log4j.properties");
		node.setFormat("pdf");

		boolean flag = importOper.execute();
		displayError(importOper, flag);
	}

	public void displayError(IDfOperation operation, boolean flag)
			throws Exception {

		if (!flag) {

			IDfList errlist = operation.getErrors();

			for (int i = 0; i < errlist.getCount(); i++) {
				IDfOperationError errOperation = (IDfOperationError) errlist
						.get(i);
				System.out.println("Error MSG " + errOperation.getMessage());
			}
		}
	}

	public void dmclAPI() throws Exception {

		System.out.println("Starting...");
		IDfSysObject sysObj = (IDfSysObject) idfSession
				.getObjectByQualification("dm_document where object_name='Test-Document'");
		String rObjectId = sysObj.getObjectId().getId();

		String name = (String) idfSession.apiGet("get", rObjectId+ ",object_name");
		System.out.println("Name : " + name);
		// idfSession.apiSet("set",rObjectId+",title","sample-doc");
		idfSession.apiExec("link",rObjectId+",/Training Cabinet XXX/Folder Level 2");
		System.out.println("Linked " + idfSession.apiExec("save", rObjectId));
	}

	public void collection() throws Exception {

		IDfQuery query = new DfQuery();
		query
				.setDQL("select * from dm_document where object_name='New Document' and any r_version_label like 'CURRENT%'");
		IDfCollection coll = query.execute(idfSession, 0);

		while (coll.next()) {
			IDfTypedObject typeObject = (IDfTypedObject) coll.getTypedObject();
			System.out.println("Object Name "
					+ typeObject.getString("r_object_id"));
			System.out.println("creation date "
					+ typeObject.getString("r_creation_date"));
		}

		if (coll != null)
			coll.close();
	}

	public void startWorkflow() throws Exception {

		// to get the attachment document
		IDfSysObject sysObj = (IDfSysObject) idfSession
				.getObjectByQualification("dm_document where object_name='DFCtest'");

		// to get the Workflow Template
		IDfProcess process = (IDfProcess) idfSession
				.getObjectByQualification("dm_process where object_name like '%INDIA_TIMES%'");

		// to create a Workflo Builder to start a workflow
		IDfWorkflowBuilder builder = idfSession.newWorkflowBuilder(process
				.getObjectId());
		IDfId wfId = builder.initWorkflow();

		// get the First Activity
		IDfList startActivityNames = builder.getStartActivityNames();
		IDfList startActivities = builder.getStartActivityIds();
		String activityName = startActivityNames.getString(0);
		IDfId activityID = (IDfId) startActivities.get(0);
		IDfActivity activity = (IDfActivity) idfSession.getObject(activityID);

		// to get the Package Name , Port and Package DocType
		int nPorts = activity.getPortCount();
		String InputPortName = null;
		String PkgType = null;
		String PkgName = null;

		for (int j = 0; j < nPorts; j++) {
			System.out.println("Port Name: " + activity.getPortName(j) + ", "
					+ "Port Type = " + activity.getPortType(j));

			if (activity.getPortType(j).equals("INPUT")) {
				InputPortName = activity.getPortName(j);
				PkgType = activity.getPackageType(j);
				PkgName = activity.getPackageName(j);
			}
		}

		// to Add the attachment document to List
		IDfList dfList = new DfList();
		dfList.append(sysObj.getObjectId());

		IDfId wfId2 = builder.runWorkflow();
		// Add a Package to Workflow Builder
		builder.addPackage(activityName, InputPortName, PkgName, PkgType, null,
				false, dfList);
		System.out.println("package added");

	}

	public void getInbox() throws Exception {
		// IDfCollection getTasks(String userName, int filter, String additionalAttributes, String orderBy)
		IDfCollection tasks = idfSession.getTasks("huoadm", IDfSession.DF_TASKS, "name, date_sent, message ", "task_name");

		try {
			while (tasks.next()) {
				IDfWorkitem wi = (IDfWorkitem) idfSession.getObject(tasks.getId("item_id"));
				IDfId queueItemId = wi.getQueueItemId();
				IDfQueueItem qi = (IDfQueueItem) idfSession.getObject(queueItemId);
				System.out.println(tasks.getString("sent_by") + "   "
								+ tasks.getString("task_name") + "   "
								+ tasks.getString("date_sent") + "   "
								+ tasks.getString("message") + "   "
								+ qi.getItemName());
				IDfActivity dfActivity = wi.getActivity();
				System.out.println("\tActivity Information : " + dfActivity.getString("object_name"));
				IDfCollection packColl = null;
				try {
					packColl = wi.getPackages("");
					while (packColl.next()) {
						IDfSysObject sysObj = (IDfSysObject) idfSession.getObject(packColl.getId("r_component_id"));
						System.out.println("\t Package Information: " + sysObj.getString("object_name"));
					}
					
				} finally {
					if (packColl != null)
						packColl.close();
				}
				// to finish a Task or Workitem
				// finishTask(wi);
			}
		} finally {
			if (tasks != null)
				tasks.close();
		}
	}

	public void finishTask(IDfWorkitem wi) throws Exception {

		if (wi.getRuntimeState() == IDfWorkflow.DF_WF_STATE_DORMANT) {
			wi.acquire();
		}
		wi.complete();
	}

	public void attachLC() throws Exception {

		IDfSysObject mDocs = (IDfSysObject) idfSession
				.getObjectByQualification("dm_document where object_name='UniqueDoc' ");

		IDfSysObject procObj = (IDfSysObject) idfSession
				.getObjectByQualification("dm_policy where object_name='Training_LC' ");
		mDocs.attachPolicy(procObj.getObjectId(), "Author", "");

	}

	public void promoteLC(String State) throws Exception {
		IDfSysObject mDocs = (IDfSysObject) idfSession
				.getObjectByQualification("dm_document where object_name='UniqueDoc' ");
		mDocs.promote(State, false, false);
	}

	public void demoteLC(String State) throws Exception {
		IDfSysObject mDocs = (IDfSysObject) idfSession
				.getObjectByQualification("dm_document where object_name='UniqueDoc' ");
		mDocs.demote(State, false);
	}

	public void expireLC(String State) throws Exception {
		IDfSysObject mDocs = (IDfSysObject) idfSession
				.getObjectByQualification("dm_document where object_name='UniqueDoc' ");
		mDocs.suspend(State, false, false);
	}

	public void resumeLC(String State) throws Exception {
		IDfSysObject mDocs = (IDfSysObject) idfSession
				.getObjectByQualification("dm_document where object_name='UniqueDoc' ");
		mDocs.resume(State, false, false, false);
	}


	public void assignACL() throws Exception {

		IDfSysObject mDocs = (IDfSysObject) idfSession
				.getObjectByQualification("dm_document where object_name='UniqueDoc' ");
		IDfACL dfACL = (IDfACL) idfSession
				.getObjectByQualification("dm_acl where object_name='TrainingACL' ");
		mDocs.setACL(dfACL);
		mDocs.save();
	}

	
	public static void main(String[] args) throws Exception {

		String user = "huoadm";
		String passwd = "pass_4_huoadm";
		String docbase = "MY_DOCBASE_DEV";
		DFCWorkShop object = new DFCWorkShop(user, passwd, docbase);

		try {

			// To get a list of available docbase
			/*
				Session created successfully
				Docbase Name : MY_DOCBASE2_DEV
				Docbase Desc : Company Repository 2
				Docbase Name : MY_DOCBASE_DEV
				Docbase Desc : Company Repository
				Docbase Name : GLOBALR
				Docbase Desc : Global Registry Repository
				Docbase Name : MY_DOCBASE3_DEV
				Docbase Desc : Company Repository 3
				Docbase Name : MY_DOCBASE4_DEV
				Docbase Desc : Company Repository 4 
			 */
//			object.getAllDocbases();

			// To create a cabinet (dm_cabinet) in docbase
			// object.createCabinet();

			// To create a folder (dm_folder object) in docbase
			// object.createFolder();

			// To create a document (dm_document object) in docbase
			// object.createDocument();

			// To check out a document from docbase using IDfOperations
			// object.checkoutDocument();

			// To check in a document to docbase using IDfOperations
			// object.checkinDocument();

			// making use of IAPI methods
			// object.dmclAPI();

			// To import a document into docbase
			// object.importDocument();

			// To cancelcheckout a document into docbase
			// object.cancelCheckoutDocument();

			// To check out a document from docbase
			// object.checkoutDoc();

			// To check in a document to docbase
			// object.checkinDoc();

			// To delete a document from docbase
			// object.deleteDoc();

			// To update document's in docbase
			// object.updateAttributes();

			// To retrieve document's attributes from docbase
			// object.getAttributes();

			// To create a virtual document in docbase
			// object.createVirtualDocument();

			// To export a virtual document from docbase
			// object.exportVirtualDocument();

			// To view virtual document from docbase
			// object.viewVirtualDocument();

			// To retrieve document from document using IDQL
			// object.collection();

			// To create and start workflow
			// object.startWorkflow();

			// to view task in inbox
			 object.getInbox();

			// To attach a lifeCycle to a document in docbase
			// object.attachLC();

			// To promote a lifeCycle state of a document
			// object.promoteLC("Review");

			// To demote a lifeCycle state of a document
			// object.demoteLC("Author");

			// To expire a lifeCycle state of a document
			// object.expireLC("Author");

			// To resume a lifeCycle state of a document
			// object.resumeLC("Author");

			// To assign a ACL to a document
			// object.assignACL();

		} finally {
			// to release a docbase session
			object.releaseSession();
		}
	}
}

Kind regards,

Huseyin

Hello,
 
In this post, I would like to present the definition of a custom Uniform Resource Identifier (URI) in order to execute a program in Windows on client side.
 
In a URL the portion with the HTTP://,FTP://, …etc are called URI Schemes. So, in some cases, it may be desirable to invoke another application to handle a custom Uniform Resource Identifier (URI) scheme. To register the existing application as an URI pluggable protocol handler and associate it with the custom URI scheme. Once the application has successfully launched, it can use command-line parameters to retrieve the URI that launched it. These settings apply to pluggable protocol handlers launched from within Windows Internet Explorer and from Windows Explorer using the Run… command (Windows logo key+R).
 
So, it is possible to register your own through the registry via the adding of a new key, along with the appropriate subkeys and values, to HKEY_CLASSES_ROOT. The root key must match the URI scheme that is being added.

HKEY_CLASSES_ROOT/
your-protocol-name/
your-protocol-name/(Default) = URL:your-protocol-name Protocol
your-protocol-name/URL Protocol = 
your-protocol-name/DefaultIcon/
your-protocol-name/DefaultIcon/(Default) = Executable.exe,1
your-protocol-name/shell/
your-protocol-name/shell/(Default) = 
your-protocol-name/shell/open/
your-protocol-name/shell/open/(Default) = 
your-protocol-name/shell/open/command/
your-protocol-name/shell/open/command/(Default) = "%ENV_VARIABLE%PathToExecutable/Executable.exe" "%1"

The URL Protocol string value indicates that this key declares a custom pluggable protocol handler. Without this key, the handler application will not launch. The value should be an empty string.
When a user clicks a link containing your custom URI scheme, Windows Internet Explorer launches the pluggable protocol handler registered for that URI scheme. If the specified open command specified in the registry contains a %1 parameter, Internet Explorer passes the URI to the registered pluggable protocol handler application
Importante Note IE must be the default browser on CLIENT side.

 
 

Example : Step by step

  • Go to Start then in Find type regedit -> it should open Registry editor:
  • Click Right Mouse on HKEY_CLASSES_ROOT then New -> Key:
  • In the Key give the lowercase name (testhuseyin) corresponding and matching with the URI Scheme (in my case it will be testhuseyin://mydata)
  • Click Right Mouse on testhuseyin -> then New -> String Value and add URL protocol without value.

  • Create hierarchy like testhuseyin -> shell -> open -> command via (Right Mouse New -> Key)
  • Create a new key DefaultIcon under testhuseyin via (Right Mouse New -> Key)
  • Inside the root key testhuseyin modify the value of entry (Default) to the protocol URL:Testhuseyin Protocol

  • Inside the key testhuseyin/DefaultIcon/, modify the value of (Default) to the name of .exe which to be launched: testhuseyin.exe,1 The “,1” corresponds to the parameter’s data.
  • Inside the key testhuseyin/shell/open/command/, modify the value of (Default) to the path of .exe which to be launched “c:\testing\testhuseyin.exe” “%1”. The “%1” corresponds to the parameter’s data.
  • Result should be:
    testhuseyin/
    testhuseyin/(Default) = URL:Testhuseyin Protocol
    testhuseyin/URL Protocol = 
    testhuseyin/DefaultIcon/
    testhuseyin/DefaultIcon/(Default) = testhuseyin.exe,1
    testhuseyin/shell/
    testhuseyin/shell/(Default) = 
    testhuseyin/shell/open/
    testhuseyin/shell/open/(Default) = 
    testhuseyin/shell/open/command/
    testhuseyin/shell/open/command/(Default) = "c:\testing\testhuseyin.exe" "%1"
    
  • To test if it works go to Internet Explorer (not Chrome or Firefox) and enter testhuseyin:test_1_test_2_hello_everybody:

    Without application helper, the below message will be displayed:

    If, you test with an unconfigured protocol, for example testhuseyin123, you will not obtain the same behaviour : testhuseyin123:test_1_test_2_hello_everybody.

  • So, create a new console application Testhuseyin:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Testhuseyin
    {
        class Program
        {
            static void Main(string[] args)
            {
            }
        }
    }
    

    Modify the Main method simply to write into output the passed parameter:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Testhuseyin
    {
        class Program
        {
            static void Main(string[] args)
            {
                //TEST HUSEYIN
                if (args != null && args.Length > 0)
                    Console.WriteLine(args[0]);
                Console.ReadKey();
    
            }
        }
    }
    

    Build the solution:

    1>------ Build started: Project: Testhuseyin, Configuration: Debug Any CPU ------
    1>  Testhuseyin -> C:\Workspaces\MS_Visual_Studio_Projects\Testhuseyin\Testhuseyin\bin\Debug\Testhuseyin.exe
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
    

    Copy/paste the executable into the protocol’s configured folder:

  • Try again to test if it works go to Internet Explorer (not Chrome or Firefox) and enter testhuseyin:test_1_test_2_hello_everybody:

  • Try again to test if it works via Start Menu/Run and enter testhuseyin:JAVABLOG.LU_huseyin:

 

Advanced : Use environment variable

  • Create user environment variable in order to store the path of executable of application helper : my_huo_user_variable = C:\testing\
    For example, this variable could be modified every time the boot of standalone application.

    Check the value of this variable:

  • Inside the key testhuseyin/shell/open/command/, modify the value of (Default) in order to use this environment variable: “%my_huo_user_variable%testhuseyin.exe” “%1”.
  • In order to use environment variable, you need to change the type of testhuseyin/shell/open/command/(Default) from default type REG_SZ to REG_EXPAND_SZ. However, it is possible to do via regedit GUI. You can use command line reg.exe to do this.

    Example 1 : C:\WINDOWS\system32>reg.exe add “HKCR\testhuseyin\shell\open\command” /ve /t REG_EXPAND_SZ /d “\”%my_huo_user_variable%testhuseyin.exe\” \”%1\”” /f
    The operation completed successfully.

    Example 2 : C:\WINDOWS\system32>reg.exe add “HKCR\testhuseyin\shell\open\command” /ve /t REG_EXPAND_SZ /d “\”^%my_huo_user_variable^%testhuseyin.exe\” \”%1\”” /f
    The operation completed successfully.

  • Final result should be:
    testhuseyin/
    testhuseyin/(Default) = URL:Testhuseyin Protocol
    testhuseyin/URL Protocol = 
    testhuseyin/DefaultIcon/
    testhuseyin/DefaultIcon/(Default) = testhuseyin.exe,1
    testhuseyin/shell/
    testhuseyin/shell/(Default) = 
    testhuseyin/shell/open/
    testhuseyin/shell/open/(Default) = 
    testhuseyin/shell/open/command/
    testhuseyin/shell/open/command/(Default) = "%my_huo_user_variable%testhuseyin.exe" "%1"
    
  • Test again:

 

Advanced : Use creation script

  • Open notepad and save the below script to testhuseyin2.reg and execute it by clicking on it in explorer.
    REGEDIT4
    
    [HKEY_CLASSES_ROOT\testhuseyin2]
    @="URL:Testhuseyin2 Protocol"
    "URL Protocol"=""
    
    [HKEY_CLASSES_ROOT\testhuseyin2\DefaultIcon]
    @="testhuseyin.exe,1"
    
    [HKEY_CLASSES_ROOT\testhuseyin2\shell]
    
    [HKEY_CLASSES_ROOT\testhuseyin2\shell\open]
    
    [HKEY_CLASSES_ROOT\testhuseyin2\shell\open\command]
    @="\"C:\\testing\\testhuseyin.exe\" \"%1\""
    

  • Final result should be:
    testhuseyin2/
    testhuseyin2/(Default) = URL:Testhuseyin2 Protocol
    testhuseyin2/URL Protocol = 
    testhuseyin2/DefaultIcon/
    testhuseyin2/DefaultIcon/(Default) = testhuseyin.exe,1
    testhuseyin2/shell/
    testhuseyin2/shell/(Default) = 
    testhuseyin2/shell/open/
    testhuseyin2/shell/open/(Default) = 
    testhuseyin2/shell/open/command/
    testhuseyin2/shell/open/command/(Default) = "C:\\testing\\testhuseyin.exe" "%1"
    
  • Test again:

That’s all!!!

Huseyin OZVEREN

Hello,

Juste a post concerning the generation of proxies client for DFS web service project due to ANT script and utilities classes.
Several steps:

  • Create a project TESTWsClientGenerator
  • Add the JAR emc-dfs-rt-remote.jar and emc-dfs-rt.jar (from DocumentumCoreProject\dfs6.7\emc-dfs-sdk-6.7\lib\java) in the BuildPath of your project
  • Get in your workplace the CXF librairies : C:\Workspaces\HUO\ECMExternalLibraries\org\apache\cfx-3.0.3 http://cxf.apache.org/cxf-303-release-notes.html
  • Create a source folder wsgenerator
  • Create the package com.emc.documentum.fs.datamodel.core.content
  • Create the below utilities classes BinaryContent and DataHandlerContent in this com.emc.documentum.fs.datamodel.core.content:
    package com.emc.documentum.fs.datamodel.core.content;
    
    import java.io.Serializable;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlType;
    
    
    /**
     * <p>Java class for BinaryContent complex type.
     * 
     * <p>The following schema fragment specifies the expected content contained within this class.
     * 
     * <pre>
     * &lt;complexType name="BinaryContent">
     *   &lt;complexContent>
     *     &lt;extension base="{http://content.core.datamodel.fs.documentum.emc.com/}Content">
     *       &lt;sequence>
     *         &lt;element name="Value" type="{http://www.w3.org/2001/XMLSchema}base64Binary"/>
     *       &lt;/sequence>
     *     &lt;/extension>
     *   &lt;/complexContent>
     * &lt;/complexType>
     * </pre>
     * 
     * 
     */
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "BinaryContent", propOrder = {
        "value"
    })
    public class BinaryContent
        extends Content
        implements Serializable
    {
    
        private final static long serialVersionUID = 1397139757393L;
        @XmlElement(name = "Value", required = true)
        protected byte[] value;
    
        /**
         * Gets the value of the value property.
         * 
         * @return
         *     possible object is
         *     byte[]
         */
        public byte[] getValue() {
            return value;
        }
    
        /**
         * Sets the value of the value property.
         * 
         * @param value
         *     allowed object is
         *     byte[]
         */
        public void setValue(byte[] value) {
            this.value = value;
        }
    
    }
    

     

    package com.emc.documentum.fs.datamodel.core.content;
    
    import java.io.Serializable;
    import javax.activation.DataHandler;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlMimeType;
    import javax.xml.bind.annotation.XmlType;
    
    
    /**
     * <p>Java class for DataHandlerContent complex type.
     * 
     * <p>The following schema fragment specifies the expected content contained within this class.
     * 
     * <pre>
     * &lt;complexType name="DataHandlerContent">
     *   &lt;complexContent>
     *     &lt;extension base="{http://content.core.datamodel.fs.documentum.emc.com/}Content">
     *       &lt;sequence>
     *         &lt;element name="Value" type="{http://www.w3.org/2001/XMLSchema}base64Binary"/>
     *       &lt;/sequence>
     *     &lt;/extension>
     *   &lt;/complexContent>
     * &lt;/complexType>
     * </pre>
     * 
     * 
     */
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "DataHandlerContent", propOrder = {
        "value"
    })
    public class DataHandlerContent
        extends Content
        implements Serializable
    {
    
        private final static long serialVersionUID = 1397139757393L;
        @XmlElement(name = "Value", required = true)
        @XmlMimeType("*/*")
        protected DataHandler value;
    
        /**
         * Gets the value of the value property.
         * 
         * @return
         *     possible object is
         *     {@link DataHandler }
         *     
         */
        public DataHandler getValue() {
            return value;
        }
    
        /**
         * Sets the value of the value property.
         * 
         * @param value
         *     allowed object is
         *     {@link DataHandler }
         *     
         */
        public void setValue(DataHandler value) {
            this.value = value;
        }
    
    }
    
  • Create the package com.emc.documentum.fs.utils
  • Create the below utilities classes ContentUtil and ServiceProxyUtils in this com.emc.documentum.fs.utils:
    package com.emc.documentum.fs.utils;
    
    import java.io.BufferedInputStream;
    import java.io.ByteArrayInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.MalformedURLException;
    import java.net.Proxy;
    import java.net.URL;
    import java.net.URLConnection;
    import java.text.MessageFormat;
    
    import javax.activation.DataHandler;
    import javax.activation.DataSource;
    
    import com.emc.documentum.fs.datamodel.core.content.BinaryContent;
    import com.emc.documentum.fs.datamodel.core.content.Content;
    import com.emc.documentum.fs.datamodel.core.content.DataHandlerContent;
    import com.emc.documentum.fs.datamodel.core.content.UrlContent;
    
    public class ContentUtil {
    
    	private static class InputStreamDataSource implements DataSource {
    		private final InputStream inputStream;
    		private final String type;
    
    		public InputStreamDataSource(InputStream inputStream) throws IOException {
    			this(inputStream, URLConnection.guessContentTypeFromStream(inputStream));
    		}
    
    		public InputStreamDataSource(InputStream inputStream, String type) {
    			this.inputStream = inputStream;
    			this.type = type;
    		}
    
    		@Override
    		public String getContentType() {
    			if (this.type == null) {
    				return "application/octet-stream";
    			}
    			return this.type;
    		}
    
    		@Override
    		public InputStream getInputStream() throws IOException {
    			return inputStream;
    		}
    
    		@Override
    		public String getName() {
    			return InputStreamDataSource.class.getSimpleName();
    		}
    
    		@Override
    		public OutputStream getOutputStream() throws IOException {
    			throw new IOException("Not Supported");
    		}
    	}
    
    	private static DataHandlerContent getDataHandlerContent(DataSource dataSource, String format) {
    		DataHandlerContent dataHandlerContent = new DataHandlerContent();
    		dataHandlerContent.setFormat(format);
    		dataHandlerContent.setValue(new DataHandler(dataSource));
    		return dataHandlerContent;
    	}
    
    	public static DataHandlerContent getDataHandlerContent(File file, String format) throws FileNotFoundException, IOException {
    		return getDataHandlerContent(new InputStreamDataSource(new FileInputStream(file), URLConnection.guessContentTypeFromName(file.getAbsolutePath())), format);
    	}
    
    	public static DataHandlerContent getDataHandlerContent(InputStream inputStream, String format) throws IOException {
    		return getDataHandlerContent(new InputStreamDataSource(inputStream), format);
    	}
    
    	public static InputStream getInputStream(Content content) throws MalformedURLException, IOException {
    		if (content == null) {
    			throw new IllegalArgumentException("content cannot be null");
    		}
    		if (content instanceof UrlContent) {
    			UrlContent urlContent = (UrlContent) content;
    			URL url = new URL(urlContent.getUrl());
    			URLConnection urlConnection = url.openConnection(Proxy.NO_PROXY);
    			InputStream inputStream = urlConnection.getInputStream();
    			BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
    			return bufferedInputStream;
    		} else if (content instanceof BinaryContent) {
    			BinaryContent binaryContent = (BinaryContent) content;
    			byte[] data = binaryContent.getValue();
    			ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data);
    			return byteArrayInputStream;
    		} else if (content instanceof DataHandlerContent) {
    			DataHandlerContent dataHandlerContent = (DataHandlerContent) content;
    			DataHandler dataHandler = dataHandlerContent.getValue();
    			InputStream inputStream = dataHandler.getInputStream();
    			return inputStream;
    		}
    		throw new RuntimeException(MessageFormat.format("{0} content is not supported", content));
    	}
    }
    

     

    package com.emc.documentum.fs.utils;
    
    import java.lang.reflect.Constructor;
    import java.lang.reflect.InvocationTargetException;
    import java.text.MessageFormat;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    import javax.xml.bind.JAXBException;
    import javax.xml.namespace.QName;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.soap.SOAPElement;
    import javax.xml.soap.SOAPException;
    
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    
    public class ServiceProxyUtils {
    
    	private static final Logger logger = Logger.getLogger(ServiceProxyUtils.class.getName());
    
    	public static Element getSecurityHeaderForRegisteredToken(String token) throws ParserConfigurationException {
    		Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    		Element wsseSecurity = document.createElementNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "wsse:Security");
    		Element wsseToken = (Element) wsseSecurity.appendChild(document.createElementNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "wsse:BinarySecurityToken"));
    		wsseToken.setAttribute("QualificationValueType", "http://schemas.emc.com/documentum#ResourceAccessToken");
    		wsseToken.setAttributeNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "wsu:Id", "RAD");
    		wsseToken.setTextContent(token);
    		return wsseSecurity;
    	}
    
    	public static Element getSecurityHeaderForKerberosToken(String token) throws ParserConfigurationException {
    		Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    		Element securityElement = (Element) document.createElementNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "ns3:Security");
    		securityElement.setAttribute("xmlns:ns1", "http://www.w3.org/2003/05/soap-envelope");
    		securityElement.setAttribute("xmlns:ns2", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
    		Element wsseToken = (Element) securityElement.appendChild(document.createElement("ns3:BinarySecurityToken"));
    		wsseToken.setAttribute("ValueType", "http://docs.oasis-open.org/wss/oasis-wss-kerberos-token-profile-1.1#Kerberosv5_AP_REQ");
    		wsseToken.setAttribute("EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
    		wsseToken.setTextContent(token);
    		return securityElement;
    	}
    
    	public static Element getSecurityHeaderForJAXBObject(Object object) throws JAXBException, ParserConfigurationException {
    		javax.xml.bind.JAXBContext j = javax.xml.bind.JAXBContext.newInstance(object.getClass());
    		org.w3c.dom.Document document = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    		j.createMarshaller().marshal(object, document);
    		return document.getDocumentElement();
    	}
    
    	public static void addBasicSecurity(javax.xml.ws.Service service, final String userName, final String password) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
    		service.setHandlerResolver(new javax.xml.ws.handler.HandlerResolver() {
    			@SuppressWarnings("rawtypes")
    			@Override
    			public java.util.List<javax.xml.ws.handler.Handler> getHandlerChain(javax.xml.ws.handler.PortInfo portInfo) {
    				java.util.List<javax.xml.ws.handler.Handler> handlerList = new java.util.ArrayList<javax.xml.ws.handler.Handler>();
    				handlerList.add(new javax.xml.ws.handler.soap.SOAPHandler<javax.xml.ws.handler.soap.SOAPMessageContext>() {
    					public void close(javax.xml.ws.handler.MessageContext context) {
    					}
    
    					public java.util.Set<javax.xml.namespace.QName> getHeaders() {
    						return new java.util.TreeSet<javax.xml.namespace.QName>();
    					}
    
    					public boolean handleFault(javax.xml.ws.handler.soap.SOAPMessageContext context) {
    						return true;
    					}
    
    					public boolean handleMessage(javax.xml.ws.handler.soap.SOAPMessageContext context) {
    						Boolean outboundProperty = (Boolean) context.get(javax.xml.ws.handler.MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    						if (outboundProperty.booleanValue()) {
    							try {
    								javax.xml.soap.SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
    								javax.xml.soap.SOAPHeader header = envelope.addHeader();
    								SOAPElement serviceContextElement = javax.xml.soap.SOAPFactory.newInstance().createElement(new QName("http://context.core.datamodel.fs.documentum.emc.com/", "ServiceContext"));
    								SOAPElement basicIdentityElement = serviceContextElement.addChildElement(javax.xml.soap.SOAPFactory.newInstance().createElement("Identities"));
    								basicIdentityElement.setAttribute("xsi:type", "BasicIdentity");
    								basicIdentityElement.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    								basicIdentityElement.setAttribute("userName", userName);
    								basicIdentityElement.setAttribute("password", password);
    								header.addChildElement(serviceContextElement);
    							} catch (Exception e) {
    								throw new RuntimeException("SOAPException in handler => unable to add security layer in header", e);
    							}
    						} else {
    							// inbound => Nothing to do
    						}
    						return true;
    					}
    				});
    				return handlerList;
    			}
    		});
    	}
    
    	public static <T extends javax.xml.ws.Service> T getService(Class<T> clazz, java.net.URL wsdlLocation) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    		return getService(clazz, wsdlLocation, null);
    	}
    
    	public static <T extends javax.xml.ws.Service> T getService(Class<T> clazz, java.net.URL wsdlLocation, final org.w3c.dom.Element wsseSecurity) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    		javax.xml.ws.WebServiceClient webServiceClient = clazz.getAnnotation(javax.xml.ws.WebServiceClient.class);
    		return getService(clazz, wsdlLocation, new javax.xml.namespace.QName(webServiceClient.targetNamespace(), webServiceClient.name()), wsseSecurity);
    	}
    
    	public static <T extends javax.xml.ws.Service> T getService(Class<T> clazz, java.net.URL wsdlLocation, javax.xml.namespace.QName serviceName, final org.w3c.dom.Element wsseSecurity) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    		Constructor<T> constructor = clazz.getConstructor(java.net.URL.class, javax.xml.namespace.QName.class);
    		T result = constructor.newInstance(wsdlLocation, serviceName);
    		if (wsseSecurity != null) {
    			result.setHandlerResolver(new javax.xml.ws.handler.HandlerResolver() {
    				@SuppressWarnings("rawtypes")
    				@Override
    				public java.util.List<javax.xml.ws.handler.Handler> getHandlerChain(javax.xml.ws.handler.PortInfo portInfo) {
    					java.util.List<javax.xml.ws.handler.Handler> handlerList = new java.util.ArrayList<javax.xml.ws.handler.Handler>();
    					handlerList.add(new javax.xml.ws.handler.soap.SOAPHandler<javax.xml.ws.handler.soap.SOAPMessageContext>() {
    						public void close(javax.xml.ws.handler.MessageContext context) {
    						}
    
    						public java.util.Set<javax.xml.namespace.QName> getHeaders() {
    							return new java.util.TreeSet<javax.xml.namespace.QName>();
    						}
    
    						public boolean handleFault(javax.xml.ws.handler.soap.SOAPMessageContext context) {
    							return true;
    						}
    
    						public boolean handleMessage(javax.xml.ws.handler.soap.SOAPMessageContext context) {
    							Boolean outboundProperty = (Boolean) context.get(javax.xml.ws.handler.MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    							if (outboundProperty.booleanValue()) {
    								try {
    									javax.xml.soap.SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
    									javax.xml.soap.SOAPHeader header = envelope.addHeader();
    									header.addChildElement(javax.xml.soap.SOAPFactory.newInstance().createElement(wsseSecurity));
    								} catch (SOAPException e) {
    									logger.log(Level.SEVERE, MessageFormat.format("SOAPException in handler => unable to add security layer {0} in header", wsseSecurity), e);
    								}
    							} else {
    								// inbound => Nothing to do
    							}
    							return true;
    						}
    					});
    					return handlerList;
    				}
    			});
    		}
    		return result;
    	}
    
    	private ServiceProxyUtils() {
    		super();
    	}
    }
    
  • Create a file build.properties:
    application.version=1
    build.vendor=JavaBlog.fr - Java.lu
    
  • Create a file simple-binding.xjb:
    <?xml version="1.0" encoding="UTF-8"?>
    <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    	jaxb:version="2.0" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    	jaxb:extensionBindingPrefixes="xjc">
    	<jaxb:globalBindings>
    		<xjc:simple />
    		<xjc:serializable uid="1397139757393" />
    	</jaxb:globalBindings>
    </jaxb:bindings>
    
  • Create a file wsdllist.txt:
    https://ws.java.lu/services/mycontext/MyWebServiceForECMService?wsdl
    https://ws.java.lu/services/mycontext/runtime/ContextRegistryService?wsdl
    
  • Create an ANT script build.xml. Modify the folder of CXF home in script cxf.home:
    	<property name="cxf.home" location="C:\Workspaces\HUO\ECMExternalLibraries\org\apache\cfx-3.0.3" />
    
    <?xml version="1.0" encoding="UTF-8"?>
    <project name="TESTWsClientGenerator" default="dist" basedir=".">
    	<property file="build.properties" />
    	<property name="build" value="build" />
    	<property name="src" value="src" />
    	<property name="build.src" value="${build}\${src}" />
    	<property name="build.classes" value="${build}\classes" />
    	<property name="build.lib" value="lib" />
    	<property name="build.dist" location="${build}/dist" />
    	<property name="build.ClientAcceptanceProxy.jar" location="${build.dist}/${ant.project.name}.jar" />
    
    	<property name="cxf.home" location="C:\Workspaces\HUO\ECMExternalLibraries\org\apache\cfx-3.0.3" />
    
    	<target name="dist" depends="create_proxy, build">
    		<jar basedir="${build.classes}" destfile="${build.ClientAcceptanceProxy.jar}" manifest="${build}/MANIFEST.MF" />
    	</target>
    
    	<target name="build" depends="javac" />
    
    	<target name="init">
    		<delete dir="${build}" failonerror="false" />
    		<mkdir dir="${build}" />
    		<mkdir dir="${build.lib}" />
    		<mkdir dir="${build.src}" />
    	</target>
    
    	<target name="javac" depends="javaclasspath" description="compile the source">
    		<delete dir="${build.classes}" />
    		<mkdir dir="${build.classes}" />
    
    		<!-- compile -->
    		<javac destdir="${build.classes}" debug="true" srcdir="${build.src}" source="1.5" target="1.5" encoding="8859_1">
    			<classpath refid="classpath.compile" />
    		</javac>
    
    		<!-- copy all resources to the classes directory -->
    		<copy todir="${build.classes}">
    			<fileset dir="${build.src}">
    				<include name="**/*" />
    				<exclude name="**/*.java" />
    			</fileset>
    		</copy>
    
    		<tstamp>
    			<format property="build.time" pattern="dd/MM/yyyy HH:mm:ss" />
    		</tstamp>
    
    		<buildnumber file="${ant.project.name}.buildnumber" />
    		<property name="build.version" value="${application.version}.${build.number}" />
    
    		<manifest file="${build}/MANIFEST.MF">
    			<attribute name="Created-By" value="${user.name}" />
    			<attribute name="Product-Name" value="${ant.project.name}" />
    			<attribute name="Product-Version" value="${application.version}" />
    			<attribute name="Build-Version" value="${build.version}" />
    			<attribute name="Build-Date" value="${build.time}" />
    			<attribute name="Vendor-Name" value="${build.vendor}" />
    		</manifest>
    
    	</target>
    
    	<target name="javaclasspath" description="Configure classpath">
    		<!-- define classpath -->
    		<path id="classpath.compile">
    			<fileset dir="${build.lib}">
    				<include name="**/*.jar" />
    			</fileset>
    		</path>
    	</target>
    
    	<path id="cxf.classpath">
    		<fileset dir="${cxf.home}/lib">
    			<include name="*.jar" />
    		</fileset>
    	</path>
    
    	<target name="prepare">
    		<mkdir dir="${build}" />
    		<mkdir dir="${build.src}" />
    		<mkdir dir="${build.classes}" />
    		<mkdir dir="${build.dist}" />
    	</target>
    
    	<target name="clean">
    		<delete dir="${build}" includeemptydirs="true" />
    	</target>
    
    	<target name="create_proxy" depends="init,prepare">
    		<java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
    			<arg value="-autoNameResolution" />
    			<arg value="-verbose" />
    			<arg value="-fe" />
    			<arg value="jaxws21" />
    			<arg value="-d" />
    			<arg value="${build.src}" />
    			<arg value="-b" />
    			<arg value="simple-binding.xjb" />
    			<arg value="-wsdlList" />
    			<arg value="wsdllist.txt" />
    
    			<classpath>
    				<path refid="cxf.classpath" />
    			</classpath>
    		</java>
    
    		<mkdir dir="${build.src}/com/emc/documentum/fs/utils" />
    		<copy todir="${build.src}/com/emc/documentum/fs/utils">
    			<fileset dir="${basedir}">
    				<include name="*.java" />
    			</fileset>
    		</copy>
    
    		<delete dir="${basedir}/src" includeemptydirs="true" />
    		<copy todir="${basedir}/src">
    			<fileset dir="${build}/src">
    				<include name="**/*.java" />
    			</fileset>
    		</copy>
    	</target>
    </project>
    
  • Execute the ANT script – Warning: Use the JDK version JavaSE-1.7 – :
    
    Buildfile: C:\Workspaces\HUO\TESTWsClientGenerator\build.xml
    init:
       [delete] Deleting directory C:\Workspaces\HUO\TESTWsClientGenerator\build
        [mkdir] Created dir: C:\Workspaces\HUO\TESTWsClientGenerator\build
        [mkdir] Created dir: C:\Workspaces\HUO\TESTWsClientGenerator\build\src
    prepare:
        [mkdir] Created dir: C:\Workspaces\HUO\TESTWsClientGenerator\build\classes
        [mkdir] Created dir: C:\Workspaces\HUO\TESTWsClientGenerator\build\dist
    create_proxy:
          Loading FrontEnd jaxws21 ...
          Loading DataBinding jaxb ...
          wsdl2java -autoNameResolution -verbose -fe jaxws21 -d build\src -b simple-binding.xjb -wsdlList wsdllist.txt
          wsdl2java - Apache CXF 3.0.3
        [mkdir] Created dir: C:\Workspaces\HUO\TESTWsClientGenerator\build\src\com\emc\documentum\fs\utils
       [delete] Deleting directory C:\Workspaces\HUO\TESTWsClientGenerator\src
         [copy] Copying 139 files to C:\Workspaces\HUO\TESTWsClientGenerator\src
    javaclasspath:
    javac:
       [delete] Deleting directory C:\Workspaces\HUO\TESTWsClientGenerator\build\classes
        [mkdir] Created dir: C:\Workspaces\HUO\TESTWsClientGenerator\build\classes
        [javac] Compiling 139 source files to C:\Workspaces\HUO\TESTWsClientGenerator\build\classes
        [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.5
        [javac] 1 warning
         [copy] Copied 1 empty directory to 1 empty directory under C:\Workspaces\HUO\TESTWsClientGenerator\build\classes
    build:
    dist:
          [jar] Building jar: C:\Workspaces\HUO\TESTWsClientGenerator\build\dist\TESTWsClientGenerator.jar
    BUILD SUCCESSFUL
    Total time: 12 seconds
    
  • Result : The folder src contains the proxies classes in order to request the DFS web services. A file TESTWsClientGenerator.buildnumber is generated with the build number:
    #Build Number for ANT. Do not edit!
    #Thu Oct 05 11:55:44 CEST 2017
    build.number=2
    

    Warning : The BinaryContent and DataHandlerContent classes are double. so, it is possible to remove the package wsgenerator\com\emc\documentum\fs\datamodel\core\content. You could execute again the ANT script.

That’s all!

Huseyin OZVEREN

Page 1 of 50:1 2 3 4 »Last »
bottom-img
Copyright ® 2012 Huseyin Ozveren. No reproduction, even partial, can be used from this site and all its contents including text, documents, images, etc.. without the express permission of the author.