Search in sources :

Example 26 with TransferTarget

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();
    }
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) TransferException(org.alfresco.service.cmr.transfer.TransferException) HostConfiguration(org.apache.commons.httpclient.HostConfiguration) HttpState(org.apache.commons.httpclient.HttpState) TransferTarget(org.alfresco.service.cmr.transfer.TransferTarget) JSONObject(org.json.JSONObject) HttpMethod(org.apache.commons.httpclient.HttpMethod) TransferException(org.alfresco.service.cmr.transfer.TransferException) IOException(java.io.IOException)

Example 27 with TransferTarget

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();
    }
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HostConfiguration(org.apache.commons.httpclient.HostConfiguration) HttpState(org.apache.commons.httpclient.HttpState) TransferTarget(org.alfresco.service.cmr.transfer.TransferTarget) MultipartRequestEntity(org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity) TransferException(org.alfresco.service.cmr.transfer.TransferException) IOException(java.io.IOException) TransferException(org.alfresco.service.cmr.transfer.TransferException) ContentData(org.alfresco.service.cmr.repository.ContentData) FilePart(org.apache.commons.httpclient.methods.multipart.FilePart) Part(org.apache.commons.httpclient.methods.multipart.Part) JSONObject(org.json.JSONObject)

Example 28 with TransferTarget

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();
    }
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) TransferException(org.alfresco.service.cmr.transfer.TransferException) HostConfiguration(org.apache.commons.httpclient.HostConfiguration) HttpState(org.apache.commons.httpclient.HttpState) TransferTarget(org.alfresco.service.cmr.transfer.TransferTarget) JSONObject(org.json.JSONObject) HttpMethod(org.apache.commons.httpclient.HttpMethod) TransferException(org.alfresco.service.cmr.transfer.TransferException) IOException(java.io.IOException)

Example 29 with TransferTarget

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);
}
Also used : TransferDefinition(org.alfresco.service.cmr.transfer.TransferDefinition) TransferTarget(org.alfresco.service.cmr.transfer.TransferTarget)

Example 30 with TransferTarget

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;
}
Also used : TransferTarget(org.alfresco.service.cmr.transfer.TransferTarget) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) HashSet(java.util.HashSet)

Aggregations

TransferTarget (org.alfresco.service.cmr.transfer.TransferTarget)48 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)30 Test (org.junit.Test)30 NodeRef (org.alfresco.service.cmr.repository.NodeRef)29 TransferDefinition (org.alfresco.service.cmr.transfer.TransferDefinition)26 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)25 HashSet (java.util.HashSet)22 Locale (java.util.Locale)18 DescriptorService (org.alfresco.service.descriptor.DescriptorService)16 Pair (org.alfresco.util.Pair)14 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)13 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)12 TransferException (org.alfresco.service.cmr.transfer.TransferException)12 ArrayList (java.util.ArrayList)10 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)10 IOException (java.io.IOException)8 Path (org.alfresco.service.cmr.repository.Path)8 List (java.util.List)7 QName (org.alfresco.service.namespace.QName)7 HostConfiguration (org.apache.commons.httpclient.HostConfiguration)7