简体   繁体   English

在Orbeon xforms中调用REST Web服务

[英]Call REST webservice in Orbeon xforms

I'm newbie in Orbeon xforms, so I ask my questions here. 我是Orbeon xforms的新手,所以我在这里问我的问题。 I have REST webservice with some address (method GET) and I want to call him and the result should be provide to metadata of my form: 我有一个带有某些地址(方法GET)的REST Web服务,我想给他打电话,结果应提供给表单的元数据:

<!-- Main instance -->
<xforms:instance id="fr-form-instance">
    <form>
        <section-meta>
            <resultOfMyRestWebservice/>

I've tried to follow this tutorial http://wiki.orbeon.com/forms/how-to/logic/load-initial-form-data (pull solution) but I don't know how I can put the result of rest in the marker: resultOfMyRestWebservice, and where I have to put the submission code: 我试图按照本教程http://wiki.orbeon.com/forms/how-to/logic/load-initial-form-data (拉式解决方案)进行操作,但我不知道如何得出放在标记:resultOfMyRestWebservice中,我必须在其中放置提交代码:

<xforms:submission
    id="load-data-submission"
    method="get" serialization="none"
    resource="addressOfMyRestWS/{xxforms:get-request-parameter('myParam')}"
    replace="?" instance="?"/>

regards 问候

If I were you I would use a temporary run-time instance to hold the results of your REST call and then use setvalue to populate your persisting instance. 如果您是我,我将使用一个临时的运行时实例来保存REST调用的结果,然后使用setvalue填充持久化的实例。

The following example works if you define the structure of your meta-data in your model, so you can use setvalue to populate. 如果您在模型中定义元数据的结构,则以下示例适用,因此可以使用setvalue进行填充。 Otherwise you can use insert. 否则,您可以使用插入。

Ie. IE浏览器。 In your xforms:model define: 在您的xforms:model中定义:

<!-- Run-time instance to hold Service response -->
<xforms:instance id="fr-service-response-instance" xxforms:exclude-result-prefixes="#all">
    <response/>
</xforms:instance>

Define your submission to replace this response instance: 定义提交以替换此响应实例:

<xforms:submission id="load-data-submission" method="get"
    serialization="none" mediatype="application/xml"
    resource="addressOfMyRestWS/{xxforms:get-request-parameter('myParam')}"
    replace="instance" instance="fr-service-response-instance"/>

And then create an action to call the submission and populate your instance: 然后创建一个动作来调用提交并填充您的实例:

<!-- Populate Data
     uses Load Data Submission
     runs on form load -->
<xforms:action id="populate-data-binding">
    <xforms:action ev:event="xforms-ready" ev:observer="fr-form-model" if="true()">
         <xforms:send submission="load-data-submission"/>
    </xforms:action>
    <!-- Populate resultOfMyRestWebservice control with pathToResults value
         following successful submission -->
    <xforms:action ev:event="xforms-submit-done" ev:observer="load-data-submission"
                context="instance('fr-service-response-instance')">
         <xforms:action>
               <xf:var name="control-name" value="'resultOfMyRestWebservice'" as="xs:string"/>
               <xf:var name="control-value" value="/pathToResults" as="xs:string"/>
               <xforms:setvalue ref="instance('fr-form-instance')/*/*[name() = $control-name]"
                        value="$control-value"/>
         </xforms:action>
    </xforms:action>
</xforms:action>

Note pathToResults is the xpath to the value you want from the results. 注意pathToResults是从结果中获取所需值的xpath。

I do everything like in mentioned tutorial: http://wiki.orbeon.com/forms/how-to/logic/load-initial-form-data I mean: 我所做的一切都与上述教程中的类似: http : //wiki.orbeon.com/forms/how-to/logic/load-initial-form-data我的意思是:

....
 <xf:model id="fr-form-model" xxf:expose-xpath-types="true">


        <!-- User in which user data is collected -->
        <xf:instance id="user-data">
            <registration>
                <first-name/>
                <last-name/>
            </registration>
        </xf:instance>

        <!-- Load initial data from a service -->
        <xf:send ev:event="xforms-model-construct-done" submission="load-data-submission"/>
        <xf:submission id="load-data-submission" method="get" serialization="none"
                       resource="http://github.com/orbeon/orbeon-forms/raw/master/src/resources/apps/xforms-sandbox/samples/howto/load-initial-form-data-pull-instance.xml"
                       replace="instance"
                       instance="user-data"/>

        <!-- Main instance -->
        <xf:instance id="fr-form-instance">
            <form>
                <name/>
....
....
 <fr:body xmlns:xbl="http://www.w3.org/ns/xbl"
                 xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel"
                 xmlns:oxf="http://www.orbeon.com/oxf/processors"
                 xmlns:p="http://www.orbeon.com/oxf/pipeline">
....
    <xforms:action ev:event="xforms-enabled">
    <xforms:setvalue ref="xxf:instance('fr-form-instance')/name"
        value="xxf:instance('user-data')/first-name"/>              
    </xforms:action>
</fr:body>
....

I want to get xml from link ( http://github.com/orbeon/orbeon-forms/raw/master/src/resources/apps/xforms-sandbox/samples/howto/load-initial-form-data-pull-instance.xml ), put in to the 'user-data' instance and then get the first-name and put to the 'name' marker in the 'fr-form-instance'. 我想从链接( http://github.com/orbeon/orbeon-forms/raw/master/src/resources/apps/xforms-sandbox/samples/howto/load-initial-form-data-pull- instance.xml ),放入“用户数据”实例,然后获取名字,并放入“ fr-form-instance”中的“ name”标记。 Unfortunately it does not working, I mean setvalue not working, because when I change 'user-instance' like that: 不幸的是,它不起作用,我的意思是setvalue不起作用,因为当我这样更改“ user-instance”时:

<xf:instance id="user-data">
    <registration>
        <first-name>SomeName</first-name>
        <last-name/>
    </registration>
</xf:instance>

it working, and the final xml look like: 它可以正常工作,最终的xml如下所示:

....
<name>SomeName</name>
....

I really haven't idea why it doesn't working. 我真的不知道为什么它不起作用。

regards 问候

/// ///

Now I see that my problem may be reduced to: 现在我看到我的问题可能简化为:

It works: 有用:

<xforms:instance id="user-data" src="http://example.org/service/load-initial-form-data-pull-instance"/>

And it does not work: 它不起作用:

<xforms:send ev:event="xforms-model-construct-done" submission="load-data-submission"/>
<xforms:submission id="load-data-submission"
               method="get" serialization="none"
               resource="http://example.org/service/load-initial-form-data-pull-instance"
               replace="instance" instance="user-data"/>

I have to use second way, because I have to pass some parameter to resource (resource="http.../{xxforms:get-request-parameter('myParam')}") 我必须使用第二种方法,因为我必须将一些参数传递给资源(resource =“ http ... / {xxforms:get-request-parameter('myParam')}”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM