use of org.alfresco.service.cmr.transfer.TransferTarget in project alfresco-repository by Alfresco.
the class HttpClientTransmitterImpl method commit.
public void commit(Transfer transfer) throws TransferException {
TransferTarget target = transfer.getTransferTarget();
HttpMethod commitRequest = getPostMethod();
try {
HostConfiguration hostConfig = getHostConfig(target);
HttpState httpState = getHttpState(target);
commitRequest.setPath(target.getEndpointPath() + "/commit");
// Put the transferId on the query string
commitRequest.setQueryString(new NameValuePair[] { new NameValuePair("transferId", transfer.getTransferId()) });
try {
int responseStatus = httpClient.executeMethod(hostConfig, commitRequest, httpState);
checkResponseStatus("commit", responseStatus, commitRequest);
// 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.error(error, e);
throw new TransferException(MSG_HTTP_REQUEST_FAILED, new Object[] { "commit", target.toString(), e.toString() }, e);
}
} finally {
commitRequest.releaseConnection();
}
}
use of org.alfresco.service.cmr.transfer.TransferTarget in project alfresco-repository by Alfresco.
the class HttpClientTransmitterImpl method sendContent.
/**
*/
public void sendContent(Transfer transfer, Set<ContentData> data) throws TransferException {
if (log.isDebugEnabled()) {
log.debug("send content to transfer:" + transfer);
}
TransferTarget target = transfer.getTransferTarget();
PostMethod postContentRequest = getPostMethod();
try {
HostConfiguration hostConfig = getHostConfig(target);
HttpState httpState = getHttpState(target);
try {
postContentRequest.setPath(target.getEndpointPath() + "/post-content");
// Put the transferId on the query string
postContentRequest.setQueryString(new NameValuePair[] { new NameValuePair("transferId", transfer.getTransferId()) });
// Put the transferId on the query string
postContentRequest.setQueryString(new NameValuePair[] { new NameValuePair("transferId", transfer.getTransferId()) });
Part[] parts = new Part[data.size()];
int index = 0;
for (ContentData content : data) {
String contentUrl = content.getContentUrl();
String fileName = TransferCommons.URLToPartName(contentUrl);
log.debug("content partName: " + fileName);
parts[index++] = new ContentDataPart(getContentService(), fileName, content);
}
MultipartRequestEntity requestEntity = new MultipartRequestEntity(parts, postContentRequest.getParams());
postContentRequest.setRequestEntity(requestEntity);
int responseStatus = httpClient.executeMethod(hostConfig, postContentRequest, httpState);
checkResponseStatus("sendContent", responseStatus, postContentRequest);
if (log.isDebugEnabled()) {
log.debug("sent content");
}
} 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[] { "sendContent", target.toString(), e.toString() }, e);
}
} finally {
postContentRequest.releaseConnection();
}
}
use of org.alfresco.service.cmr.transfer.TransferTarget in project alfresco-repository by Alfresco.
the class HttpClientTransmitterImpl method abort.
public void abort(Transfer transfer) throws TransferException {
TransferTarget target = transfer.getTransferTarget();
HttpMethod abortRequest = getPostMethod();
try {
HostConfiguration hostConfig = getHostConfig(target);
HttpState httpState = getHttpState(target);
abortRequest.setPath(target.getEndpointPath() + "/abort");
// Put the transferId on the query string
abortRequest.setQueryString(new NameValuePair[] { new NameValuePair("transferId", transfer.getTransferId()) });
try {
int responseStatus = httpClient.executeMethod(hostConfig, abortRequest, httpState);
checkResponseStatus("abort", responseStatus, abortRequest);
// 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[] { "abort", target.toString(), e.toString() }, e);
}
} finally {
abortRequest.releaseConnection();
}
}
use of org.alfresco.service.cmr.transfer.TransferTarget in project alfresco-repository by Alfresco.
the class TransferOneNodeActionExecuter method executeImpl.
/* (non-Javadoc)
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
TransferTarget target = TransferTestUtil.getTestTarget(transferService);
TransferDefinition td = new TransferDefinition();
td.setNodes(actionedUponNodeRef);
transferService.transfer(target.getName(), td);
}
use of org.alfresco.service.cmr.transfer.TransferTarget in project alfresco-repository by Alfresco.
the class TransferServiceImpl2 method getTransferTargets.
/**
* Given the noderef of a group of transfer targets, return all the contained transfer targets.
* @param groupNode NodeRef
* @return Set<TransferTarget>
*/
private Set<TransferTarget> getTransferTargets(NodeRef groupNode) {
Set<TransferTarget> result = new HashSet<TransferTarget>();
List<ChildAssociationRef> children = nodeService.getChildAssocs(groupNode, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef child : children) {
if (nodeService.getType(child.getChildRef()).equals(TransferModel.TYPE_TRANSFER_TARGET)) {
TransferTargetImpl newTarget = new TransferTargetImpl();
mapTransferTarget(child.getChildRef(), newTarget);
result.add(newTarget);
}
}
return result;
}
Aggregations