cancel
Showing results for 
Search instead for 
Did you mean: 

create webi report based on unx with Restful WS SDK

Former Member
0 Kudos

Hi, all

     I write the java code to create the simple webi report based on unx with Restful WS SDK, but fail.

     The error message in BO Servier's log is  the below

  

webiserver_SAPVM.WebIntelligenceProcessingServer_trace.000009.glf

kctRequestProc.cpp:777:void __cdecl cdztools::RequestProcBasic::generateResult(class OBFixSeq<unsigned char> *&,const char *,const char *,const char *,const unsigned char *,const unsigned char *,class std::basic_istream<char,struct std::char_traits<char> > *,int,bool &): TraceLog message 700

|01430d10-5a66-86b4-d939-4136a76f3b06|2015 01 30 00:33:42:598|+0800|Error| |>>|E| |webiserver_SAPVM.WebIntelligenceProcessingServer| 8896|10072|| |1|0|1|0|Webi SDK.CorbaServerImpl.doProcess()|SAPVM:14824:5746.19374:4|Webi SDK.CorbaServerImpl.doProcess()|SAPVM:14824:5746.19374:4|webiserver_SAPVM.WebIntelligenceProcessingServer.processVariable|localhost:8896:10072.20988:1|CgAZU7RaWUGDr1V9d60Aoaw2176|||||||||||**ERROR:RequestProc:user: Administrator, doc: "eFashioin_IQ_Auto", error stream: <ERRORS>

<ERROR COMPONENT="WIS" ERRORCODE="10006" ERRORTYPE="USER" LENGTH="4" MESSAGE="The object &apos;[YR]&apos;  at position 1 does not exist in the report.  (IES 10006)" POSITION="1" PREFIX="ERR">

<DEBUGINFO/>

<REASON MODULE="C3QE">

<CONTENT>

</CONTENT>

</REASON>

</ERROR>

</ERRORS>

[kctRequestProc.cpp;777]

The error message in console is  the below

The output is in console

http://192.168.72.145:6405/biprws/logon/long/

http://192.168.72.145:6405/biprws/raylight/v1/documents

http://192.168.72.145:6405/biprws/raylight/v1/documents/23633/dataproviders

http://192.168.72.145:6405/biprws/raylight/v1/documents/23633/dataproviders/DP0/specification

http://192.168.72.145:6405/biprws/raylight/v1/documents/23633/reports/1/elements

http://192.168.72.145:6405/biprws/raylight/v1/documents/23633/reports/1/elements/8/axes/1/expression...

Exception in thread "main" java.lang.RuntimeException: Failed : HTTP error code : 400

  at com.sap.oem.restfulws.test.CreateWebiReport.postAndPutContentJson(CreateWebiReport.java:287)

  at com.sap.oem.restfulws.test.CreateWebiReport.putXmlContentJson(CreateWebiReport.java:260)

  at com.sap.oem.restfulws.test.CreateWebiReport.updateExpressionInAxis(CreateWebiReport.java:178)

  at com.sap.oem.restfulws.test.CreateWebiReport.main(CreateWebiReport.java:56)

The java source code is

Java Source code

package com.sap.oem.restfulws.test;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

import java.net.HttpURLConnection;

import java.net.URL;

import java.text.ParseException;

import org.json.JSONException;

import org.json.JSONObject;

public class CreateWebiReport {

  /** CMS System */

  private static final String CMS_LOG_HOST = "192.168.72.145:6405";

  /** User name used to log in to the CMS */

  private static final String CMS_LOG_USER = "Administrator";

  /** User password */

  private static final String CMS_LOG_PASS = "SAPoem123";

  /** Authentication mode used to log in to the CMS. Here: Enterprise */

  private static final String CMS_AUTH_MODE = "secEnterprise";

  private static final String WEBI_URL = "/biprws/raylight/v1";

  private String logonToken;

  private boolean isLogon = false;

  private String folderID = "7882";

  private String fileName = "eFashioin_IQ_Auto";

  private String documentID = "23547";

  private String reportID = "1";

  private String dataSourceID = "21576";

  private String dataProviderID = "DP0";

  private String elementID = "8";

  private String elementParentID = "2";

  private String elementName = "Block 1";

  private String axisID = "1";

  public static void main(String[] args) throws JSONException,

  ParseException, IOException {

  CreateWebiReport webiRep = new CreateWebiReport();

  JSONObject json = null;

  String resultStr = null;

  webiRep.getLogonToken();

  json = webiRep.createDoc();

  json = webiRep.addDataSourceInReport();

  json = webiRep.addTableInReport();

  json = webiRep.updateExpressionInAxis();

  webiRep.saveDocument();

  System.out.println(resultStr);

  if (json != null) {

  System.out.println(json.toString());

  }

  }

  public JSONObject createDoc() throws IOException, ParseException,

  JSONException {

  String body = "<document>" + "<name>" + this.fileName + "</name>"

  + "<folderId>" + this.folderID + "</folderId>" + "</document>";

  JSONObject json = postContentJson("http://" + CMS_LOG_HOST + WEBI_URL

  + "/documents", body);

  this.documentID = json.getJSONObject("success").getString("id");

  return json;

  //

  }

  public JSONObject saveDocument() throws IOException, ParseException,

  JSONException {

  String urlStr = "http://" + CMS_LOG_HOST + WEBI_URL + "/documents/"

  + this.documentID;

  String body = "<document>" + "    <name>" + this.fileName + "</name>"

  + "    <folderId>" + this.folderID + "</folderId>"

  + "</document>";

  // System.out.println(urlStr);

  JSONObject json = postContentJson(urlStr, body);

  return json;

  }

  public JSONObject addDataSourceInReport() throws IOException,

  ParseException, JSONException {

  String urlStr = "http://" + CMS_LOG_HOST + WEBI_URL + "/documents/"

  + this.documentID + "/dataproviders";

  String body = "<dataprovider>" + "<name>Query 1</name>"

  + "<dataSourceId>" + this.dataSourceID + "</dataSourceId>"

  + "<dataSourceType>unx</dataSourceType>" + "</dataprovider>";

  JSONObject json = postContentJson(urlStr, body);

  this.dataProviderID = json.getJSONObject("success").getString("id");

  json = addQueryInDataProvider();

  return json;

  }

  public JSONObject addTableInReport() throws IOException, ParseException,

  JSONException {

  String urlStr = "http://" + CMS_LOG_HOST + WEBI_URL + "/documents/"

  + this.documentID + "/reports/" + this.reportID + "/elements";

  String body = "<element type=\"VTable\">"

  + "    <reference>1.B</reference>" + "    <name>"

  + this.elementName

  + "</name>"

  + "    <parentId>"

  + this.elementParentID

  + "</parentId>"

  + "    <position newVerticalPage=\"false\" oneVerticalPage=\"false\" repeatOnEveryVerticalPage=\"false\" newHorizontalPage=\"false\" oneHorizontalPage=\"false\" verticalAnchorId=\"4\" verticalAnchorType=\"End\" horizontalAnchorType=\"None\" y=\"900.0\" x=\"450.0\"/>"

  + "    <hide always=\"false\"/>"

  + "    <style>"

  + "        <border>"

  + "            <top style=\"None\" rgb=\"#000000\" thickness=\"None\"/>"

  + "            <bottom style=\"None\" rgb=\"#000000\" thickness=\"None\"/>"

  + "            <left style=\"None\" rgb=\"#000000\" thickness=\"None\"/>"

  + "            <right style=\"None\" rgb=\"#000000\" thickness=\"None\"/>"

  + "        </border>"

  + "        <background height=\"0.0\" width=\"0.0\"/>"

  + "        <alternateColor rgb=\"#f8fbfc\" frequency=\"2\"/>"

  + "    </style>"

  + "    <content>"

  + "        <axes duplicateRowAggregation=\"true\">"

  + "            <axis role=\"Column\">"

  + "                <id>1</id>"

  + "                <expressions>"

  // + "                    <formula dataObjectId=\""

  // + this.dataProviderID

  // + ".YR"

  // + "\" dataType=\"String\">=[YR]"

  // + "</formula>"

  // + "                    <formula dataObjectId=\""

  // + this.dataProviderID

  // + ".QUANTITY_SOLD"

  // + "\" dataType=\"Numeric\">"

  // + "=[QUANTITY SOLD]"

  // + "</formula>"

  + "                </expressions>"

  + "            </axis>"

  + "        </axes>"

  + "        <layout>"

  + "            <zone verticalType=\"Body\" horizontalType=\"Body\">"

  + "                <child columnSpan=\"1\" column=\"0\" rowSpan=\"1\" row=\"0\" id=\"5\"/>"

  + "                <child columnSpan=\"1\" column=\"1\" rowSpan=\"1\" row=\"0\" id=\"6\"/>"

  + "            </zone>"

  + "            <zone verticalType=\"Header\" horizontalType=\"Body\">"

  + "                <child columnSpan=\"1\" column=\"0\" rowSpan=\"1\" row=\"0\" id=\"8\"/>"

  + "                <child columnSpan=\"1\" column=\"1\" rowSpan=\"1\" row=\"0\" id=\"9\"/>"

  + "            </zone>"

  + "        </layout>"

  + "    </content>" + "</element>";

  JSONObject json = postContentJson(urlStr, body);

  this.elementID = json.getJSONObject("success").getString("id");

  return json;

  }

  public JSONObject updateExpressionInAxis() throws IOException,

  ParseException, JSONException {

  String urlStr = "http://" + CMS_LOG_HOST + WEBI_URL + "/documents/"

  + this.documentID + "/reports/" + this.reportID + "/elements/"

  + this.elementID + "/axes/" + this.axisID + "/expressions";

  // int i = 0;

  String body = "<expressions>"

  + "    <formula  dataType=\"String\">=[YR]</formula>"

  + "    <formula  dataType=\"Numeric\">=[QUANTITY SOLD]</formula>"

  + "</expressions>";

  JSONObject json = putXmlContentJson(urlStr, body);

  return json;

  }

  public JSONObject addQueryInDataProvider() throws IOException,

  ParseException, JSONException {

  String urlStr = "http://" + CMS_LOG_HOST + WEBI_URL + "/documents/"

  + this.documentID + "/dataproviders/" + this.dataProviderID

  + "/specification";

  // int i = 0;

  String body = "<queryspec:QuerySpec xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""

  + "    xmlns:queryspec=\"http://com.sap.sl.queryspec\" dataProviderId=\""

  + this.dataProviderID

  + "\">"

  + "  <queryParameters>"

  + "    <duplicatedRowsProperty activated=\"true\" value=\"true\"/>"

  + "    <maxRetrievalTimeInSecondsProperty value=\"0\"/>"

  + "    <maxRowsRetrievedProperty value=\"0\"/>"

  + "    <removeEmptyRowsProperty activated=\"true\" value=\"true\"/>"

  + "    <allowOtherUserToEditQueryProperty activated=\"true\" value=\"true\"/>"

  + "    <resetContextOnRefreshProperty activated=\"true\" value=\"true\"/>"

  + "    <stripQueryProperty/>"

  + "    <useBexQueryDefaultValue activated=\"true\" value=\"true\"/>"

  + "  </queryParameters>"

  + "  <queriesTree xsi:type=\"queryspec:QueryDataNode\">"

  + "    <bOQuery name=\"Query\" identifier=\"_"

  + this.documentID

  + "_"

  + this.dataProviderID

  + "_"

  + "query\">"

  + "      <resultObjects identifier=\""

  + this.dataProviderID

  + ".YR"

  + "\" name=\"YR\"/>"

  + "      <resultObjects identifier=\""

  + this.dataProviderID

  + ".QUANTITY_SOLD"

  + "\" name=\"QUANTITY SOLD\"/>"

  + "      <conditionPart/>"

  + "    </bOQuery>"

  + "  </queriesTree>" + "</queryspec:QuerySpec>";

  JSONObject json = putTextContentJson(urlStr, body);

  return json;

  }

  public String getLogonToken() throws ParseException, IOException,

