Merge from DEV/SEAMIST3

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10832 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2008-09-07 13:06:28 +00:00
parent 64bf87af37
commit a42cc8992f
51 changed files with 4046 additions and 352 deletions

View File

@@ -1,229 +0,0 @@
/*
* Copyright (C) 2005-2008 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.cmis.ws.example;
import java.io.IOException;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import org.alfresco.repo.cmis.ws.CmisObjectType;
import org.alfresco.repo.cmis.ws.CmisQueryType;
import org.alfresco.repo.cmis.ws.CmisRepositoryEntryType;
import org.alfresco.repo.cmis.ws.EnumTypesOfFileableObjects;
import org.alfresco.repo.cmis.ws.GetChildren;
import org.alfresco.repo.cmis.ws.GetChildrenResponse;
import org.alfresco.repo.cmis.ws.GetFolderParent;
import org.alfresco.repo.cmis.ws.GetRepositories;
import org.alfresco.repo.cmis.ws.GetRepositoryInfo;
import org.alfresco.repo.cmis.ws.GetTypes;
import org.alfresco.repo.cmis.ws.NavigationServicePort;
import org.alfresco.repo.cmis.ws.ObjectFactory;
import org.alfresco.repo.cmis.ws.RepositoryServicePort;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.WSPasswordCallback;
import org.apache.ws.security.handler.WSHandlerConstants;
/**
* This helper-class contain all necessary for <b>SimpleCmisWsTest</b> correct working service-methods
*
* @author Dmitry Velichkevich
*/
public class ExecutableServicesHelper
{
private static final QName NAVIGATION_SERVICE_NAME = new QName("http://www.cmis.org/ns/1.0", "NavigationService");
private static final QName REPOSITORY_SERVICE_NAME = new QName("http://www.cmis.org/ns/1.0", "RepositoryService");
private static final String NAVIGATION_SERVER_URL_POSTFIX = "/alfresco/cmis/NavigationService?wsdl";
private static final String REPOSITORY_SERVER_URL_POSTFIX = "/alfresco/cmis/RepositoryService?wsdl";
private static final Log LOGGER = LogFactory.getLog(ExecutableServicesHelper.class);
private String username;
private String password;
private Service navigationServicesFactory;
private Service repositoryServicesFactory;
/**
* @param username - an existent authentication user name
* @param password - appropriate password for specified user name
* @param serverAddress - IP address (or domain name) and port for the server to connect
* @throws Exception - an caught <b>MalformedURLException</b> in time of server connect <b>URL</b> creation
*/
public ExecutableServicesHelper(String username, String password, String serverAddress) throws Exception
{
this.username = username;
this.password = password;
try
{
navigationServicesFactory = Service.create(new URL(serverAddress + NAVIGATION_SERVER_URL_POSTFIX), NAVIGATION_SERVICE_NAME);
repositoryServicesFactory = Service.create(new URL(serverAddress + REPOSITORY_SERVER_URL_POSTFIX), REPOSITORY_SERVICE_NAME);
}
catch (MalformedURLException e)
{
throw new Exception("Field to connect to specified URL. Exception Message: " + e.getMessage());
}
}
/**
* This method simplify <b>RepositoryServicePort</b> instance creation
*
* @return an instance of <b>RepositoryServicePort</b>
*/
public RepositoryServicePort receiveAuthorizedRepositoryServicePort()
{
RepositoryServicePort result = repositoryServicesFactory.getPort(RepositoryServicePort.class);
createAuthorizationClient(result);
return result;
}
/**
* This method simplify <b>NavigationServicePort</b> instance creation
*
* @return an instance of <b>NavigationServicePort</b>
*/
public NavigationServicePort receiveAuthorizedNavigationServicePort()
{
NavigationServicePort result = navigationServicesFactory.getPort(NavigationServicePort.class);
createAuthorizationClient(result);
return result;
}
/**
* This method simplify configuring of <b>GetChildren CMIS Service</b> query with "ANY" filter, <b>Company Home Object Identificator</b> and <b>FOLDERS_AND_DOCUMENTS</b>
* entity types.
*
* @param servicesPort - <b>NavigationServicePort</b> configured with <b>WSS4J Client</b> instance
* @return <b>List< DocumentOrFolderObjectType></b> - list of all children elements of <b>Company Home</b> folder
* @throws Exception This exception throws when any <b>CMIS Services</b> operations was failed
*/
public List<CmisObjectType> receiveSpaceContent(NavigationServicePort servicesPort) throws Exception
{
GetChildrenResponse response;
response = servicesPort.getChildren(configureGetChildrenServiceQuery());
if ((response != null) && (response.getObject() != null))
{
return response.getObject();
}
else
{
return null;
}
}
/**
* This method simplify receiving of Object Identificator for Company Home Root Folder
*
* @param servicesPort - <b>RepositoryServicePort</b> instance that configured with WSS4J Client
* @return <b>String</b> representation of <b>Object Identificator</b>
* @throws Exception This exception throws when any <b>CMIS Services</b> operations was failed
*/
public String receiveCompanyHomeObjectId(RepositoryServicePort servicesPort) throws Exception
{
GetRepositoryInfo parameteers = new GetRepositoryInfo();
parameteers.setRepositoryId(servicesPort.getRepositories().get(0).getRepositoryID());
return servicesPort.getRepositoryInfo(parameteers).getRootFolderId();
}
/**
* This method simplify creation of authorized Client instance with specified user name and appropriate password
*
* @return - an instance of authorized <b>CMIS Client</b>
*/
protected Client createAuthorizationClient(Object servicePortInstance)
{
Map<String, Object> outInterceptorProperties = configureWss4jProperties();
WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outInterceptorProperties);
return createAndConfigureClientInstance(servicePortInstance, outInterceptor);
}
private GetChildren configureGetChildrenServiceQuery() throws Exception
{
ObjectFactory objectFactory = new ObjectFactory();
RepositoryServicePort authorizedRepositoryServicePort = receiveAuthorizedRepositoryServicePort();
GetChildren requestParameters = objectFactory.createGetChildren();
requestParameters.setRepositoryId(authorizedRepositoryServicePort.getRepositories().get(0).getRepositoryID());
requestParameters.setFilter(objectFactory.createGetChildrenFilter("*"));
requestParameters.setMaxItems(objectFactory.createGetChildrenMaxItems(BigInteger.valueOf(Long.MAX_VALUE)));
requestParameters.setFolderId(receiveCompanyHomeObjectId(authorizedRepositoryServicePort));
requestParameters.setType(objectFactory.createGetChildrenType(EnumTypesOfFileableObjects.ANY));
return requestParameters;
}
private Client createAndConfigureClientInstance(Object servicePortInstance, WSS4JOutInterceptor outInterceptor)
{
Client client = ClientProxy.getClient(servicePortInstance);
client.getEndpoint().getOutInterceptors().add(new SAAJOutInterceptor());
client.getEndpoint().getOutInterceptors().add(outInterceptor);
return client;
}
private Map<String, Object> configureWss4jProperties()
{
Map<String, Object> outInterceptorProperties = new HashMap<String, Object>();
outInterceptorProperties.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN + " " + WSHandlerConstants.TIMESTAMP);
outInterceptorProperties.put(WSHandlerConstants.USER, username);
outInterceptorProperties.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
outInterceptorProperties.put(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler()
{
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
{
((WSPasswordCallback) callbacks[0]).setPassword(password);
}
});
return outInterceptorProperties;
}
}

