Page tree

When you submit RESTful commands via the BLCLI, the authentication credentials you provide when you initiate your BLCLI session are sufficient for submitting RESTful commands. However, when you access web services via HTTP, you need to provide authentication information in order to access web services.

  • Browser: When you pass in a RESTful request in a browser, you must pass in a username, a password, and role credentials with each request.
  • HTTPRequests: If you are submitting RESTful requests by building your own HTTPRequests from your own client, you can use the login command to obtain a session ID. After you have a session ID, you can reuse it in subsequent requests.

Here is an example of submitting a login request, getting the session ID in the XML response, and submitting a subsequent GET using that session ID:

Submit the Login request
https://myAppServer:9843/group/Servers/myServers/?username=BLAdmin&password=foo&role=
BLAdmins&BQUERY=SELECT%20*%20FROM%20%22SystemObject%2FServer%2
URL url = new URL("https://localhost:9843/login?username=<user>&password=<password>&role=<role>");
        HttpsURLConnection urlConnection = (HttpsURLConnection)url.openConnection();
        urlConnection.setRequestProperty("Accept", "text/xml");
        urlConnection.setSSLSocketFactory(getSocketFactory());
        urlConnection.setHostnameVerifier(new MyHostNameVerifier());
        urlConnection.connect();
        InputStream stream = urlConnection.getInputStream();
        // parse the response
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(stream);
        doc.getDocumentElement().normalize();
        Element docElement = doc.getDocumentElement();
        Node sessionIdResponseNode = docElement.getFirstChild();
        Node sessionIdNode = sessionIdResponseNode.getFirstChild();
        // Get the sessionId
        String sessionId = sessionIdNode.getFirstChild().getNodeValue();
        urlConnection.disconnect();
        // Submit a GET request
        url = new URL("https://localhost:9843/type/PropertySetClasses/SystemObject/Server");
        urlConnection = (HttpsURLConnection)url.openConnection();
        urlConnection.setRequestProperty("Accept", "text/xml");
            // Set the SessionId
        urlConnection.setRequestProperty("SessionId", sessionId);
        urlConnection.setSSLSocketFactory(getSocketFactory());
        urlConnection.setHostnameVerifier(new MyHostNameVerifier());
        urlConnection.connect();
        InputStream stream = urlConnection.getInputStream();
        // Parse the response...
  • No labels