How to Store the Images into PostgreSQL using wso2esb and wso2dss - encoding

I am using wso2esb4.7.0 , wso2dss 3.0.1 and posgresql 9.1.4
In postgresql i used data type bytea and in wso2dss 3.0.1 we dont have bytea so i used binary data type while i am inserting via dss it inserting the values but selecting query is not working
In wso2esb or wso2dss has any example for this
data is saving in this format x5c78
but selection time its not showing in dss what is the issue
<query id="insert_testing_query" useConfig="default">
<sql>INSERT INTO public.testing(username,password,remoteaddress,result,img) VALUES(?,?,?,?,?)</sql>
<param name="username" ordinal="1" sqlType="STRING"/>
<param name="password" ordinal="2" sqlType="STRING"/>
<param name="remoteaddress" ordinal="3" sqlType="STRING"/>
<param name="result" ordinal="4" sqlType="STRING"/>
<param name="img" ordinal="5" sqlType="BINARY"/>
</query>
<operation name="insert_testing_operation">
<call-query href="insert_testing_query">
<with-param name="result" query-param="result"/>
<with-param name="remoteaddress" query-param="remoteaddress"/>
<with-param name="username" query-param="username"/>
<with-param name="img" query-param="img"/>
<with-param name="password" query-param="password"/>
</call-query>
</operation>

In the select query the element should be in the xs:base64 type. Please refer this doc. Here is a sample dataservices configuration for select query.
<query id="select_testing_query" useConfig="default">
<sql>SELECT username,password,remoteaddress,result,img FROM public.testing</sql>
<result element="SAMPLECollection" rowName="SAMPLE">
<element column="username" name="username" xsdType="xs:string"/>
<element column="password" name="password" xsdType="xs:string"/>
<element column="remoteaddress" name="remoteaddress" xsdType="xs:string"/>
<element column="result" name="result" xsdType="xs:string"/>
<element column="img" name="img" xsdType="xs:base64"/>
</result>
</query>
<operation name="select_testing_operation">
<call-query href="select_testing_query"/>
</operation>

Related

Rest resource error in WSO2 dataservice with procedure with out param

