【问题标题】:Need to create WSO2 DSS service which can read parameter from url需要创建可以从 url 读取参数的 WSO2 DSS 服务
【发布时间】:2014-06-12 07:31:39
【问题描述】:

我创建了一个简单的 dss 服务,它通过输入 cust_id 为我提供客户数据。

我已将此 Web 服务公开为具有以下 url 的 http get 资源 获取 /services/getCustDetailDSS/getDetail?cid=101

我的服务对应的xml代码如下

<data name="getCustomerDetailDSS" serviceGroup="" serviceNamespace="">
<description/>
<config id="mydb">
    <property name="carbon_datasource_name">mydb</property>
</config>
<query id="get_customer_detail" useConfig="mydb">
    <sql>select identifier,user_status from customer_detail where identifier = :cid</sql>
    <param name="cid" paramType="SCALAR" sqlType="STRING"/>
    <result element="customer">
        <element column="identifier" name="cid" xsdType="xs:string"/>
        <element column="user_status" name="status" xsdType="xs:string"/>
    </result>
</query>
<operation name="get_customer_detail_operation">
    <call-query href="get_customer_detail">
        <with-param name="cid" query-param="identifier"/>
    </call-query>
</operation>
<resource method="GET" path="/getDetail">
    <call-query href="get_customer_detail">
        <with-param name="cid" query-param="cid"/>
    </call-query>
</resource>
</data>

但现在我希望 dss 服务从 url 读取 cust_id 而不是将其作为参数传递。

即我想点击 dss 服务作为 获取 /services/getCustDetailDSS/cid/101/getDetail

我如何在 DSS 中做到这一点?

谁能提供我需要在我的 dss 中进行的 wat 更改?

【问题讨论】:

    标签: wso2 wso2carbon wso2dss dss


    【解决方案1】:

    对于GET /services/getCustDetailDSS/getDetail/cid/101

    您必须按如下方式编辑资源路径。

    <resource method="GET" path="getDetail/cid/{cid}">
    

    【讨论】:

    • 这不起作用......如果我在有参数 url 之后添加这个路径 n 就像 /getDetail/cid/?identifier=?如果我不添加查询参数(这是我想做的),url 就像 /getDetail/cid/。如果我在 /cid/ 之后输入 id 并尝试从 soapui 中点击它,我会收到错误 DS Code: INCOMPATIBLE_PARAMETERS_ERROR\nNested Exception:-\njavax.xml.stream.XMLStreamException: DS Fault Message: Error in 'Query.extractParams',找不到名称为:cid\nDS 的查询参数
    • 应该可以。您使用的 DSS 版本是什么?也试试这个 curl 命令。 (相应地修改 ip/port)curl -k -H "Accept: application/json" https://10.213.209.1:9483/services/getCustDetailDSS.HTTPEndpoint/getDetail/cid/101
    • 我使用的是 dss 3.2.0。我尝试了上面的 curl 命令,但得到了与我的第一条评论中描述的相同的错误。我还在这个 cmets 中添加了额外的响应 stmts。\n默认命名空间:ws.wso2.org/dataservice\n当前请求名称:_get_getstatus_cid\n当前参数:{}\n \n","详细信息":""}}
    • 如果你在你的系统中尝试过,你能把数据服务的xml代码放上去吗?
    • 我只在 DSS 3.1.1 中尝试过。我也将尝试 3.2.0 之一。 DSS 包附带了一个示例 DSS 服务 (samples/ResourcesSample)。这就是您正在寻找的样本。试试它是否适合你。
    【解决方案2】:

    使用 WSO2 DSS 3.2.1,您现在可以如下定义查询字符串参数:

    <param name="cid" sqlType="QUERY_STRING"/>
    

    代替:

    <param name="cid" paramType="SCALAR" sqlType="STRING"/>
    

    您的网址应该如下所示:

    .../getDetail?cid=101
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多