Search in sources :

Example 1 with TransferTarget

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

Example 2 with TransferTarget

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();
    }
}
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 3 with TransferTarget

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

Example 4 with TransferTarget

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

Example 5 with TransferTarget

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