mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged V2.1 to HEAD
6327: Drops alfresco-deployment.zip in build/dist instead of build. 6328:Set AVM file name requirements as lenient as possible. 6329: Fixed DNS name restriction to allow 1-char host labels. 6330: Setting read-only flag for start up components (AR-1621 and AR-193) 6331: Minor formatting 6332: Implementation of a read-only, HTTP-based ContentStore. 6333: AR-1619: A debug message needed changing as the FileFolderService now supports adding children onto system nodes. 6334: Build fix 6335: Fix for AWC-1447 (Office Add-In - Create Collaboration Space) 6337: Fixed AR-1622: WebService requests must be wrapped in retries git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6721 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -8,3 +8,8 @@ index.recovery.starting=Index recovery started: {0} transactions.
|
|||||||
index.recovery.complete=Index recovery completed.
|
index.recovery.complete=Index recovery completed.
|
||||||
index.recovery.progress=\t{0} % complete.
|
index.recovery.progress=\t{0} % complete.
|
||||||
index.recovery.terminated=Index recovery terminated.
|
index.recovery.terminated=Index recovery terminated.
|
||||||
|
|
||||||
|
content.http_reader.err.no_connection=Unable to connect to remote Alfresco server via HTTP: {0}
|
||||||
|
content.http_reader.err.no_authentication=The HTTP reader was unable to authenticate on the remote server: {0} \n
|
||||||
|
content.http_reader.err.check_cluster=Please ensure that 'replicateUpdates' and 'replicateUpdatesViaCopy' is enabled for the cache 'org.alfresco.cache.ticketsCache'. Check that the general cluster configuration is correct and working.
|
||||||
|
content.http_reader.err.unrecognized=An unrecognized error occured when attempting to download content from remote server:\n Server: {0} \n Content: {1} \n HTTP Response: {2}
|
||||||
|
@@ -179,7 +179,7 @@ public class ConfigurationChecker extends AbstractLifecycleBean
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
transactionService.getRetryingTransactionHelper().doInTransaction(checkWork);
|
transactionService.getRetryingTransactionHelper().doInTransaction(checkWork, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -34,7 +34,7 @@ public class FileNameValidator
|
|||||||
/**
|
/**
|
||||||
* The bad file name pattern.
|
* The bad file name pattern.
|
||||||
*/
|
*/
|
||||||
private static String fgBadPattern = ".*[\"\\*\\\\><\\?/:\\|\\xA3\\xAC%&;]+.*";
|
private static String fgBadPattern = ".*[\"\\*\\\\><\\?/:\\|]+.*";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The compiled regex.
|
* The compiled regex.
|
||||||
|
@@ -33,8 +33,8 @@ public class FileNameValidatorTest extends TestCase
|
|||||||
{
|
{
|
||||||
public void testValidator()
|
public void testValidator()
|
||||||
{
|
{
|
||||||
String [] badNames = { "\"", "\\", "/", "<", ">", "?", "*", "%", "&",
|
String [] badNames = { "\"", "\\", "/", "<", ">", "?", "*",
|
||||||
":", ";", "|" };
|
":", "|" };
|
||||||
for (String name : badNames)
|
for (String name : badNames)
|
||||||
{
|
{
|
||||||
assertFalse(FileNameValidator.IsValid(name));
|
assertFalse(FileNameValidator.IsValid(name));
|
||||||
|
@@ -208,7 +208,7 @@ public class FileContentReader extends AbstractContentReader
|
|||||||
// the file must exist
|
// the file must exist
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
{
|
{
|
||||||
throw new IOException("File does not exist");
|
throw new IOException("File does not exist: " + file);
|
||||||
}
|
}
|
||||||
// create the channel
|
// create the channel
|
||||||
ReadableByteChannel channel = null;
|
ReadableByteChannel channel = null;
|
||||||
|
@@ -304,7 +304,7 @@ public class FileContentStore extends AbstractContentStore
|
|||||||
*/
|
*/
|
||||||
public boolean isWriteSupported()
|
public boolean isWriteSupported()
|
||||||
{
|
{
|
||||||
return true;
|
return !readOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -24,24 +24,34 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.content.http;
|
package org.alfresco.repo.content.http;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.ConnectException;
|
||||||
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import net.sf.acegisecurity.Authentication;
|
import net.sf.acegisecurity.Authentication;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
import org.alfresco.i18n.I18NUtil;
|
||||||
import org.alfresco.repo.content.AbstractContentReader;
|
import org.alfresco.repo.content.AbstractContentReader;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.security.authentication.TicketComponent;
|
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentStreamListener;
|
||||||
|
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||||
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
import org.apache.commons.httpclient.HttpClient;
|
||||||
import org.apache.commons.httpclient.HttpException;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reader that does the actual communication with the Alfresco HTTP
|
* The reader that does the actual communication with the Alfresco HTTP
|
||||||
@@ -53,29 +63,45 @@ import org.apache.commons.httpclient.methods.GetMethod;
|
|||||||
*/
|
*/
|
||||||
public class HttpAlfrescoContentReader extends AbstractContentReader
|
public class HttpAlfrescoContentReader extends AbstractContentReader
|
||||||
{
|
{
|
||||||
private static final String DEFAULT_URL = "{0}/dr?contentUrl={1}?ticket={2}";
|
private static final String ERR_NO_CONNECTION = "content.http_reader.err.no_connection";
|
||||||
private static final String INFO_ONLY = "?infoOnly=true";
|
private static final String ERR_NO_AUTHENTICATION = "content.http_reader.err.no_authentication";
|
||||||
|
private static final String ERR_CHECK_CLUSTER = "content.http_reader.err.check_cluster";
|
||||||
|
private static final String ERR_UNRECOGNIZED = "content.http_reader.err.unrecognized";
|
||||||
|
|
||||||
AuthenticationService authenticationService;
|
private static final String DEFAULT_URL = "{0}/dr?contentUrl={1}&ticket={2}";
|
||||||
AuthenticationComponent authenticationComponent;
|
private static final String INFO_ONLY = "&infoOnly=true";
|
||||||
|
|
||||||
|
private static Log logger = LogFactory.getLog(HttpAlfrescoContentReader.class);
|
||||||
|
|
||||||
|
private TransactionService transactionService;
|
||||||
|
private AuthenticationService authenticationService;
|
||||||
private String baseHttpUrl;
|
private String baseHttpUrl;
|
||||||
private String contentUrl;
|
|
||||||
// Helpers
|
// Helpers
|
||||||
private HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
|
private PropagateTicketCallback ticketCallback;
|
||||||
|
// Cached values
|
||||||
|
private boolean isInfoCached;
|
||||||
|
private boolean cachedExists;
|
||||||
|
private long cachedLastModified;
|
||||||
|
private long cachedSize;
|
||||||
|
|
||||||
public HttpAlfrescoContentReader(
|
public HttpAlfrescoContentReader(
|
||||||
|
TransactionService transactionService,
|
||||||
AuthenticationService authenticationService,
|
AuthenticationService authenticationService,
|
||||||
AuthenticationComponent authenticationComponent,
|
|
||||||
String baseHttpUrl,
|
String baseHttpUrl,
|
||||||
String contentUrl)
|
String contentUrl)
|
||||||
{
|
{
|
||||||
super(contentUrl);
|
super(contentUrl);
|
||||||
|
this.transactionService = transactionService;
|
||||||
this.authenticationService = authenticationService;
|
this.authenticationService = authenticationService;
|
||||||
this.authenticationComponent = authenticationComponent;
|
|
||||||
this.baseHttpUrl = baseHttpUrl;
|
this.baseHttpUrl = baseHttpUrl;
|
||||||
this.contentUrl = contentUrl;
|
|
||||||
// Helpers
|
// Helpers
|
||||||
this.httpClient = new HttpClient();
|
this.httpClient = new HttpClient();
|
||||||
|
this.ticketCallback = new PropagateTicketCallback();
|
||||||
|
// A trip to the remote server has not been made
|
||||||
|
cachedExists = false;
|
||||||
|
cachedSize = 0L;
|
||||||
|
cachedLastModified = 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -88,31 +114,99 @@ public class HttpAlfrescoContentReader extends AbstractContentReader
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean exists()
|
/**
|
||||||
|
* Helper class to wrap the ticket creation in order to force propagation of the
|
||||||
|
* authentication ticket around the cluster.
|
||||||
|
*
|
||||||
|
* @since 2.1
|
||||||
|
* @author Derek Hulley
|
||||||
|
*/
|
||||||
|
private class PropagateTicketCallback implements RetryingTransactionCallback<String>
|
||||||
{
|
{
|
||||||
|
public String execute() throws Throwable
|
||||||
|
{
|
||||||
|
return authenticationService.getCurrentTicket();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getInfo()
|
||||||
|
{
|
||||||
|
String contentUrl = getContentUrl();
|
||||||
|
// Info will be cached
|
||||||
|
isInfoCached = true;
|
||||||
// Authenticate as the system user for the call
|
// Authenticate as the system user for the call
|
||||||
Authentication authentication = null;
|
Authentication authentication = null;
|
||||||
GetMethod method = null;
|
GetMethod method = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
authenticationComponent.setSystemUserAsCurrentUser();
|
authentication = AuthenticationUtil.setCurrentUser(AuthenticationUtil.SYSTEM_USER_NAME);
|
||||||
String ticket = authenticationService.getCurrentTicket();
|
String ticket = transactionService.getRetryingTransactionHelper().doInTransaction(ticketCallback, false, true);
|
||||||
String url = HttpAlfrescoContentReader.generateURL(baseHttpUrl, contentUrl, ticket, true);
|
String url = HttpAlfrescoContentReader.generateURL(baseHttpUrl, contentUrl, ticket, true);
|
||||||
|
|
||||||
method = new GetMethod(url);
|
method = new GetMethod(url);
|
||||||
int statusCode = httpClient.executeMethod(method);
|
int statusCode = httpClient.executeMethod(method);
|
||||||
if (statusCode == HttpServletResponse.SC_NO_CONTENT)
|
if (statusCode == HttpServletResponse.SC_OK)
|
||||||
{
|
{
|
||||||
return false;
|
// Get the information values from the request
|
||||||
|
String responseSize = method.getResponseHeader("alfresco.dr.size").getValue();
|
||||||
|
String responseLastModified = method.getResponseHeader("alfresco.dr.lastModified").getValue();
|
||||||
|
String responseMimetype = method.getResponseHeader("alfresco.dr.mimetype").getValue();
|
||||||
|
String responseEncoding = method.getResponseHeader("alfresco.dr.encoding").getValue();
|
||||||
|
String responseLocale = method.getResponseHeader("alfresco.dr.locale").getValue();
|
||||||
|
// Fill in this reader's values
|
||||||
|
cachedSize = DefaultTypeConverter.INSTANCE.convert(Long.class, responseSize);
|
||||||
|
cachedLastModified = DefaultTypeConverter.INSTANCE.convert(Date.class, responseLastModified).getTime();
|
||||||
|
setMimetype(DefaultTypeConverter.INSTANCE.convert(String.class, responseMimetype));
|
||||||
|
setEncoding(DefaultTypeConverter.INSTANCE.convert(String.class, responseEncoding));
|
||||||
|
setLocale(DefaultTypeConverter.INSTANCE.convert(Locale.class, responseLocale));
|
||||||
|
// It exists
|
||||||
|
cachedExists = true;
|
||||||
|
// Done
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("\n" +
|
||||||
|
"HttpReader content found: \n" +
|
||||||
|
" Reader: " + this + "\n" +
|
||||||
|
" Server: " + baseHttpUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return true;
|
// Check the return codes
|
||||||
|
if (statusCode == HttpServletResponse.SC_NOT_FOUND)
|
||||||
|
{
|
||||||
|
// It doesn't exist, which is not an error. The defaults are fine.
|
||||||
}
|
}
|
||||||
|
else if (statusCode == HttpServletResponse.SC_FORBIDDEN)
|
||||||
|
{
|
||||||
|
// If the authentication fails, then the server is there, but probably not
|
||||||
|
// clustered correctly.
|
||||||
|
logger.error(I18NUtil.getMessage(ERR_NO_AUTHENTICATION, baseHttpUrl));
|
||||||
|
logger.error(I18NUtil.getMessage(ERR_CHECK_CLUSTER));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// What is this?
|
||||||
|
logger.error(I18NUtil.getMessage(ERR_UNRECOGNIZED, baseHttpUrl, contentUrl, statusCode));
|
||||||
|
logger.error(I18NUtil.getMessage(ERR_CHECK_CLUSTER));
|
||||||
|
}
|
||||||
|
// Done
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("\n" +
|
||||||
|
"HttpReader content not found: \n" +
|
||||||
|
" Reader: " + this + "\n" +
|
||||||
|
" Server: " + baseHttpUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ConnectException e)
|
||||||
|
{
|
||||||
|
logger.error(I18NUtil.getMessage(ERR_NO_CONNECTION, baseHttpUrl));
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Reader exists check failed: " + this);
|
throw new AlfrescoRuntimeException("Reader exists check failed: " + this, e);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -120,30 +214,114 @@ public class HttpAlfrescoContentReader extends AbstractContentReader
|
|||||||
{
|
{
|
||||||
try { method.releaseConnection(); } catch (Throwable e) {}
|
try { method.releaseConnection(); } catch (Throwable e) {}
|
||||||
}
|
}
|
||||||
authenticationComponent.setCurrentAuthentication(authentication);
|
AuthenticationUtil.setCurrentAuthentication(authentication);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastModified()
|
public synchronized boolean exists()
|
||||||
{
|
{
|
||||||
throw new UnsupportedOperationException();
|
if (!isInfoCached)
|
||||||
|
{
|
||||||
|
getInfo();
|
||||||
|
}
|
||||||
|
return cachedExists;
|
||||||
|
}
|
||||||
|
public synchronized long getLastModified()
|
||||||
|
{
|
||||||
|
if (!isInfoCached)
|
||||||
|
{
|
||||||
|
getInfo();
|
||||||
|
}
|
||||||
|
return cachedLastModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getSize()
|
public synchronized long getSize()
|
||||||
{
|
{
|
||||||
throw new UnsupportedOperationException();
|
if (!isInfoCached)
|
||||||
|
{
|
||||||
|
getInfo();
|
||||||
|
}
|
||||||
|
return cachedSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ContentReader createReader() throws ContentIOException
|
protected ContentReader createReader() throws ContentIOException
|
||||||
{
|
{
|
||||||
throw new UnsupportedOperationException();
|
return new HttpAlfrescoContentReader(transactionService, authenticationService, baseHttpUrl, getContentUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReadableByteChannel getDirectReadableChannel() throws ContentIOException
|
protected ReadableByteChannel getDirectReadableChannel() throws ContentIOException
|
||||||
{
|
{
|
||||||
throw new UnsupportedOperationException();
|
String contentUrl = getContentUrl();
|
||||||
|
|
||||||
|
Authentication authentication = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!exists())
|
||||||
|
{
|
||||||
|
throw new IOException("Content doesn't exist");
|
||||||
|
}
|
||||||
|
authentication = AuthenticationUtil.setCurrentUser(AuthenticationUtil.SYSTEM_USER_NAME);
|
||||||
|
String ticket = transactionService.getRetryingTransactionHelper().doInTransaction(ticketCallback, false, true);
|
||||||
|
String url = HttpAlfrescoContentReader.generateURL(baseHttpUrl, contentUrl, ticket, false);
|
||||||
|
|
||||||
|
GetMethod method = new GetMethod(url);
|
||||||
|
int statusCode = httpClient.executeMethod(method);
|
||||||
|
if (statusCode == HttpServletResponse.SC_OK)
|
||||||
|
{
|
||||||
|
// Get the stream from the request
|
||||||
|
InputStream contentStream = method.getResponseBodyAsStream();
|
||||||
|
// Attach a listener to the stream to ensure that the HTTP request is cleaned up
|
||||||
|
this.addListener(new StreamCloseListener(method));
|
||||||
|
// Done
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("\n" +
|
||||||
|
"HttpReader retrieve intput stream: \n" +
|
||||||
|
" Reader: " + this + "\n" +
|
||||||
|
" Server: " + baseHttpUrl);
|
||||||
|
}
|
||||||
|
return Channels.newChannel(contentStream);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// The content exists, but we failed to get it
|
||||||
|
throw new IOException("Failed to get content remote content that supposedly exists.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Throwable e)
|
||||||
|
{
|
||||||
|
throw new ContentIOException(
|
||||||
|
"Failed to open stream: \n" +
|
||||||
|
" Reader: " + this + "\n" +
|
||||||
|
" Remote server: " + baseHttpUrl,
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
AuthenticationUtil.setCurrentAuthentication(authentication);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A listener to ensure that the HTTP method gets closed when the content stream it
|
||||||
|
* is serving to the reader is closed.
|
||||||
|
*
|
||||||
|
* @since 2.1
|
||||||
|
* @author Derek Hulley
|
||||||
|
*/
|
||||||
|
private static class StreamCloseListener implements ContentStreamListener
|
||||||
|
{
|
||||||
|
private GetMethod getMethod;
|
||||||
|
private StreamCloseListener(GetMethod getMethod)
|
||||||
|
{
|
||||||
|
this.getMethod = getMethod;
|
||||||
|
}
|
||||||
|
public void contentStreamClosed() throws ContentIOException
|
||||||
|
{
|
||||||
|
try { getMethod.releaseConnection(); } catch (Throwable e) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -24,10 +24,19 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.content.http;
|
package org.alfresco.repo.content.http;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
|
||||||
import org.alfresco.repo.content.AbstractContentStore;
|
import org.alfresco.repo.content.AbstractContentStore;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentData;
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||||
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
|
import org.alfresco.util.ApplicationContextHelper;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A read-only store using HTTP to access content from a remote Alfresco application.
|
* A read-only store using HTTP to access content from a remote Alfresco application.
|
||||||
@@ -40,8 +49,8 @@ import org.alfresco.service.cmr.security.AuthenticationService;
|
|||||||
*/
|
*/
|
||||||
public class HttpAlfrescoStore extends AbstractContentStore
|
public class HttpAlfrescoStore extends AbstractContentStore
|
||||||
{
|
{
|
||||||
AuthenticationComponent authenticationComponent;
|
private TransactionService transactionService;
|
||||||
AuthenticationService authenticationService;
|
private AuthenticationService authenticationService;
|
||||||
private String baseHttpUrl;
|
private String baseHttpUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,11 +61,12 @@ public class HttpAlfrescoStore extends AbstractContentStore
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param authenticationComponent the authentication compoent
|
*
|
||||||
|
* @param transactionService used to ensure proper ticket propagation in a cluster
|
||||||
*/
|
*/
|
||||||
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
|
public void setTransactionService(TransactionService transactionService)
|
||||||
{
|
{
|
||||||
this.authenticationComponent = authenticationComponent;
|
this.transactionService = transactionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,7 +78,8 @@ public class HttpAlfrescoStore extends AbstractContentStore
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the base HTTP URL of the remote Alfresco application.
|
* Set the base HTTP URL of the remote Alfresco application.<br/>
|
||||||
|
* For example: <pre>http://192.168.1.66:8080/alfresco</pre>.
|
||||||
*
|
*
|
||||||
* @param baseHttpUrl the remote HTTP address including the <b>.../alfresco</b>
|
* @param baseHttpUrl the remote HTTP address including the <b>.../alfresco</b>
|
||||||
*/
|
*/
|
||||||
@@ -97,10 +108,140 @@ public class HttpAlfrescoStore extends AbstractContentStore
|
|||||||
public ContentReader getReader(String contentUrl)
|
public ContentReader getReader(String contentUrl)
|
||||||
{
|
{
|
||||||
ContentReader reader = new HttpAlfrescoContentReader(
|
ContentReader reader = new HttpAlfrescoContentReader(
|
||||||
|
transactionService,
|
||||||
authenticationService,
|
authenticationService,
|
||||||
authenticationComponent,
|
|
||||||
baseHttpUrl,
|
baseHttpUrl,
|
||||||
contentUrl);
|
contentUrl);
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the HTTP store against a given server.<br>
|
||||||
|
* Usage:
|
||||||
|
* <pre>
|
||||||
|
* HttpAlfrescoStore help
|
||||||
|
* Print the usage message
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param args the program arguments
|
||||||
|
*/
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
String baseUrl = null;
|
||||||
|
String contentUrl = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (args.length != 2)
|
||||||
|
{
|
||||||
|
printUsage(System.err);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
else if (args[0].equalsIgnoreCase("help"))
|
||||||
|
{
|
||||||
|
printUsage(System.out);
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
baseUrl = args[0];
|
||||||
|
contentUrl = args[1];
|
||||||
|
|
||||||
|
// Start the application to get hold of all the beans
|
||||||
|
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"Starting test of " + HttpAlfrescoStore.class.getName() + " using server " + baseUrl + ".");
|
||||||
|
|
||||||
|
// Do the test
|
||||||
|
doTest(ctx, baseUrl, contentUrl);
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"Completed test of " + HttpAlfrescoStore.class.getName() + " using server " + baseUrl + ".");
|
||||||
|
|
||||||
|
// Done
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
catch (Throwable e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
System.err.println(
|
||||||
|
"Test of " + HttpAlfrescoStore.class.getName() + " using server " + baseUrl + " failed.");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ApplicationContextHelper.closeApplicationContext();
|
||||||
|
}
|
||||||
|
catch (Throwable e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void doTest(ApplicationContext ctx, String baseUrl, String contentUrl) throws Exception
|
||||||
|
{
|
||||||
|
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||||
|
TransactionService transactionService = serviceRegistry.getTransactionService();
|
||||||
|
AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
|
||||||
|
// Construct the store
|
||||||
|
HttpAlfrescoStore store = new HttpAlfrescoStore();
|
||||||
|
store.setTransactionService(transactionService);
|
||||||
|
store.setAuthenticationService(authenticationService);
|
||||||
|
store.setBaseHttpUrl(baseUrl);
|
||||||
|
|
||||||
|
// Now test
|
||||||
|
System.out.println(
|
||||||
|
" Retrieving reader for URL " + contentUrl);
|
||||||
|
ContentReader reader = store.getReader(contentUrl);
|
||||||
|
System.out.println(
|
||||||
|
" Retrieved reader for URL " + contentUrl);
|
||||||
|
// Check if the content exists
|
||||||
|
boolean exists = reader.exists();
|
||||||
|
if (!exists)
|
||||||
|
{
|
||||||
|
System.out.println(
|
||||||
|
" Content doesn't exist: " + contentUrl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println(
|
||||||
|
" Content exists: " + contentUrl);
|
||||||
|
}
|
||||||
|
// Get the content data
|
||||||
|
ContentData contentData = reader.getContentData();
|
||||||
|
System.out.println(
|
||||||
|
" Retrieved content data: " + contentData);
|
||||||
|
|
||||||
|
// Now get the content
|
||||||
|
ByteBuffer buffer = ByteBuffer.allocate((int)reader.getSize());
|
||||||
|
FileChannel channel = reader.getFileChannel();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int count = channel.read(buffer);
|
||||||
|
if (count != reader.getSize())
|
||||||
|
{
|
||||||
|
System.err.println("The number of bytes read was " + count + " but expected " + reader.getSize());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
channel.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void printUsage(OutputStream os) throws IOException
|
||||||
|
{
|
||||||
|
String msg = "Usage: \n" +
|
||||||
|
" HttpAlfrescoStore <server-ip> <content-url>\n" +
|
||||||
|
" server-ip: the remote HTTP server running Alfresco \n" +
|
||||||
|
" content-url: the content URL to retrieve \n" +
|
||||||
|
" Run the test against a server. \n" +
|
||||||
|
" HttpAlfrescoStore help \n" +
|
||||||
|
" Print the usage message";
|
||||||
|
os.write(msg.getBytes());
|
||||||
|
os.flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -348,6 +348,11 @@ public class ReplicatingContentStore extends AbstractContentStore
|
|||||||
{
|
{
|
||||||
for (ContentStore store : secondaryStores)
|
for (ContentStore store : secondaryStores)
|
||||||
{
|
{
|
||||||
|
// Ignore read-only stores
|
||||||
|
if (!store.isWriteSupported())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
store.delete(contentUrl);
|
store.delete(contentUrl);
|
||||||
}
|
}
|
||||||
// log
|
// log
|
||||||
@@ -445,6 +450,19 @@ public class ReplicatingContentStore extends AbstractContentStore
|
|||||||
for (int i = 0; i < stores.size(); i++)
|
for (int i = 0; i < stores.size(); i++)
|
||||||
{
|
{
|
||||||
ContentStore store = stores.get(i);
|
ContentStore store = stores.get(i);
|
||||||
|
// Bypass read-only stores
|
||||||
|
if (!store.isWriteSupported())
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("Ignoring read-only store for content replication: \n" +
|
||||||
|
" Content: " + writer + "\n" +
|
||||||
|
" Store: " + store + "\n" +
|
||||||
|
" Number: " + i);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// replicate the content to the store - we know the URL that we want to write to
|
// replicate the content to the store - we know the URL that we want to write to
|
||||||
|
@@ -71,12 +71,18 @@ public class ReplicatingContentStoreTest extends AbstractWritableContentStoreTes
|
|||||||
primaryStore = new FileContentStore(storeDir);
|
primaryStore = new FileContentStore(storeDir);
|
||||||
// create some secondary file stores
|
// create some secondary file stores
|
||||||
secondaryStores = new ArrayList<ContentStore>(3);
|
secondaryStores = new ArrayList<ContentStore>(3);
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
storeDir = tempDir.getAbsolutePath() + File.separatorChar + GUID.generate();
|
storeDir = tempDir.getAbsolutePath() + File.separatorChar + GUID.generate();
|
||||||
ContentStore store = new FileContentStore(storeDir);
|
FileContentStore store = new FileContentStore(storeDir);
|
||||||
secondaryStores.add(store);
|
secondaryStores.add(store);
|
||||||
|
// Only the first 3 are writable
|
||||||
|
if (i >= 3)
|
||||||
|
{
|
||||||
|
store.setReadOnly(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// Create the replicating store
|
||||||
replicatingStore = new ReplicatingContentStore();
|
replicatingStore = new ReplicatingContentStore();
|
||||||
replicatingStore.setPrimaryStore(primaryStore);
|
replicatingStore.setPrimaryStore(primaryStore);
|
||||||
replicatingStore.setSecondaryStores(secondaryStores);
|
replicatingStore.setSecondaryStores(secondaryStores);
|
||||||
@@ -106,6 +112,11 @@ public class ReplicatingContentStoreTest extends AbstractWritableContentStoreTes
|
|||||||
{
|
{
|
||||||
for (ContentStore store : secondaryStores)
|
for (ContentStore store : secondaryStores)
|
||||||
{
|
{
|
||||||
|
// This is only required for writable stores
|
||||||
|
if (!store.isWriteSupported())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ContentReader reader = store.getReader(contentUrl);
|
ContentReader reader = store.getReader(contentUrl);
|
||||||
assertTrue("Content was not replicated out to the secondary stores within a second", reader.exists());
|
assertTrue("Content was not replicated out to the secondary stores within a second", reader.exists());
|
||||||
assertEquals("The replicated content was incorrect", content, reader.getContentString());
|
assertEquals("The replicated content was incorrect", content, reader.getContentString());
|
||||||
|
@@ -721,9 +721,8 @@ public class FileFolderServiceImpl implements FileFolderService
|
|||||||
// done
|
// done
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
FileInfo parentFileInfo = toFileInfo(parentNodeRef, false);
|
|
||||||
logger.debug("Created: \n" +
|
logger.debug("Created: \n" +
|
||||||
" parent: " + parentFileInfo + "\n" +
|
" parent: " + parentNodeRef + "\n" +
|
||||||
" created: " + fileInfo);
|
" created: " + fileInfo);
|
||||||
}
|
}
|
||||||
return fileInfo;
|
return fileInfo;
|
||||||
|
@@ -217,7 +217,7 @@ public abstract class AbstractReindexComponent implements IndexRecovery
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
transactionService.getRetryingTransactionHelper().doInTransaction(reindexWork);
|
transactionService.getRetryingTransactionHelper().doInTransaction(reindexWork, true);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
<types>
|
<types>
|
||||||
|
|
||||||
<type name="usr:authority">
|
<type name="usr:authority">
|
||||||
<title>Alfreco Authority Abstract Type</title>
|
<title>Alfresco Authority Abstract Type</title>
|
||||||
<parent>sys:base</parent>
|
<parent>sys:base</parent>
|
||||||
</type>
|
</type>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user