How to access the asset in workflow process step

假如想象 提交于 2019-12-11 10:35:36

问题


I am trying to write a workflow process step for the DAM update asset such that the uploaded asset will be sent to an external service that will modify the asset and then the modified asset can be sent to the Metadata extraction step. So I've added my process step to the DAM update asset like this:

And my code looks like this so far:

public void execute(WorkItem item, WorkflowSession wfsession,MetaDataMap args) throws WorkflowException {
    try
    {
        log.info("Here2 in execute method");    //ensure that the execute method is invoked

        final Map<String, Object> map = new HashMap<String, Object>();
        map.put( "user.jcr.session", wfsession.getSession());

        ResourceResolver rr = resolverFactory.getResourceResolver(map);
        String path = item.getWorkflowData().getPayload().toString();
        log.info("Here2 path: " + path);
        Resource resource = rr.getResource(path);
        log.info("Here2 resource: " + resource);
        InputStream is = resource.adaptTo(InputStream.class);
        log.info("Here2 assets IS: " + is);
    }

    catch (Exception e)
    {
        log.info("Here Error");
        e.printStackTrace();
    }
}

This is what I see in the logs when I upload an asset:

Here2 in execute method Here2 path: /content/dam/photo1.JPG/jcr:content/renditions/original Here2 asset: null

Question

  • My external service has an API accepting requests over HTTP. How should I send over the asset to the external service?
  • Once the external service modifies the asset, what should I do so that the Metadata extraction step reads the modified asset instead of the original?

回答1:


In order to access your external service via HTTP, you have to write a client. CQ provides commons-httpclient bundle and you may use it to access the service. Documentation for the library can be found here. I don't know if the service expects that the file will be send using PUT or POST, but httpclient provides all these methods. All you have to do is to provide appropriate InputStream. Adapt your resource to Rendition and use getStream() method to get the InputStream.

When you'll get the modified asset from the webservice, you need to replace the original one:

// rendition = ...;      // original rendition object created as above
// newInputStream = ...; // new asset received from your webservice
Asset asset = rendition.getAsset();
asset.addRendition("original", newInputStream, rendition.getMimeType());


来源:https://stackoverflow.com/questions/24473136/how-to-access-the-asset-in-workflow-process-step

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!