  JSONException {

  String body = "<attrs xmlns=\"http://www.sap.com/rws/bip\">"

  + "<attr name=\"userName\" type=\"string\">"

  + CMS_LOG_USER

  + "</attr>"

  + "<attr name=\"password\" type=\"string\">"

  + CMS_LOG_PASS

  + "</attr>"

  + "<attr name=\"auth\" type=\"string\" possibilities=\"secEnterprise,secLDAP,secWinAD\">"

  + CMS_AUTH_MODE + "</attr>" + "</attrs>";

  JSONObject json = postContentJson("http://" + CMS_LOG_HOST

  + "/biprws/logon/long/", body);

  logonToken = (String) json.get("logonToken");

  isLogon = true;

  return logonToken;

  }

  private JSONObject postContentJson(String urlStr, String body)

  throws IOException, JSONException {

  return postAndPutContentJson(urlStr, body, "POST",

  "application/xml; charset=utf-8");

  }

  private JSONObject putTextContentJson(String urlStr, String body)

  throws IOException, JSONException {

  return postAndPutContentJson(urlStr, body, "PUT",

  "text/xml; charset=utf-8");

  }

  private JSONObject putXmlContentJson(String urlStr, String body)

  throws IOException, JSONException {

  return postAndPutContentJson(urlStr, body, "PUT",

  "application/xml; charset=utf-8");

  }

  private JSONObject postAndPutContentJson(String urlStr, String body,

  String method, String contentType) throws IOException,

  JSONException {

  System.out.println(urlStr);

  URL url = new URL(urlStr);

  HttpURLConnection conn = (HttpURLConnection) url.openConnection();

  conn.setRequestMethod(method);

  if (this.isLogon) {

  conn.setRequestProperty("X-SAP-LogonToken", "\"" + logonToken

  + "\"");

  }

  conn.setRequestProperty("Accept", "application/json");

  conn.setRequestProperty("Content-Type", contentType);

  conn.setDoInput(true);

  conn.setDoOutput(true);

  int len = body.length();

  conn.setRequestProperty("Content-Length", Integer.toString(len));

  conn.connect();

  OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());

  out.write(body, 0, len);

  out.flush();

  if (conn.getResponseCode() != 200) {

  throw new RuntimeException("Failed : HTTP error code : "

  + conn.getResponseCode());

  }

  BufferedReader br = new BufferedReader(new InputStreamReader((conn

  .getInputStream())));

  String jsontxt = br.readLine();

  br.close();

  conn.disconnect();

  JSONObject json = new JSONObject(jsontxt);

  return json;

  }

}

Can you help me .

Accepted Solutions (0)

Answers (1)

Answers (1)

daniel_paulsen
Active Contributor
0 Kudos

For a starting point, try commenting out:

json = webiRep.updateExpressionInAxis();

and then when the report is saved into the CMS, open Launchpad and try adding the same expression into the Vtable and see if it will allow you or if the syntax needs to be different for [YR]

do you get the same issue for [QUANTITY SOLD] if you comment out the first formula expression?

Former Member
0 Kudos

I find the root cause.

I need the refresh document firstly after add data provider.

The correct flow should be :

1. Login to the CMS repository using POST <bipURL>/Logon/Long to get the logon token.

2. Retrieve the document folder ID using GET <bipURL>/infostore/cuid_{cuid}.

3. Create a Web Intelligence document using POST <webiURL>/documents.

4. Create a report for the document using POST <webiURL>/documents/{documentId}/reports.

5. Choose a universe by adding a data provider to the document using POST <webiURL>/documents/{documentId}/dataproviders.

6. To create your query, add a query specification based on the data provider of the document using POST

<webiURL>/documents/{documentId}/dataproviders/{dataProviderId}/specification.

7. Run your query to get the document data using PUT <webiURL>/documents/{documentId}/parameters.

8. To format your report, add the report structure using PUT <webiURL>/documents/{documentId}/reports/{reportId}/specification.

9. Refresh the document using PUT <webiURL>/documents/{documentId}/parameters.

10. Save the document using PUT <webiURL>/documents/{documentId}.

former_member197386
Active Contributor
0 Kudos

Hey Kevin,

Great stuff

To quickly fix this kind of error, check the error message sent back by our RESTful API. Most of the time, they will tell you exactly what is going wrong.

Enjoy!

Best regards,

Anthony