View File

@@ -1,123 +0,0 @@
/*
* Copyright (C) 2005-2008 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.cmis.ws.example;
import java.util.List;
import org.alfresco.repo.cmis.ws.CmisObjectType;
import org.alfresco.repo.cmis.ws.CmisPropertiesType;
import org.alfresco.repo.cmis.ws.CmisProperty;
import org.alfresco.repo.cmis.ws.CmisPropertyString;
/**
* This class executes simple processing for prompting server address and user name and password for authentication this user on specified server. After successful connection this
* class print contents of Company Home.<br />
* <br />
* This class expects next command-line parameters:<nobr />
* <ul>
* <li><b>Server Address</b> - with form: (IP_ADDRESS|DOMAIN_NAME):PORT;</li>
* <li><b>Username</b> - login name of the existent user;</li>
* <li><b>Password</b> - appropriate password for specified user.</li>
* </ul>
* <b>Example: <font color=green>192.168.0.1:8080 admin admin</font></b> - authenticate an user as admin on <font color=gray><b>http://192.168.0.1:8080/alfresco/</b></font>
* server
*
* @author Dmitry Velichkevich
*/
public class SimpleExecutableCmisServicesUtilizer
{
/**
* Executable entry point - represents main life cycle
*
* @param args - not used
* @see SimpleCmisWsTest description
*/
public static void main(String[] args)
{
String username = null;
String password = null;
String serverUrl = null;
if (args.length != 3)
{
System.out.println("Usage: cmis-test.bat server_url username password");
System.out.println("Example : cmis-test.bat http://localhost:8080 admin admin");
return;
}
else
{
serverUrl = args[0];
username = args[1];
password = args[2];
}
ExecutableServicesHelper servicesHelper;
try
{
servicesHelper = new ExecutableServicesHelper(username, password, serverUrl);
}
catch (Exception e)
{
System.out.println("Can't connect to specified server. Message: " + e.getMessage());
return;
}
List<CmisObjectType> response;
try
{
response = servicesHelper.receiveSpaceContent(servicesHelper.receiveAuthorizedNavigationServicePort());
}
catch (Exception e)
{
System.out.println("Can't receive content of Company Home caused: " + e.getMessage());
e.printStackTrace();
return;
}
System.out.println("Outing Company Home contents:");
for (CmisObjectType item : response)
{
boolean thisIsFolder = ((CmisPropertyString) getCmisProperty(item.getProperties(), "BaseType")).getValue().contains("folder");
String itemName = ((CmisPropertyString) getCmisProperty(item.getProperties(), "Name")).getValue();
System.out.println(((thisIsFolder) ? ("[") : ("")) + itemName + ((thisIsFolder) ? ("]") : ("")));
}
}
private static CmisProperty getCmisProperty(CmisPropertiesType properties, String cmisPropertyName)
{
for (CmisProperty cmisProperty : properties.getProperty())
{
if (cmisProperty.getName().equalsIgnoreCase(cmisPropertyName))
{
return cmisProperty;
}
}
return null;
}
}