use of org.alfresco.service.cmr.transfer.TransferException in project alfresco-remote-api by Alfresco.
the class PostSnapshotCommandProcessor method process.
/* (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) {
int result = Status.STATUS_OK;
// Unwrap to a WebScriptServletRequest if we have one
WebScriptServletRequest webScriptServletRequest = null;
WebScriptRequest current = req;
do {
if (current instanceof WebScriptServletRequest) {
webScriptServletRequest = (WebScriptServletRequest) current;
current = null;
} else if (current instanceof WrappingWebScriptRequest) {
current = ((WrappingWebScriptRequest) req).getNext();
} else {
current = null;
}
} while (current != null);
if (webScriptServletRequest == null) {
logger.debug("bad request, not assignable from");
resp.setStatus(Status.STATUS_BAD_REQUEST);
return Status.STATUS_BAD_REQUEST;
}
// We can't use the WebScriptRequest version of getParameter, since that may cause the content stream
// to be parsed. Get hold of the raw HttpServletRequest and work with that.
HttpServletRequest servletRequest = webScriptServletRequest.getHttpServletRequest();
// Read the transfer id from the request
String transferId = servletRequest.getParameter("transferId");
if ((transferId == null) || !ServletFileUpload.isMultipartContent(servletRequest)) {
logger.debug("bad request, not multipart");
resp.setStatus(Status.STATUS_BAD_REQUEST);
return Status.STATUS_BAD_REQUEST;
}
try {
logger.debug("about to upload manifest file");
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(servletRequest);
while (iter.hasNext()) {
FileItemStream item = iter.next();
if (!item.isFormField() && TransferCommons.PART_NAME_MANIFEST.equals(item.getFieldName())) {
logger.debug("got manifest file");
receiver.saveSnapshot(transferId, item.openStream());
}
}
logger.debug("success");
resp.setStatus(Status.STATUS_OK);
OutputStream out = resp.getOutputStream();
resp.setContentType("text/xml");
resp.setContentEncoding("utf-8");
receiver.generateRequsite(transferId, out);
out.close();
} catch (Exception ex) {
logger.debug("exception caught", ex);
if (transferId != null) {
logger.debug("ending transfer", ex);
receiver.end(transferId);
}
if (ex instanceof TransferException) {
throw (TransferException) ex;
}
throw new TransferException(MSG_CAUGHT_UNEXPECTED_EXCEPTION, ex);
}
return result;
}
use of org.alfresco.service.cmr.transfer.TransferException in project alfresco-remote-api by Alfresco.
the class PrepareTransferCommandProcessor method process.
/*
* (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) {
String transferRecordId = null;
// Read the transfer id from the request
// Unwrap to a WebScriptServletRequest if we have one
WebScriptServletRequest webScriptServletRequest = null;
WebScriptRequest current = req;
do {
if (current instanceof WebScriptServletRequest) {
webScriptServletRequest = (WebScriptServletRequest) current;
current = null;
} else if (current instanceof WrappingWebScriptRequest) {
current = ((WrappingWebScriptRequest) req).getNext();
} else {
current = null;
}
} while (current != null);
HttpServletRequest servletRequest = webScriptServletRequest.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 {
logger.debug("prepare transferId: " + transferId);
receiver.prepare(transferId);
// return the unique transfer id (the lock id)
StringWriter stringWriter = new StringWriter(300);
JSONWriter jsonWriter = new JSONWriter(stringWriter);
jsonWriter.startObject();
jsonWriter.writeValue("transferId", transferRecordId);
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("prepared transferId: " + transferId);
return Status.STATUS_OK;
} catch (Exception ex) {
logger.debug("in exception handler", ex);
receiver.end(transferRecordId);
if (ex instanceof TransferException) {
throw (TransferException) ex;
}
throw new TransferException(MSG_CAUGHT_UNEXPECTED_EXCEPTION, ex);
}
}
use of org.alfresco.service.cmr.transfer.TransferException in project alfresco-remote-api by Alfresco.
the class ReportCommandProcessor method process.
/*
* (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
// Unwrap to a WebScriptServletRequest if we have one
WebScriptServletRequest webScriptServletRequest = null;
WebScriptRequest current = req;
do {
if (current instanceof WebScriptServletRequest) {
webScriptServletRequest = (WebScriptServletRequest) current;
current = null;
} else if (current instanceof WrappingWebScriptRequest) {
current = ((WrappingWebScriptRequest) req).getNext();
} else {
current = null;
}
} while (current != null);
HttpServletRequest servletRequest = webScriptServletRequest.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 {
OutputStream out = resp.getOutputStream();
try {
resp.setContentType("text/xml");
resp.setContentEncoding("utf-8");
BufferedInputStream br = new BufferedInputStream(receiver.getProgressMonitor().getLogInputStream(transferId));
try {
byte[] buffer = new byte[1000];
int i = br.read(buffer);
while (i > 0) {
out.write(buffer, 0, i);
i = br.read(buffer);
}
} finally {
br.close();
}
} finally {
out.flush();
out.close();
}
return Status.STATUS_OK;
} catch (TransferException ex) {
throw ex;
} catch (Exception ex) {
throw new TransferException(MSG_CAUGHT_UNEXPECTED_EXCEPTION, ex);
}
}
use of org.alfresco.service.cmr.transfer.TransferException in project alfresco-remote-api by Alfresco.
the class StatusCommandProcessor method process.
/*
* (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
// Unwrap to a WebScriptServletRequest if we have one
WebScriptServletRequest webScriptServletRequest = null;
WebScriptRequest current = req;
do {
if (current instanceof WebScriptServletRequest) {
webScriptServletRequest = (WebScriptServletRequest) current;
current = null;
} else if (current instanceof WrappingWebScriptRequest) {
current = ((WrappingWebScriptRequest) req).getNext();
} else {
current = null;
}
} while (current != null);
HttpServletRequest servletRequest = webScriptServletRequest.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);
if (logger.isDebugEnabled()) {
logger.debug(progress);
}
JSONObject progressObject = new JSONObject();
progressObject.put("transferId", transferId);
progressObject.put("status", progress.getStatus().toString());
progressObject.put("currentPosition", progress.getCurrentPosition());
progressObject.put("endPosition", progress.getEndPosition());
if (progress.getError() != null) {
JSONObject errorObject = errorSerializer.serialize(progress.getError());
progressObject.put("error", errorObject);
}
String response = progressObject.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);
return Status.STATUS_OK;
} catch (TransferException ex) {
throw ex;
} catch (Exception ex) {
throw new TransferException(MSG_CAUGHT_UNEXPECTED_EXCEPTION, ex);
}
}
Aggregations