Oracle Service Bus 12c - How to pass Array Data type in Java Callout - oracle12c

I've created a java class that has an argument of String[] Data type but couldn't figure out how to pass an array. What i've tried is putting the array inside single quotes but when I run the Proxy Service, it returns null.
Request Arguments:
java.lang.String = 'EDGF.FMW_SELECT_TABLE_NAME'
java.lang.String[] = '{"jdbc:oracle:thin:#IP:PORT:SID", "User", "Password"}'
java.lang.String[] = '{$body/oraf:Order/oraf:var1,$body/oraf:Order/oraf:var2}'
The way I set the output is like this in response
<oraf:queryResult>{data($resultSetTable)}</oraf:queryResult>
I've tried running the Java Class with the same arguments and it returns a result.
Result from Running Java Class:
, 49451234, , , 2019-02-13 00:00:00.0, , 12341234, , null,
Response from Running Proxy Service
<soapenv:Body>
<oraf:queryResult xmlns:oraf="http://xmlns.oracle.com/db/SPName"/>
</soapenv:Body>

To put array into JavaCallout you can use fn:tokenize function for example:
create $variable ealier for example by using assign ("var1,var2,var3") then into your argument paste below line:
fn:tokenize($variable,',')

I agree to use fn:tokenize(). However, in the OSB environment (12c IntegratedWeblogicServer) on my WindowsOS, I could not use an OSB variable to pass the resulting array (in fact: Xquery sequence) to the JavaCallout. It started working for me when I placed the fn:tokenize() in the input arguments-expression of the JavaCallout itself.

Related

how to use json_extract_path_text?

I am facing an issue with JSON extract using JSON_EXTRACT_PATH_TEXT in redshift
I have two separate JSON columns
One containing the modems the customer is using and the other one containing the recharge details
{"Mnfcr": "Technicolor","Model_Name":"Technicolor ABC1243","Smart_Modem":"Y"}
For the above, I have no issue extracting the Model_name using JSON_EXTRACT_PATH_TEXT(COLUMN_NAME, 'Model_Name') as model_name
[{"Date":"2021-12-24 21:42:01","Amt":50.00}]
This one is causing me trouble. I used the same method above and it did not work. it gave me the below error
ERROR: JSON parsing error Detail: ----------------------------------------------- error: JSON parsing error code: 8001 context: invalid json object [{"Date":"2021-07-03 17:12:16","Amt":50.00
Can I please get assistance on how to extract this using the json_extract_path_text?
One other method I have found and it worked was to use regexp_substring.
This second string is a json array (square braces), not an object (curly brackets). The array contains a single element which is an object. So you need to extract the object from the array before using JSON_EXTRACT_PATH_TEXT().
The junction for this is JSON_EXTRACT_ARRAY_ELEMENT_TEXT().
Putting this all together we get:
JSON_EXTRACT_PATH_TEXT(
JSON_EXTRACT_ARRAY_ELEMENT_TEXT( <column>, 0)
, 'Amt')
you can use json_extract_path_text like below example
json_extract_path_text(json_columnName, json_keyName) = compareValue
for more you can refer this article
https://docs.aws.amazon.com/redshift/latest/dg/JSON_EXTRACT_PATH_TEXT.html

avoid $( expansion in Qliksense

I have rest api which decrypts the token passed to it and returns the actual value.
The token can sometime contains $( values and hence this is causing issues in the post call to the api
[dbtable]:
SELECT X
FROM "table" WHERE key='1234';
Let v_C= Peek('X',0,'dbtable');
//create the json request
Let vRequestBody='[';
Let vRequestBody = vRequestBody&'{"troup":"CB","tt":"CBA","tk":"$(v_C)"}';
Let vRequestBody = vRequestBody&']';
LIB CONNECT TO 'postapi';
RestConnectorMasterTable:
SQL SELECT
"data"
FROM JSON (wrap on) "root"
WITH CONNECTION (BODY "$(vRequestBody)" );
its working for rest of the values. But for values with "$(" the value of v_C turns NULL due to $ expansion. is there a way where I can avoid $ expansion and pass the value as it is to the body of the api call in qlik sense
Yes, this is quite common with APIs where they can have ways they want things passing that "confuse" Qlik Sense's parser. Generally the way around it is to put in a placeholder and then replace that with the real value later or use a chr() command to get the character you want. I think the latter should work in this situation:
Let vRequestBody = vRequestBody&'{"troup":"CB","tt":"CBA","tk":"' & chr(36) & '(v_C)"}';
Hope that works.

How to pass context parameter to Query parameters value in Talend

In Talend studio, i am creating a job which involves supplying URL and query parameters to 'tRest_Client' component and facing below stated issue -
I am trying to pass context parameter data to Query parameter value as below
Context parameter -
Name : mis_id
Default : 10
Query Paramaters -
name : "query"
value : {target-rel[=context.mis_id]}
actual URL -
URL+query={target-rel[=10]}
Here i am trying to pass value 10 with 'context.mis_id'
When i run the talend job, no data is passed to the Value of Query Parameter.
Please let me know if this is correct way to pass Context parameter data.
If you need to include the context variable in a query parameter, then try remember how Java works with a static string and a variable, since talend is a Java based tool.
Say in Java, I have a variable,
String world = "World!!!";
System.out.Println("Hello "+world); // This will display as Hello World!!!
Likewise, in talend you have to use as
"{target-rel[="+context.mis_id+"]}"
Hope this would help you out.

Using [array] in a class based DSC resource

I have been creating a few class based custom DSC resources and I am running into the following issue:
Whenever I try to use an array as input for my resource, I get an error.
For example
DscProperty(Mandatory)]
[array]$Products
Would result in the following error when I try to create a MOF file using my resource:
Write-NodeMOFFile : Invalid MOF definition for node 'nodename':
Exceptioncalling "ValidateInstanceText" with "1" argument(s):
"Convert property 'Products' value from type 'STRING[]' to type 'INSTANCE' failed.
The input object for $Products would be (for example):
$Products = #("Windows server 2012", "Windows SQL Server", "Windows 8.1")
I honestly have no idea why the Write-NodeMOFFile function would try to convert the array (it should not need converting, right?) and even if it needed to be converted - why would it convert an array from STRING[] to INSTANCE?
Anyone has a clue as to why this happens?
The only way I got it to work was by creating a long string from my array of strings and then seperating them within the resource.
declare array like this :
[string[]]$product="ddd","dq","dqq"

DbContext.Database.SqlQuery<T>(query, parameters) parameter with value 0 sent as "default" to the database

I have a code like this:
const string query = "select count(*) from query with parameters"
+ "#param1, #param2..."
(Obvioulsy is pseudocode). When I run the query like this:
ctx.Database.SqlQuery<int>(query,
new SqlParameter("param1", idAsociacion),
new SqlParameter("param2", 0));
I get an exception stating that I didn't provide a value for param2.
If I use SQl Server Profiles I see that the generated query looks like this:
exec sp_executesql N'The query', #param1=N'P', #param2=default
If I try to run it directly in SQL Server I do also get the error that param2 is required and not provided (I don't know the exact error in English, because I have a localized SQL Server).
Why is EF converting the value 0 into default?
The problem was a silly one.
When I put the mouse pointer over this constructor invocation in VS:
new SqlParameter("param2", 0)
I see that the SqlParameter overload being invoked is not this one:
SqlParameter(string, object)
but this one
SqlParameter(string, SqlDbType)
So, the simple solution is to invoke the constructor casting the value to object, like this:
new SqlParameter("param2", (object)0)
so the correct overload is invoked, and it works as expected.