Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello
I am trying to develop a Job that exposes a rest end point and this end point tales in two parameters:
I want to use these parameters later on in the flow to restrict a SQL Statement.
I have defined a 'tRESTrequest' and have added a API Mapping with a URI Pattern of "/{areaCode}/{groupNumber}/". In the Output Flow I have defined the two parameters.
When I execute this, I pass the two parameters
However the two parameters are evaluated to null. I have put a Java component to debug the the Request Object and it confirms that they are null.
The tJavaRow Component code is:
System.out.println("Area Code : "+globalMap.get("groupCode.areaCode")); System.out.println("Group Number: "+globalMap.get("groupCode.groupNumber")); //The object with the key "restRequest" is a HashMap java.util.Map<String, Object> myMap = ((java.util.Map<String, Object>)globalMap.get("restRequest")); //Print out of what you are seeing already System.out.println("MyMap = " +myMap.toString()); //Create an iterator over the keyset java.util.Iterator<String> it = myMap.keySet().iterator(); //Iterate over the keyset and print out the keys while(it.hasNext()){ System.out.println(it.next()); } //Retrieve the PARAMS HashMap java.util.Map<String, Object> myParams = ((java.util.Map<String, Object>)myMap.get("PARAMS")); //Create an Iterator for the PARAMS HashMap java.util.Iterator<String> it2 = myParams.keySet().iterator(); //Iterate over the PARAMS HasMap while(it2.hasNext()){ System.out.println(it2.next()); }
The output is:
Am I missing some config ?
Any Ideas
Thanks
Patrice
Okay I think I resolved it, when referencing REST Inbound parameters, you do NOT need to use the 'globalMap.get'.
You just refer directly...
FROM WalkDetails "+
"WHERE WalkDetails.Group_Code = '"+groupCode.areaCode+groupCode.groupNumber+"'"
This worked...
Anyway...I have another question.
I want to add a check after the SQL Query and count number of rows returned, if 0 then I want the REST Response to return a custom message saying "Now rows found etc"
Is this possible...
The AreaCode and GroupNumber are not stored in the globalMap. They are columns in the row from your tRESTRequest component.
I assume you are using globalMap.get("groupCode.areaCode")) and globalMap.get("groupCode.groupNumber")) in your query which is returning nothing. You can fix this by adding the following code to the very top of your tJavaRow....
globalMap.put("groupCode.areaCode",groupCode.areaCode);
globalMap.put("groupCode.groupNumber",groupCode.groupNumber);
Of course, a better way to resolve this is to remove the tJavaRow and use the globalMap variables automatically created by the tFlowToIterate. They will have the keys.....
"row3.areaCode"
"row3.groupNumber"
Thanks Richard.
That is exactly how I had it originally. I only added the tJavaRow in order to debug the inbound parameters.
So I now deactivate the Java Component and rewire the flow...
So when I run the flow and pass : http://localhost:8088/walkDetails/ES/50/
As you can see the SQLInput component returns 0 rows..
The SQL Statement in the 'GetWalkDetails_GroupCode' component looks like this:
"SELECT WalkDetails.WalkID, WalkDetails.D_grade, WalkDetails.D_strand, WalkDetails.D_event, WalkDetails.D_festival, WalkDetails.D_restriction, WalkDetails.Title, WalkDetails.Summary, WalkDetails.Group_Code, WalkDetails.WalkDescription, WalkDetails.Date, WalkDetails.Distance_KM, WalkDetails.Distance_Miles, WalkDetails.Grade_Local, WalkDetails.Linear_Ind, WalkDetails.Time, WalkDetails.GridRef, WalkDetails.Easting, WalkDetails.Northing, WalkDetails.Latitude, WalkDetails.Longitude, WalkDetails.Postcode, WalkDetails.StartingPointDescription, WalkDetails.Display_Ind, WalkDetails.Postcode_Latitude, WalkDetails.Postcode_Logitude, WalkDetails.CreationSource, WalkDetails.CreationDate, WalkDetails.MaintenanceSource, WalkDetails.MaintenanceDate FROM WalkDetails "+ "WHERE WalkDetails.Group_Code = '"+globalMap.get("groupCode.areaCode")+globalMap.get("groupCode.groupNumber")+"'"
This should return some rows, because if I were to change the SQL and hard code the values that I pass via the URL, the SQL returns rows
WalkDetails.MaintenanceSource, WalkDetails.MaintenanceDate FROM WalkDetails "+ "WHERE WalkDetails.Group_Code = 'ES50'"
and run the flow...
Let me know
Thanks for your help so far...
Also I have tried, casting the globalMap return object to String before concatenating it...
"WHERE WalkDetails.Group_Code = '"+((String)globalMap.get("groupCode.areaCode"))+((String)globalMap.get("groupCode.groupNumber"))+"'"
this also did not work....
Have you tried printing....
((String)globalMap.get("groupCode.areaCode"))+((String)globalMap.get("groupCode.groupNumber"))
...to the System.out? Are you SURE it will produce a value that will return records?
Okay so I have simplified it and just add one parameter and just for a minute lets forget the SQL...All I want is to pass a parameter and have the flow acknowledge the receipt of that parameter and print the value that I passed....
I have added a Java Component to print the value of this parameter..
when I run this...
the output shows that the values in the parameters are null.
I have added the 'query' in the comment field in the schema...the screen shot shows it.
I tried these ...
http://localhost:8088/walkDetails?areaCode=ES50
http://localhost:8088/walkDetails?param=ES50
http://localhost:8088/walkDetails/areaCode=ES50
none of them picks up the value of 'ES50' and passes it to the REST...