Hi I am creating a WSO2 data service and i am calling a stored procedure that has an out param.
{call ? :=IRIS_REST_PKG.INSERT_OR_UPDATE_STUDENT(?,?,?) }
So i can get the whole thing to work in the try it editor but when i configure the rest resource i see a list of request params which includes my out param that was earlier defined in the query.
When i call the rest service with only in params i get:
Value type miss match, Expected value type - 'null', but found - 'STRING'.
I am using version 6.4.0 of Enterprise Intergrator.
This is my dbs file:
<data name="IRIS" transports="http https local">
<config enableOData="false" id="ORACLE">
<property name="driverClassName">oracle.jdbc.driver.OracleDriver</property>
<property name="url">jdbc:oracle:thin:#ldap:...</property>
<property name="username">xxxxxxxxxxxx</property>
<property name="password">xxxxxxxxxxxx</property>
<property name="dataSourceProps"/>
<property name="dynamicUserAuthMapping">
<configuration/>
</property>
</config>
<query id="get_student" useConfig="ORACLE">
<sql>{call ?:=TEST_PKG.get_student(?)}</sql>
<result element="upi" rowName="">
<element column="upi" name="upi" xsdType="string"/>
<element column="research_summary" name="research_summary" xsdType="string"/>
</result>
<param name="result" sqlType="ORACLE_REF_CURSOR" type="OUT"/>
<param name="upi" sqlType="STRING"/>
</query>
<query id="q1" useConfig="ORACLE">
<sql>{call ?:=TEST_PKG.myfunction(?,?)}</sql>
<result element="myCount" rowName="">
<element column="myCount" name="myCount" xsdType="integer"/>
</result>
<param name="myCount" sqlType="INTEGER" type="OUT"/>
<param name="ename" sqlType="STRING"/>
<param name="eid" sqlType="INTEGER"/>
</query>
<query id="insert_or_update_student" useConfig="ORACLE">
<sql>{call ? :=IRIS_REST_PKG.INSERT_OR_UPDATE_STUDENT(?,?,?) }</sql>
<result outputType="json">{"result":{"status":"$status"}}</result>
<param defaultValue="-1" name="status" sqlType="INTEGER" type="OUT"/>
<param name="upi" sqlType="STRING"/>
<param name="summary" sqlType="STRING"/>
<param name="optIn" sqlType="INTEGER"/>
</query>
<query id="get_jstudent" useConfig="ORACLE">
<sql>SELECT UPI, RESEARCH_SUMMARY FROM xxx r WHERE r.UPI = :upi</sql>
<result outputType="json">{"result":{"upi":"$upi","research_summary":"$research_summary"}}</result>
<param name="upi" sqlType="STRING"/>
</query>
<operation name="get_student">
<call-query href="get_student">
<with-param name="upi" query-param="upi"/>
</call-query>
</operation>
<operation name="op1">
<call-query href="q1">
<with-param name="ename" query-param="ename"/>
<with-param name="eid" query-param="eid"/>
</call-query>
</operation>
<operation name="insert_or_update_student">
<call-query href="insert_or_update_student">
<with-param name="upi" query-param="upi"/>
<with-param name="summary" query-param="summary"/>
<with-param name="optIn" query-param="optIn"/>
</call-query>
</operation>
<operation name="get_jstudent">
<call-query href="get_jstudent">
<with-param name="upi" query-param="upi"/>
</call-query>
</operation>
<resource method="GET" path="r1">
<call-query href="get_student">
<with-param name="result" query-param="result"/>
<with-param name="upi" query-param="upi"/>
</call-query>
</resource>
<resource method="POST" path="insertOrUpdateStudent">
<call-query href="insert_or_update_student">
<with-param name="status" query-param="status"/>
<with-param name="upi" query-param="upi"/>
<with-param name="summary" query-param="summary"/>
<with-param name="optIn" query-param="optIn"/>
</call-query>
</resource>
<resource method="GET" path="get_jstudent/{upi}">
<call-query href="get_jstudent">
<with-param name="upi" query-param="upi"/>
</call-query>
</resource>
</data>
I am talking about: insertOrUpdateStudent resource section.
<with-param name="status" query-param="status"/>
I have also removed this line but still not working.
I also tried and pass null / 0 / "" and still not working.
Any help would be greatly appreciated.
Thank you.
The answer is that if the resource and the operation have the same name things go wrong. Also even with the above correct the wizard shows the out param as a query param, so the thing to do is to edit the xml and remove the out param from the resource parameters.

WSO2 Mongo data service dynamic query parameter

i'm trying to create a mongo data service in WSO2EI. Currently I have this query, which gives me results based on componentId:
<query id="find" useConfig="MongoDB">
<expression>collection.find("{componentId : #}")</expression>
<result outputType="json">{
"Documents": {
"Document": [
{
"Data": "$document"
}
]
}
}</result>
<param name="componentId" sqlType="STRING"/>
</query>
But I need to enter the parameter(s) dynamically to be able to .find different results based on parameter name I provided, something like this:
<query id="find" useConfig="MongoDB">
<expression>collection.find("{fieldName : #} : {fieldValue : #}")</expression>
<result outputType="json">{
"Documents": {
"Document": [
{
"Data": "$document"
}
]
}
}</result>
<param name="fieldName" sqlType="STRING"/>
<param name="fieldValue" sqlType="STRING"/>
</query>
Is this possible? Or do I have to create multiple queries for each parameter?
Thanks
Yes it's possible! Try this (work for me).
<query id="wesites_find_param" useConfig="mongo_ds">
<expression>websites.find("{#: #}")</expression>
<result element="Documents" rowName="Document" useColumnNumbers="true">
<element column="document" name="Data" xsdType="string"/>
</result>
<param defaultValue="name" name="par1" sqlType="STRING"/>
<param name="par2" sqlType="STRING"/>
</query>
<operation name="website_find_param_op">
<call-query href="wesites_find_param">
<with-param name="par1" query-param="par1"/>
<with-param name="par2" query-param="par2"/>
</call-query>
</operation>
<resource method="GET" path="/websitefind">
<call-query href="wesites_find_param">
<with-param name="par1" query-param="par1"/>
<with-param name="par2" query-param="par2"/>
</call-query>
</resource>
Example,
for componentId : "pippo" use ?par1=componentId&par2=pippo
for componentName : "proxy_hl7" use ?par1=componentName&par2=proxy_hl7

