1

I have created a simple dss service which by inputing cust_id it gives me the customer data.

I have exposed this webservice as http get resource with the following url GET /services/getCustDetailDSS/getDetail?cid=101

Corrsponding xml code for my service is as follows

<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>

But now i want the dss service to read cust_id from url instead of passing it as a parameter.

i.e i want to hit dss service as GET /services/getCustDetailDSS/cid/101/getDetail

How can i do this in DSS ?

Can anyone provide wat changes i need to do in my dss?

mihir S
  • 617
  • 3
  • 8
  • 23

2 Answers2

3

For GET /services/getCustDetailDSS/getDetail/cid/101

You have to edit your resource path as follows.

<resource method="GET" path="getDetail/cid/{cid}">
Bee
  • 12,251
  • 11
  • 46
  • 73
  • this is not working...bcoz if i add this path n after if there is parameter url is like /getDetail/cid/?identifier=? and if i dont add query param (which is i want to do) url is like /getDetail/cid/. and if i enter id after /cid/ and try to hit it from soapui i get the error DS Code: INCOMPATIBLE_PARAMETERS_ERROR\nNested Exception:-\njavax.xml.stream.XMLStreamException: DS Fault Message: Error in 'Query.extractParams', cannot find query param with name:cid\nDS – mihir S Jun 13 '14 at 07:28
  • That should be working. What is the DSS version you are using? Try this curl command too. (modify ip/port accordingly) `curl -k -H "Accept: application/json" https://10.213.209.1:9483/services/getCustDetailDSS.HTTPEndpoint/getDetail/cid/101` – Bee Jun 13 '14 at 16:36
  • i m using dss 3.2.0. I tried the above curl command but getting the same error as described in my first comment.Also i m adding additional response stmts in this comments.. \nDefault Namespace: http://ws.wso2.org/dataservice\nCurrent Request Name: _get_getstatus_cid\nCurrent Params: {}\n\n","Detail":""}} – mihir S Jun 16 '14 at 07:26
  • Can u put the xml code of data service if u have tried in your system? – mihir S Jun 16 '14 at 07:30
  • I tried in DSS 3.1.1 only. I will try on 3.2.0 one too. There is a sample DSS service (samples/ResourcesSample) which comes with DSS pack. That is the sample for what you are looking for. Try if it works for you. – Bee Jun 16 '14 at 22:27
  • I tried in 3.2.1 and it works fine when `Accept: application/xml`. But I get a different exception when `Accept: application/json`. I will send and email to dev list and reply back once I get a response. Meanwhile you can try with `Accept: application/xml` – Bee Jun 16 '14 at 23:42
  • i'm still getting incompatible parameters error with xml accept header..looks like i'm making some mistake while creating dss service.i m posting the xml of my resource part of service in next comment...can u check and tell me whether it is correct or not... – mihir S Jun 17 '14 at 05:54
  • You need `` part too. Try removing starting slash in path too. `path="getDetail/{cid}"` – Bee Jun 17 '14 at 06:00
  • yah it worked...thanks alot bhathiya for all your help...previuosly wen i added parameter with resource it was not working..i guess i myt have made some mistake...now after adding paramters with resource it is wroking perfectly fine..thanks a lot – mihir S Jun 17 '14 at 06:25
  • Also Accept:application/json is also working in mine. – mihir S Jun 17 '14 at 06:26
  • Good to hear that... :) – Bee Jun 17 '14 at 06:27
  • i am looking for this, but what if i have 2 params or more with nullable value? – irvana Oct 29 '15 at 07:09
0

With WSO2 DSS 3.2.1, you can now define your query string parameter as below:

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

instead of:

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

and your URL should look like:

.../getDetail?cid=101
john smith
  • 536
  • 4
  • 11