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
<%@page contentType="text/xml"%>
<%@page trimDirectiveWhitespaces="true" %>
//for debugging the post request, very useful...
String user = "";
String pwd = "";
 StringBuffer sbf = new StringBuffer();
 String xmlString = "<attrs xmlns=\"\"><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));

 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);
 } else {
<%=sbf.toString() %>
This entry was posted in BusinessObjects 4.0. Bookmark the permalink.