Why I am getting the WSO2 DSS Mapping issue?

I am trying to map my MongoDB with the WSO2 DSS. But the service generated is faulty and getting many errors regarding the mapping of the data.
Here is what I tried:
<data name="MongoDB" transports="http https local">
<config enableOData="false" id="mongodb">
<property name="mongoDB_servers">127.0.0.1:27017</property>
<property name="mongoDB_database">domain_with_email</property>
<property name="mongoDB_write_concern">NONE</property>
<property name="mongoDB_read_preference">PRIMARY</property>
</config>
<query id="search" useConfig="mongodb">
<expression>domainemail.find({"domain":#})</expression>
<result escapeNonPrintableChar="true" outputType="json" useColumnNumbers="true">{
"entries":
{
"id":"$_id",
"domain":"$domain",
"emails":[
 {
 "email":"$email"
 }
]
}
}</result>
<param defaultValue="yahoo.com" name="domain" sqlType="STRING"/>
</query>
<operation name="search">
<call-query href="search">
<with-param name="domain" query-param="domain"/>
</call-query>
</operation>
</data>
Here is the errors:
https://gist.github.com/JafferWilson/b4aa22c39205d61a25f2bee5b45a7607
Kindly let me know what I need to do to get a JSON output from my MongoDB using WSO2 DSS?
We're still struggling with our WSO2 + Mongo journey too. Anyhow I hope this can help. Here's our code for a working JSON service to MongoDB
<data name="MongoTestDS2" transports="http https local">
<config enableOData="false" id="MongoDS">
<property name="mongoDB_servers">xx.xx.xx.xx</property>
<property name="mongoDB_database">mydb</property>
</config>
<query id="GetTestVals" useConfig="MongoDS">
<expression>things.find()</expression>
<result element="Documents" rowName="Document" useColumnNumbers="true">
<element column="document" export="id" name="Data" xsdType="string"/>
</result>
</query>
<query id="InsertTestVals" returnUpdatedRowCount="true" useConfig="MongoDS">
<expression>things.insert("{id:#, name:#}")</expression>
<result element="UpdatedRowCount" rowName="" useColumnNumbers="true">
<element column="1" name="Value" xsdType="integer"/>
</result>
<param name="id" sqlType="STRING"/>
<param name="name" sqlType="STRING"/>
</query>
<query id="GetValsJson" useConfig="MongoDS">
<expression>things.find()</expression>
<result outputType="json">{
 "Documents": {
 "Document": [
 {
 "Data": "$document"
 }
 ]
 }
}</result>
</query>
<operation name="GetThings">
<description>Test Mongo DB 
 </description>
<call-query href="GetTestVals"/>
</operation>
<operation name="PutThings">
<call-query href="InsertTestVals">
<with-param name="id" query-param="id"/>
<with-param name="name" query-param="name"/>
</call-query>
</operation>
<operation name="GetThingsJson">
<call-query href="GetValsJson"/>
</operation>
</data>
In your case I think, it's this line you need to change:
<query id="GetValsJson" useConfig="MongoDS">
<expression>things.find()</expression>
<result outputType="json">{
 "Documents": {
 "Document": [
 {
 "Data": "$document"
 }
 ]
 }
}</result>
</query>
This returns all the fields into a string.
If this is then related to your earlier question, then I think this tutorial will help with the next step of mapping field from one service to another:
https://docs.wso2.com/display/EI611/Transforming+Message+Content
On our side, we unfortunately gave up on the mongodb adapter that comes with WSO2 and used RESTHeart to expose the mongodb as APIs (http://restheart.org/) This seems to work well as WSO2 then just consumes them as if they were any other REST API.
We'd love to hear how you get on as I'm sure we'll hit many of the same challenges in our own mongodb + WSO2 testing.

Uploading Data Service with REST when try it got "The endpoint reference (EPR) for the Operation not found"

I'm trying DSS 3.2.1 and upload to server Pais.dbs file, but when try to test the REST resource with GET to url http://www.example.org:9763/services/Pais.HTTPEndpoint/Pais got the error:
<soapenv:Reason xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Text xml:lang="en-US">The endpoint reference (EPR) for the Operation not found is /services/Pais.HTTPEndpoint/Pais and the WSA Action = null. If this EPR was previously reachable, please contact the server administrator.</soapenv:Text>
</soapenv:Reason>
Calling through SOAP works like expected.
If I construct the DBS using import the REST resources works. Its something wrong with my .dbs file or maybe a BUG with the way I constructed the .dbs file?
Pais.dbs
<data name="Pais" serviceNamespace="http://www.example.org/systemx/ds">
<config id="default">
<property name="carbon_datasource_name">SYSTEMX_DB</property>
</config>
<query id="getPaisByIdQuery" useConfig="default">
<sql>select id, codigo, nome, sigla, codigoBacen, codigoSiscomex from Pais where id=:id</sql>
<param name="id" ordinal="1" paramType="SCALAR" sqlType="INTEGER" type="IN"/>
<result element="resultado" rowName="Pais">
<element column="id" name="id" xsdType="integer"/>
<element column="codigo" name="codigo" xsdType="integer"/>
<element column="nome" name="nome" xsdType="string"/>
<element column="sigla" name="sigla" xsdType="string"/>
<element column="codigobacen" name="codigoBacen" xsdType="integer"/>
<element column="codigosiscomex" name="codigoSiscomex" xsdType="integer"/>
</result>
</query>
<query id="getAllPaisQuery" useConfig="default">
<sql>select id, codigo, nome, sigla, codigoBacen, codigoSiscomex from Pais</sql>
<result element="resultado" rowName="Pais">
<element column="id" name="id" xsdType="integer"/>
<element column="codigo" name="codigo" xsdType="integer"/>
<element column="nome" name="nome" xsdType="string"/>
<element column="sigla" name="sigla" xsdType="string"/>
<element column="codigobacen" name="codigoBacen" xsdType="integer"/>
<element column="codigosiscomex" name="codigoSiscomex" xsdType="integer"/>
</result>
</query>
<query id="updatePaisQuery" useConfig="default">
<sql>update Pais set codigo=:codigo, nome=:nome, sigla=:sigla, codigobacen=:codigoBacen, codigosiscomex=:codigoSiscomex where id=:id</sql>
<param name="id" sqlType="INTEGER"/>
<param name="codigo" sqlType="INTEGER"/>
<param name="nome" sqlType="STRING"/>
<param name="sigla" sqlType="STRING"/>
<param name="codigoBacen" sqlType="INTEGER"/>
<param name="codigoSiscomex" sqlType="INTEGER"/>
</query>
<query id="createPaisQuery" returnGeneratedKeys="true" useConfig="default">
<sql>insert into Pais (codigo, nome, sigla, codigoBacen, codigoSiscomex ) values (:codigo, :nome, :sigla, :codigoBacen, :codigoSiscomex )</sql>
<result element="resultado" rowName="Pais" useColumnNumbers="true">
<element column="1" name="id" xsdType="integer"/>
</result>
<param name="codigo" sqlType="INTEGER"/>
<param name="nome" sqlType="STRING"/>
<param name="sigla" sqlType="STRING"/>
<param name="codigoBacen" sqlType="INTEGER"/>
<param name="codigoSiscomex" sqlType="INTEGER"/>
</query>
<query id="deletePaisQuery" useConfig="default">
<sql>delete Pais where id=:id</sql>
<param name="id" ordinal="1" paramType="SCALAR" sqlType="INTEGER" type="IN"/>
</query>
<!-- SOAP -->
<operation name="getPais">
<call-query href="getPaisByIdQuery">
<with-param name="id" query-param="id"/>
</call-query>
</operation>
<operation name="getAllPais">
<call-query href="getAllPaisQuery"/>
</operation>
<operation name="insertPais">
<call-query href="createPaisQuery">
<with-param name="codigo" query-param="codigo"/>
<with-param name="nome" query-param="nome"/>
<with-param name="sigla" query-param="sigla"/>
<with-param name="codigoBacen" query-param="codigoBacen"/>
<with-param name="codigoSiscomex" query-param="codigoSiscomex"/>
</call-query>
</operation>
<operation name="updatePais">
<call-query href="updatePaisQuery">
<with-param name="id" query-param="id"/>
<with-param name="codigo" query-param="codigo"/>
<with-param name="nome" query-param="nome"/>
<with-param name="sigla" query-param="sigla"/>
<with-param name="codigoBacen" query-param="codigoBacen"/>
<with-param name="codigoSiscomex" query-param="codigoSiscomex"/>
</call-query>
</operation>
<operation name="deletePais">
<call-query href="deletePaisQuery">
<with-param name="id" query-param="id"/>
</call-query>
</operation>
<!-- REST -->
<resource method="GET" path="Pais/{id}">
<call-query href="getPaisByIdQuery">
<with-param name="id" query-param="id"/>
</call-query>
</resource>
<resource method="GET" path="Pais">
<call-query href="getAllPaisQuery"/>
</resource>
<resource method="POST" path="Pais">
<call-query href="createPaisQuery">
<with-param name="codigo" query-param="codigo"/>
<with-param name="nome" query-param="nome"/>
<with-param name="sigla" query-param="sigla"/>
<with-param name="codigoBacen" query-param="codigoBacen"/>
<with-param name="codigoSiscomex" query-param="codigoSiscomex"/>
</call-query>
</resource>
<resource method="PUT" path="Pais">
<call-query href="updatePaisQuery">
<with-param name="id" query-param="id"/>
<with-param name="codigo" query-param="codigo"/>
<with-param name="nome" query-param="nome"/>
<with-param name="sigla" query-param="sigla"/>
<with-param name="codigoBacen" query-param="codigoBacen"/>
<with-param name="codigoSiscomex" query-param="codigoSiscomex"/>
</call-query>
</resource>
<resource method="DELETE" path="Pais/{id}">
<call-query href="deletePaisQuery">
<with-param name="id" query-param="id"/>
</call-query>
</resource>
DDL for pais table
CREATE TABLE "public"."pais"
(
id int PRIMARY KEY NOT NULL,
codigo int,
nome varchar(60),
sigla varchar(3),
codigobacen int,
codigosiscomex int
)
;
CREATE UNIQUE INDEX pais_pkey ON "public"."pais"(id)
;
Please specify the resource name in simple letters. ie. "pais" instead of "Pais"

WSO2 Data Services Server REST configuration

First post to SO, hopefully, I get it right. :-)
And, new to WSO2DSS...
I'd like to configure WSO2DSS to expose REST services like, for example:
http://localhost/svcendpoint/products
http://localhost/svcendpoint/products/computer
http://localhost/svcendpoint/products/computer/disks
where each url returns a more refined list. I've set up three queries / operations / resources, but I'm not getting the expected results.
I am getting the list for the first, a Axis2 "String index out of range" exception for the second, and a list for the third.
I'm not sure if it is me, a bug, or the wrong way to do this. Any help would be appreciated.
Here is the .dbs file (I can include the exception stacktrace if it will be useful):
<data name="MyDataService">
<config id="MyDataSource">
<property name="driverClassName">oracle.jdbc.driver.OracleDriver</property>
<property name="url">jdbc:oracle:thin:xxxxxx</property>
<property name="username">xxx</property>
<property name="password">xxx</property>
</config>
<query id="MyCategoriesQuery" useConfig="MyDataSource">
<sql>select distinct CAT_NM from T_FAM_BLMBRG_DATA_DICT order by CAT_NM</sql>
<result defaultNamespace="http://test.org" element="categories" rowName="">
<element column="FLD_MNM_NM" name="FLD_MNM_NM" xsdType="string"/>
<element column="FLD_ID" name="FLD_ID" xsdType="string"/>
<element column="DATA_LIC_CAT_NM" name="DATA_LIC_CAT_NM" xsdType="string"/>
<element column="FLD_DESC_TX" name="FLD_DESC_TX" xsdType="string"/>
<element column="CAT_NM" name="CAT_NM" xsdType="string"/>
<element column="FLD_DFN_TX" name="FLD_DFN_TX" xsdType="string"/>
<element column="FLD_DATYP_NM" name="FLD_DATYP_NM" xsdType="string"/>
<element column="CRT_USER_ID" name="CRT_USER_ID" xsdType="string"/>
<element column="CRT_TS" name="CRT_TS" xsdType="string"/>
<element column="UPD_USER_ID" name="UPD_USER_ID" xsdType="string"/>
<element column="UPD_TS" name="UPD_TS" xsdType="string"/>
</result>
</query>
<query id="MyCategoryQuery" useConfig="MyDataSource">
<sql>select * from T_FAM_BLMBRG_DATA_DICT where CAT_NM = :cat</sql>
<result defaultNamespace="http://test.org" element="entries" rowName="">
<element column="FLD_MNM_NM" name="FLD_MNM_NM" xsdType="string"/>
<element column="FLD_ID" name="FLD_ID" xsdType="string"/>
<element column="DATA_LIC_CAT_NM" name="DATA_LIC_CAT_NM" xsdType="string"/>
<element column="FLD_DESC_TX" name="FLD_DESC_TX" xsdType="string"/>
<element column="CAT_NM" name="CAT_NM" xsdType="string"/>
<element column="FLD_DFN_TX" name="FLD_DFN_TX" xsdType="string"/>
<element column="FLD_DATYP_NM" name="FLD_DATYP_NM" xsdType="string"/>
<element column="CRT_USER_ID" name="CRT_USER_ID" xsdType="string"/>
<element column="CRT_TS" name="CRT_TS" xsdType="string"/>
<element column="UPD_USER_ID" name="UPD_USER_ID" xsdType="string"/>
<element column="UPD_TS" name="UPD_TS" xsdType="string"/>
</result>
<param name="cat" sqlType="STRING"/>
</query>
<query id="MyCategoryFldQuery" useConfig="MyDataSource">
<sql>select * from T_FAM_BLMBRG_DATA_DICT where CAT_NM = :cat and FLD_ID = :fld</sql>
<result defaultNamespace="http://test.org" element="names" rowName="">
<element column="FLD_MNM_NM" name="FLD_MNM_NM" xsdType="string"/>
<element column="FLD_ID" name="FLD_ID" xsdType="string"/>
<element column="DATA_LIC_CAT_NM" name="DATA_LIC_CAT_NM" xsdType="string"/>
<element column="FLD_DESC_TX" name="FLD_DESC_TX" xsdType="string"/>
<element column="CAT_NM" name="CAT_NM" xsdType="string"/>
<element column="FLD_DFN_TX" name="FLD_DFN_TX" xsdType="string"/>
<element column="FLD_DATYP_NM" name="FLD_DATYP_NM" xsdType="string"/>
<element column="CRT_USER_ID" name="CRT_USER_ID" xsdType="string"/>
<element column="CRT_TS" name="CRT_TS" xsdType="string"/>
<element column="UPD_USER_ID" name="UPD_USER_ID" xsdType="string"/>
<element column="UPD_TS" name="UPD_TS" xsdType="string"/>
</result>
<param name="cat" sqlType="STRING"/>
<param name="fld" sqlType="STRING"/>
</query>
<operation name="MyCategoriesService">
<call-query href="MyCategoriesQuery"/>
</operation>
<operation name="MyCategoryService">
<call-query href="MyCategoryQuery">
<with-param name="cat" query-param="cat"/>
</call-query>
</operation>
<operation name="MyCategoryFldService">
<call-query href="MyCategoryFldQuery">
<with-param name="cat" query-param="cat"/>
<with-param name="fld" query-param="fld"/>
</call-query>
</operation>
<resource method="GET" path="category">
<call-query href="MyCategoriesQuery"/>
</resource>
<resource method="GET" path="category/{cat}">
<call-query href="MyCategoryQuery">
<with-param name="cat" query-param="cat"/>
</call-query>
</resource>
<resource method="GET" path="category/{cat}/{fld}">
<call-query href="MyCategoryFldQuery">
<with-param name="cat" query-param="cat"/>
<with-param name="fld" query-param="fld"/>
</call-query>
</resource>
</data>
You need to invoke the service as shown below
http://localhost:9763/services/SERVIVENAME.HTTPEndpoint/RESOURCEPATH/
For example
http://localhost:9763/services/MyDataSource.HTTPEndpoint/category/computer
Please refer [1] for more details
https://docs.wso2.org/display/DSS310/Exposing+Data+as+REST-Style+Resources