use of org.alfresco.service.cmr.transfer.TransferProgress 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