use of org.alfresco.service.cmr.transfer.TransferTarget in project alfresco-repository by Alfresco.
the class ScriptTransferService method getAllTransferTargets.
public ScriptTransferTarget[] getAllTransferTargets() {
Set<TransferTarget> values = transferService.getTransferTargets();
ScriptTransferTarget[] retVal = new ScriptTransferTarget[values.size()];
int i = 0;
for (TransferTarget value : values) {
retVal[i++] = new ScriptTransferTarget(value);
}
return retVal;
}
use of org.alfresco.service.cmr.transfer.TransferTarget in project alfresco-repository by Alfresco.
the class HttpClientTransmitterImpl method prepare.
public void prepare(Transfer transfer) throws TransferException {
TransferTarget target = transfer.getTransferTarget();
HttpMethod prepareRequest = getPostMethod();
try {
HostConfiguration hostConfig = getHostConfig(target);
HttpState httpState = getHttpState(target);
prepareRequest.setPath(target.getEndpointPath() + "/prepare");
// Put the transferId on the query string
prepareRequest.setQueryString(new NameValuePair[] { new NameValuePair("transferId", transfer.getTransferId()) });
try {
int responseStatus = httpClient.executeMethod(hostConfig, prepareRequest, httpState);
checkResponseStatus("prepare", responseStatus, prepareRequest);
// If we get here then we've received a 200 response
// We're expecting the transfer id encoded in a JSON object...
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
String error = "Failed to execute HTTP request to target";
log.debug(error, e);
throw new TransferException(MSG_HTTP_REQUEST_FAILED, new Object[] { "prepare", target.toString(), e.toString() }, e);
}
} finally {
prepareRequest.releaseConnection();
}
}
use of org.alfresco.service.cmr.transfer.TransferTarget in project alfresco-repository by Alfresco.
the class HttpClientTransmitterImpl method getStatus.
// end of sendContent
/**
*/
public TransferProgress getStatus(Transfer transfer) throws TransferException {
TransferTarget target = transfer.getTransferTarget();
HttpMethod statusRequest = getPostMethod();
try {
HostConfiguration hostConfig = getHostConfig(target);
HttpState httpState = getHttpState(target);
statusRequest.setPath(target.getEndpointPath() + "/status");
// Put the transferId on the query string
statusRequest.setQueryString(new NameValuePair[] { new NameValuePair("transferId", transfer.getTransferId()) });
try {
int responseStatus = httpClient.executeMethod(hostConfig, statusRequest, httpState);
checkResponseStatus("status", responseStatus, statusRequest);
// If we get here then we've received a 200 response
String statusPayload = statusRequest.getResponseBodyAsString();
JSONObject statusObj = new JSONObject(statusPayload);
// We're expecting the transfer progress encoded in a JSON object...
int currentPosition = statusObj.getInt("currentPosition");
int endPosition = statusObj.getInt("endPosition");
String statusStr = statusObj.getString("status");
TransferProgress p = new TransferProgress();
if (statusObj.has("error")) {
JSONObject errorJSON = statusObj.getJSONObject("error");
Throwable throwable = rehydrateError(errorJSON);
p.setError(throwable);
}
p.setStatus(TransferProgress.Status.valueOf(statusStr));
p.setCurrentPosition(currentPosition);
p.setEndPosition(endPosition);
return p;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
String error = "Failed to execute HTTP request to target";
log.debug(error, e);
throw new TransferException(MSG_HTTP_REQUEST_FAILED, new Object[] { "status", target.toString(), e.toString() }, e);
}
} finally {
statusRequest.releaseConnection();
}
}
use of org.alfresco.service.cmr.transfer.TransferTarget in project alfresco-repository by Alfresco.
the class HttpClientTransmitterImpl method getTransferReport.
/**
*/
public void getTransferReport(Transfer transfer, OutputStream result) {
TransferTarget target = transfer.getTransferTarget();
PostMethod getReportRequest = getPostMethod();
try {
HostConfiguration hostConfig = getHostConfig(target);
HttpState httpState = getHttpState(target);
try {
getReportRequest.setPath(target.getEndpointPath() + "/report");
// Put the transferId on the query string
getReportRequest.setQueryString(new NameValuePair[] { new NameValuePair("transferId", transfer.getTransferId()) });
int responseStatus = httpClient.executeMethod(hostConfig, getReportRequest, httpState);
checkResponseStatus("getReport", responseStatus, getReportRequest);
InputStream is = getReportRequest.getResponseBodyAsStream();
// Now copy the response input stream to result.
final ReadableByteChannel inputChannel = Channels.newChannel(is);
final WritableByteChannel outputChannel = Channels.newChannel(result);
try {
// copy the channels
channelCopy(inputChannel, outputChannel);
} finally {
// closing the channels
inputChannel.close();
outputChannel.close();
}
return;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
String error = "Failed to execute HTTP request to target";
log.debug(error, e);
throw new TransferException(MSG_HTTP_REQUEST_FAILED, new Object[] { "getTransferReport", target.toString(), e.toString() }, e);
}
} finally {
getReportRequest.releaseConnection();
}
}
use of org.alfresco.service.cmr.transfer.TransferTarget in project alfresco-repository by Alfresco.
the class TransferServiceImpl2 method getTransferTargets.
/**
* Get all transfer targets
*/
public Set<TransferTarget> getTransferTargets() {
NodeRef home = getTransferHome();
Set<TransferTarget> ret = new HashSet<TransferTarget>();
// get all groups
List<ChildAssociationRef> groups = nodeService.getChildAssocs(home);
// for each group
for (ChildAssociationRef group : groups) {
NodeRef groupNode = group.getChildRef();
ret.addAll(getTransferTargets(groupNode));
}
return ret;
}
Aggregations