BusinessObjects 4.0 RESTful web service proxy

SAP introduced RESTful web services in its BI platform (BusinessObjects 4.0) for the first time in the latest service pack SP4. This is a first step in a good direction. The rest web services available in the platform are a bit limited yet, but indicate an important directional shift. Up to now, all we had to work with was soap. The rest web services allow developers to obtain a logon token and perform basic scheduling operations. The crystal RESTful sdk has some additional possibilities in terms of access to reports and data. I decided to take the RESTful web services for a spin, and right off the bat, ran into problems…
First of all, the services are deployed on the WACS (the web application container service), as opposed to the web server that the rest of the app runs on (typically Tomcat). So if you were planning to make a simple ajax call to the logon service to obtain a logon token, you can forget about it. Same origin policy will prevent your web client from accessing ajax content from a different host, and technically, even though you might be deploying your code on the same machine as the bo Tomcat, the WACS will run on a different port, so you are out of luck.
To work around that, i wrote a jsp proxy that connects to the logon service and displays the response xml. The trick was to get the post request to look just right for the service to accept it, but once i got that, the rest is simple. You can grab this code, put it in a webapp on the bo server, and now you can call this proxy using ajax to obtain a token and pass it to other applications that need to integrate with BO. Sweet.

<%@ page
    import="org.apache.http.HttpEntity,
  org.apache.http.HttpResponse,
  org.apache.http.client.methods.HttpPost,
  org.apache.http.impl.client.DefaultHttpClient,
  org.apache.http.util.EntityUtils,
  org.apache.http.entity.StringEntity,
  org.apache.http.client.HttpClient,
  org.apache.http.protocol.BasicHttpContext,
  org.apache.http.HttpStatus,
  java.io.*,
  java.net.*"
%>
<%@page contentType="text/xml"%>
<%@page trimDirectiveWhitespaces="true" %>
<%
//for debugging the post request, very useful...
//System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog");
//System.setProperty("org.apache.commons.logging.simplelog.showdatetime","true");
//System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http","DEBUG");
//System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire","DEBUG");
String user = "";
String pwd = "";
 StringBuffer sbf = new StringBuffer();
 String xmlString = "<attrs xmlns=\"http://www.sap.com/rws/bip\"><attr name=\"userName\" type=\"string\">"+user+"</attr><attr name=\"password\" type=\"string\">"+pwd+"</attr><attr name=\"auth\" type=\"string\" possibilities=\"secEnterprise,secLDAP,secWinAD\">secEnterprise</attr></attrs>";
 HttpPost httpRequest = new HttpPost("http://localhost:6405/biprws/logon/long");
 httpRequest.setEntity(new StringEntity(xmlString));
 httpRequest.setHeader("Content-Type","application/xml");
 httpRequest.setHeader("Accept","application/xml"); 

 HttpClient httpclient = new DefaultHttpClient();
 HttpResponse httpResponse = httpclient.execute(httpRequest, new BasicHttpContext());

 if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK && httpResponse.getEntity() != null) {
 HttpEntity ent = httpResponse.getEntity();
              BufferedReader in = new BufferedReader(new InputStreamReader(ent.getContent()));
              String inputLine;
              while ( (inputLine = in.readLine()) != null) sbf.append(inputLine);
                  in.close();
              EntityUtils.consume(ent);
 } else {
   out.println("error");
}
 %>
<%=sbf.toString() %>
This entry was posted in BusinessObjects 4.0. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>