我必须在哪里定义 Alfresco 中的连接器?我可以从“.bpmn"文件中使用它们吗?文件? [英] Where do I have to define connectors in Alfresco? Can I use them from a ".bpmn" file?

查看:49
本文介绍了我必须在哪里定义 Alfresco 中的连接器?我可以从“.bpmn"文件中使用它们吗?文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好!我正在尝试从 Alfresco 通信到工作流中的 RESTful ws.有人告诉我,使用连接器来实​​现这一点是个好主意.我正在 ACS 中创建一个 wf 作为 .bpmn 文件,所以 3 个问题:

Good afternoon! I am trying to communicate from Alfresco to a RESTful ws from a workflow. Somebody told me that it will be a good idea to use connector to acomplish that. I am creating a wf in ACS as a .bpmn file, so 3 questions:

  1. 我必须在哪个文件中定义连接器?,我想和这个js脚本一样:

var url = "https://google.com";

var xhr = new XMLHttpRequest();
xhr.open("GET", url);

xhr.onreadystatechange = function () {
   if (xhr.readyState === 4) {
      console.log(xhr.status);
      console.log(xhr.responseText);
   }};

xhr.send();

  1. 我可以直接从 .bpmn 文件使用连接器吗?你能举例说明如何使用它吗?

  1. Can I use the connector directly from the .bpmn file? Could you give me an example on how to use it?

您能给我举个例子来进行 GETPOST 调用吗?

Could you give me an example to make a GET and a POST call?

提前致谢!

推荐答案

连接器是 Web 脚本框架的一部分.Alfresco 共享层有一个 Web 脚本框架,存储库层有一个 Web 脚本框架.

Connectors are part of the web script framework. There is a web script framework in the Alfresco Share tier and there is a web script framework in the repository tier.

在 Web 脚本中,您使用远程"对象以连接到远程 RESTful 端点.例如,通过 API 的项目 ID 从 API 获取一些项目信息的代码可能如下所示:

In web scripts, you use the "remote" object to make connections to remote RESTful end points. For example, the code to fetch some project information from an API via its project ID might look like this:

    var connector = remote.connect("someapp");
    var resp = connector.get("/someapp/projects/" + projectId);
    if (resp.status == 200) {
        obj = JSON.parse(resp);
        model.result = obj;
        model.startDateFormatted = getFormattedDate(model.result.StartDate);
        model.endDateFormatted = getFormattedDate(model.result.EndDate);
    }

那么someapp"在哪里?连接器定义?您可以将其放在 Alfresco 配置文件中,例如共享自定义配置.在基于 Alfresco SDK 的项目中,该文件位于 ./src/main/resources/META-INF/share-config-custom.xml 下的共享模块中:

So where is that "someapp" connector defined? You can put it in an Alfresco config file such as the share custom config. In an Alfresco SDK based project that file lives in the share module under ./src/main/resources/META-INF/share-config-custom.xml:

<config evaluator="string-compare" condition="Remote">
    <remote>
        <endpoint>
            <id>someapp</id>
            <name>Some Remote App</name>
            <connector-id>http</connector-id>
            <endpoint-url>https://someapp.example.org</endpoint-url>
        </endpoint>
    </remote>
</config>

您面临的挑战是您在 Activiti 工作流程中运行,而不是在 Web 脚本中运行.而且,除此之外,远程对象在 repo 层上被禁用,这也是您运行的地方.它可以重新启用,但我手边没有这些步骤,无论如何它对您没有帮助.

The challenge for you is that you are running in an Activiti workflow, not a web script. And, aside from that, the remote object is disabled on the repo tier, which is also where you are running. It can be re-enabled, but I don't have those steps handy and it doesn't help you anyway.

因此,我的建议是使用 Java 委托 在您的工作流程中.从 Java 委托中,您可以做任何您想做的事情,包括利用诸如 Apache HTTP 之类的东西客户端与您需要调用的 API 建立连接.

So, rather than use any of the above, my advice is to use a Java delegate in your workflow. From the Java delegate you can do anything you want, including leveraging something like the Apache HTTP Client to make a connection to the API you need to call.

你可能有一个像这样的委托类:

You might have a delegate class like:

public class RemoteApiInvocationDelegate implements JavaDelegate {
    private Logger logger = LoggerFactory.getLogger(RemoteApiInvocationDelegate.class);

    public void execute(DelegateExecution execution) throws Exception {
        HttpClient httpClient = Utils.noCertClient();

        HttpGet httpGet = new HttpGet("http://someapp.example.org/someapp/projects/12345");
        HttpResponse response = httpClient.execute(httpGet);
        int status = response.getStatusLine().getStatusCode();
        logger.info("Response Status Code: " + status);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line;
        StringBuilder sb = new StringBuilder();
        while ((line = rd.readLine()) != null) {
            sb.append(line);
        }
        logger.info(sb.toString());
    }
}

您对响应执行的操作,例如解析它、提取一些数据并将其设置在流程变量上,例如,取决于您.

What you do with the response, like parse it, extract some data, and set it on a process variable, for example, is up to you.

这篇关于我必须在哪里定义 Alfresco 中的连接器?我可以从“.bpmn"文件中使用它们吗?文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