Issues while quering LQE based reports via java
Hello Folks,
We built a simple JRS report against DataWarehouse which returns the result based on the input parameters. And then we exported the result to excel, copied the URL and queried the URL via java code and got the same results.
Example URL: https://dns.com/rs/query/2465/dataservice?limit=-1&basicAuthenticationEnabled=true&pName=ProjectIds&pName=parmVar_0&pName=parmVar_0&report=2451&pVal=201&pVal=351&pVal=422
But when we built a similar report against LQE, copied the URL from excel export, and tried querying the URL, but in this case the results are not returned. Please find the sample code:
InputStream inputXml = null;
try {
URL url = new URL(
"https://dns.com/rs/query/679/dataservice?limit=-1&basicAuthenticationEnabled=true&pName=ProjectIds&pName=parmVar_0&report=669&pVal=https%3A%2F%2Frb-alm-05-d.de.bosch.com%2Fccm%2Fprocess%2Fproject-areas%2F_HxhqwEeAEeiBQ-3nrkp-9Q&pVal=320176");
URLConnection uc = url.openConnection();
String userpass = "**" + ":" + "*";
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
uc.setRequestProperty("Authorization", basicAuth);
inputXml = uc.getInputStream();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(inputXml);
NodeList parentNod = doc.getElementsByTagName("results");
List<DBObject> documents = new ArrayList<DBObject>();
if (parentNod.getLength() > 0) {
for (int i = 0; i < parentNod.getLength(); i++) {
DBObject document1 = new BasicDBObject();
Element nodo = (Element) parentNod.item(i);
NodeList nodeList = nodo.getChildNodes();
for (int j = 0; j <= nodeList.getLength(); j++) {
Element childNodo = (Element) nodeList.item(j);
String childTagName = childNodo.getTagName();
String childTextContent = childNodo.getTextContent();
System.out.println("Tag Name: " + childTagName);
System.out.println("Tag Value: " + childTextContent);
document1.put(childTagName, childTextContent);
}
documents.add(document1);
}
System.out.println("" + documents);
}
}
catch (Exception ex) {
System.out.println(ex.getMessage());
}
finally {
try {
if (inputXml != null) {
inputXml.close();
}
}
catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
}
Guess the parsing logic is wrong, not very sure. Any help will be much appreciated.
Thanks
One answer
You need to be able to see the XML in order to write the correct parsing logic.
Open a Firefox browser tab with DW query
https://dns.com/rs/query/2465/dataservice?limit=-1&basicAuthenticationEnabled=true&pName=ProjectIds&pName=parmVar_0&pName=parmVar_0&report=2451&pVal=201&pVal=351&pVal=422
Open another firefox browser tab with the LQE query
https://dns.com/rs/query/679/dataservice?limit=-1&basicAuthenticationEnabled=true&pName=ProjectIds&pName=parmVar_0&report=669&pVal=https%3A%2F%2Frb-alm-05-d.de.bosch.com%2Fccm%2Fprocess%2Fproject-areas%2F_HxhqwEeAEeiBQ-3nrkp-9Q&pVal=320176%22);
You will see the exact XML that is being created. In my case the top level node and each result node were exactly the same namespace and hierarchy. The individual result elements of course contain different tags. Here's an excerpt of one of my LQE results.
<results>
<result>
<PROJECT_NAME>Jazz Reporting Service</PROJECT_NAME>
<REFERENCE_ID>232401</REFERENCE_ID>
<URL1_title>Provide ability to cancel scheduled operations for a data source</URL1_title>
<URL1>https://jazz.net/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/232401</URL1>
<REQUEST_STATE>New</REQUEST_STATE>
</result>
</results>