mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merge DM-DM_deployment to HEAD
18665 : Switch over to using new surf <formdata multipart-processing="false" /> configuration option. - now the PostContentCommandProcessor and PostSnapshotCommandProcessor handle their own MimePart processing. 18683 : SAIL-288 Implementation of TransferService client side cancelAsync. 18716 : Adding TransferEventBegin missed from asyncCancel work. 18734 : Transfer format : implementation of null properties and Serialized base64 Java objects for type d:any 18749 : SAIL-290: Added features that provide asynchronous commit on the receiver end and the ability to query commit status, as well as code that writes a progress report on the server side (currently only plain text) and the functionality to allow a transfer to be cancelled 18750 : New files that should have been checked in with previous commit but weren't... 18770 : Various transfer service work. - correction to transfer report name. - use surf Base64 Encoder - implementation of async commit to the TransferServiceImpl - implementation of the statusCommand through the HttpClientTransmitter. 18773 : transferId was null. 18780 : Changed the server-side commit to occur asynchronously. Added two test actions to transfer a single node or a tree of nodes. Tweaked TransferDefinition to provide varargs version of setNodes. 18793 : SAIL-290: Added a couple of test actions. Added varargs versions of transfer and transferAsync on TransferService. 18794 : SAIL-290: Added "targetExists" operation to the TransferService interface. 18804 : SAIL-36: Fixed an issue where transfer could fail if numerous nodes with the same cm:name value are transferred. 18805 : SAIL-36: Added model file that should have been with last commit. 18808 Continuing work on transfer report. 18825 TransferServiceImplTest green line. 18836 : Added a little more output to the server-side transfer report. 18848 : More work on transfer report. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18865 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -79,7 +79,7 @@ public class AbortTransferCommandProcessor implements CommandProcessor
|
||||
{
|
||||
logger.debug("abort transfer:" + transferId);
|
||||
|
||||
receiver.abort(transferId);
|
||||
receiver.cancel(transferId);
|
||||
|
||||
// return the unique transfer id (the lock id)
|
||||
StringWriter stringWriter = new StringWriter(300);
|
||||
|
@@ -31,7 +31,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.alfresco.service.cmr.transfer.TransferException;
|
||||
import org.alfresco.service.cmr.transfer.TransferReceiver;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
@@ -77,7 +76,7 @@ public class CommitTransferCommandProcessor implements CommandProcessor
|
||||
|
||||
try
|
||||
{
|
||||
receiver.commit(transferId);
|
||||
receiver.commitAsync(transferId);
|
||||
|
||||
// return the unique transfer id (the lock id)
|
||||
StringWriter stringWriter = new StringWriter(300);
|
||||
@@ -94,17 +93,14 @@ public class CommitTransferCommandProcessor implements CommandProcessor
|
||||
resp.setStatus(Status.STATUS_OK);
|
||||
resp.getWriter().write(response);
|
||||
|
||||
logger.debug("committed transferId:" + transferId);
|
||||
|
||||
return Status.STATUS_OK;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.debug("caught exception :" + ex.toString(), ex);
|
||||
|
||||
//TODO Think very carefully about this.
|
||||
//TODO MER I think we need to roll forward here since we are after prepare.
|
||||
receiver.end(transferId);
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("caught exception :" + ex.toString(), ex);
|
||||
}
|
||||
if (ex instanceof TransferException)
|
||||
{
|
||||
throw (TransferException) ex;
|
||||
|
@@ -91,36 +91,37 @@ public class PostContentCommandProcessor implements CommandProcessor
|
||||
|
||||
try
|
||||
{
|
||||
//TODO - See comments on PostSnapshotCommandProcessor RE WebScript framework
|
||||
// ServletFileUpload upload = new ServletFileUpload();
|
||||
// FileItemIterator iter = upload.getItemIterator(servletRequest);
|
||||
// while (iter.hasNext())
|
||||
// {
|
||||
// FileItemStream item = iter.next();
|
||||
// if (!item.isFormField() && "content".equals(item.getFieldName()))
|
||||
// {
|
||||
// receiver.saveContent(transferId, item.getName(), item.openStream());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
||||
WebScriptServletRequest alfRequest = (WebScriptServletRequest)req;
|
||||
String[] names = alfRequest.getParameterNames();
|
||||
for(String name : names)
|
||||
|
||||
ServletFileUpload upload = new ServletFileUpload();
|
||||
FileItemIterator iter = upload.getItemIterator(servletRequest);
|
||||
while (iter.hasNext())
|
||||
{
|
||||
FormField item = alfRequest.getFileField(name);
|
||||
|
||||
if(item != null)
|
||||
FileItemStream item = iter.next();
|
||||
String name = item.getFieldName();
|
||||
if (!item.isFormField())
|
||||
{
|
||||
logger.debug("got content Mime Part : " + name);
|
||||
receiver.saveContent(transferId, item.getName(), item.getInputStream());
|
||||
receiver.saveContent(transferId, item.getName(), item.openStream());
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO - should this be an exception?
|
||||
logger.debug("Unable to get content for Mime Part : " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WebScriptServletRequest alfRequest = (WebScriptServletRequest)req;
|
||||
// String[] names = alfRequest.getParameterNames();
|
||||
// for(String name : names)
|
||||
// {
|
||||
// FormField item = alfRequest.getFileField(name);
|
||||
//
|
||||
// if(item != null)
|
||||
// {
|
||||
// logger.debug("got content Mime Part : " + name);
|
||||
// receiver.saveContent(transferId, item.getName(), item.getInputStream());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //TODO - should this be an exception?
|
||||
// logger.debug("Unable to get content for Mime Part : " + name);
|
||||
// }
|
||||
// }
|
||||
|
||||
logger.debug("success");
|
||||
|
||||
|
@@ -85,38 +85,33 @@ public class PostSnapshotCommandProcessor implements CommandProcessor
|
||||
|
||||
try
|
||||
{
|
||||
logger.debug("about to upload manifest file");
|
||||
logger.debug("about to upload manifest file");
|
||||
|
||||
// OLD implenementation
|
||||
// ServletFileUpload upload = new ServletFileUpload();
|
||||
// FileItemIterator iter = upload.getItemIterator(servletRequest);
|
||||
// while (iter.hasNext())
|
||||
// {
|
||||
// FileItemStream item = iter.next();
|
||||
// if (!item.isFormField() && "manifest".equals(item.getFieldName()))
|
||||
// {
|
||||
// logger.debug("save snapshot content item");
|
||||
// receiver.saveSnapshot(transferId, item.openStream());
|
||||
// // receiver.saveContent(transferId, item.getName(), item.openStream());
|
||||
// }
|
||||
// }
|
||||
|
||||
// Work Around impelemtation with an implementation that uses FormData
|
||||
// This has the side effect that the content is written to disk and parsed twice.
|
||||
// Needs reworking but requires changes to the WebScript framework
|
||||
// MER - Brian and Kevin to discuss
|
||||
WebScriptServletRequest alfRequest = (WebScriptServletRequest)req;
|
||||
FormField field = alfRequest.getFileField(TransferCommons.PART_NAME_MANIFEST);
|
||||
|
||||
if(field != null)
|
||||
ServletFileUpload upload = new ServletFileUpload();
|
||||
FileItemIterator iter = upload.getItemIterator(servletRequest);
|
||||
while (iter.hasNext())
|
||||
{
|
||||
logger.debug("got manifest file");
|
||||
receiver.saveSnapshot(transferId, field.getInputStream());
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug("manifest is missing");
|
||||
FileItemStream item = iter.next();
|
||||
if (!item.isFormField() && TransferCommons.PART_NAME_MANIFEST.equals(item.getFieldName()))
|
||||
{
|
||||
logger.debug("got manifest file");
|
||||
receiver.saveSnapshot(transferId, item.openStream());
|
||||
}
|
||||
}
|
||||
|
||||
// <formdata multipart-processing="false" /> so the following code does not work
|
||||
// WebScriptServletRequest alfRequest = (WebScriptServletRequest)req;
|
||||
// FormField field = alfRequest.getFileField(TransferCommons.PART_NAME_MANIFEST);
|
||||
//
|
||||
// if(field != null)
|
||||
// {
|
||||
// logger.debug("got manifest file");
|
||||
// receiver.saveSnapshot(transferId, field.getInputStream());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// logger.debug("manifest is missing");
|
||||
// }
|
||||
|
||||
logger.debug("success");
|
||||
resp.setStatus(Status.STATUS_OK);
|
||||
|
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (C) 2009-2010 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 received a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.web.scripts.transfer;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.alfresco.service.cmr.transfer.TransferException;
|
||||
import org.alfresco.service.cmr.transfer.TransferProgress;
|
||||
import org.alfresco.service.cmr.transfer.TransferReceiver;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||
import org.springframework.extensions.webscripts.json.JSONWriter;
|
||||
import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest;
|
||||
|
||||
/**
|
||||
* This command processor is used to record the start a transfer. No other transfer can be started after this command
|
||||
* has executed until the started transfer terminates.
|
||||
*
|
||||
* @author brian
|
||||
*
|
||||
*/
|
||||
public class StatusCommandProcessor implements CommandProcessor
|
||||
{
|
||||
private static final String MSG_CAUGHT_UNEXPECTED_EXCEPTION = "transfer_service.receiver.caught_unexpected_exception";
|
||||
|
||||
private TransferReceiver receiver;
|
||||
|
||||
private final static Log logger = LogFactory.getLog(StatusCommandProcessor.class);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.alfresco.repo.web.scripts.transfer.CommandProcessor#process(org.alfresco .web.scripts.WebScriptRequest,
|
||||
* org.alfresco.web.scripts.WebScriptResponse)
|
||||
*/
|
||||
public int process(WebScriptRequest req, WebScriptResponse resp)
|
||||
{
|
||||
//Read the transfer id from the request
|
||||
HttpServletRequest servletRequest = ((WebScriptServletRequest)req).getHttpServletRequest();
|
||||
String transferId = servletRequest.getParameter("transferId");
|
||||
|
||||
if (transferId == null)
|
||||
{
|
||||
logger.debug("transferId is missing");
|
||||
resp.setStatus(Status.STATUS_BAD_REQUEST);
|
||||
return Status.STATUS_BAD_REQUEST;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TransferProgress progress = receiver.getProgressMonitor().getProgress(transferId);
|
||||
|
||||
// return the unique transfer id (the lock id)
|
||||
StringWriter stringWriter = new StringWriter(300);
|
||||
JSONWriter jsonWriter = new JSONWriter(stringWriter);
|
||||
jsonWriter.startObject();
|
||||
jsonWriter.writeValue("transferId", transferId);
|
||||
jsonWriter.writeValue("status", progress.getStatus().toString());
|
||||
jsonWriter.writeValue("currentPosition", progress.getCurrentPosition());
|
||||
jsonWriter.writeValue("endPosition", progress.getEndPosition());
|
||||
if (progress.getError() != null)
|
||||
{
|
||||
//FIXME: bjr: write this
|
||||
}
|
||||
jsonWriter.endObject();
|
||||
String response = stringWriter.toString();
|
||||
|
||||
resp.setContentType("application/json");
|
||||
resp.setContentEncoding("UTF-8");
|
||||
int length = response.getBytes("UTF-8").length;
|
||||
resp.addHeader("Content-Length", "" + length);
|
||||
resp.setStatus(Status.STATUS_OK);
|
||||
resp.getWriter().write(response);
|
||||
|
||||
logger.debug("transfer started" + transferId);
|
||||
|
||||
return Status.STATUS_OK;
|
||||
|
||||
}
|
||||
catch (TransferException ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new TransferException(MSG_CAUGHT_UNEXPECTED_EXCEPTION, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param receiver
|
||||
* the receiver to set
|
||||
*/
|
||||
public void setReceiver(TransferReceiver receiver)
|
||||
{
|
||||
this.receiver = receiver;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
package org.alfresco.repo.web.scripts.transfer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.alfresco.service.cmr.transfer.TransferException;
|
||||
import org.springframework.extensions.webscripts.json.JSONWriter;
|
||||
|
||||
public class TransferProcessorUtil
|
||||
{
|
||||
public static String writeError(TransferException ex) throws IOException
|
||||
{
|
||||
StringWriter stringWriter = new StringWriter(300);
|
||||
JSONWriter jsonWriter = new JSONWriter(stringWriter);
|
||||
jsonWriter.startObject();
|
||||
jsonWriter.writeValue("errorId", ex.getMsgId());
|
||||
jsonWriter.startValue("errorParams");
|
||||
jsonWriter.startArray();
|
||||
stringWriter.write(writeErrorParams(ex.getMsgParams()));
|
||||
jsonWriter.endArray();
|
||||
jsonWriter.endObject();
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stringWriter
|
||||
* @param msgParams
|
||||
*/
|
||||
public static String writeErrorParams(Object[] msgParams)
|
||||
{
|
||||
if (msgParams == null) return "";
|
||||
StringWriter writer = new StringWriter(300);
|
||||
boolean first = true;
|
||||
for (Object param : msgParams) {
|
||||
if (!first) {
|
||||
writer.write(",");
|
||||
}
|
||||
if (param != null) {
|
||||
writer.write("\"");
|
||||
writer.write(JSONWriter.encodeJSONString(param.toString()));
|
||||
writer.write("\"");
|
||||
} else {
|
||||
writer.write("null");
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -26,7 +26,6 @@
|
||||
package org.alfresco.repo.web.scripts.transfer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@@ -109,7 +108,7 @@ public class TransferWebScript extends AbstractWebScript
|
||||
{
|
||||
log.debug("transfer exception caught", ex);
|
||||
res.setStatus(Status.STATUS_INTERNAL_SERVER_ERROR);
|
||||
String error = writeError(ex);
|
||||
String error = TransferProcessorUtil.writeError(ex);
|
||||
|
||||
res.setContentType("application/json");
|
||||
res.setContentEncoding("UTF-8");
|
||||
@@ -132,46 +131,4 @@ public class TransferWebScript extends AbstractWebScript
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ex
|
||||
* @return
|
||||
*/
|
||||
private String writeError(TransferException ex) throws IOException
|
||||
{
|
||||
StringWriter stringWriter = new StringWriter(300);
|
||||
JSONWriter jsonWriter = new JSONWriter(stringWriter);
|
||||
jsonWriter.startObject();
|
||||
jsonWriter.writeValue("errorId", ex.getMsgId());
|
||||
jsonWriter.startValue("errorParams");
|
||||
jsonWriter.startArray();
|
||||
writeErrorParams(stringWriter, ex.getMsgParams());
|
||||
jsonWriter.endArray();
|
||||
jsonWriter.endObject();
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stringWriter
|
||||
* @param msgParams
|
||||
*/
|
||||
private void writeErrorParams(StringWriter writer, Object[] msgParams)
|
||||
{
|
||||
if (msgParams == null) return;
|
||||
|
||||
boolean first = true;
|
||||
for (Object param : msgParams) {
|
||||
if (!first) {
|
||||
writer.write(",");
|
||||
}
|
||||
if (param != null) {
|
||||
writer.write("\"");
|
||||
writer.write(JSONWriter.encodeJSONString(param.toString()));
|
||||
writer.write("\"");
|
||||
} else {
|
||||
writer.write("null");
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user