Tuesday 18 November 2014

Build URL of Document in FileNet (Content Engine API)

//Build URL of Document in FileNet (Content Engine API)



//The below code generates the URL of Document. The URL works on same Browser where you run the code else it asks Credentials

public void opendoc() throws IOException
    {
        String baseP8URL = "http://localhost:9080/WorkplaceXT/";
        String user = //User Name
        String password = //Password
        //String objectStore = //Object Store Name
        String docID = //GUID of Document
        //Get Connection
        //Get Domain
        objectStore = //Get Object Store
        com.filenet.api.core.Document doc=com.filenet.api.core.Factory.Document.fetchInstance(objectStore, docID, null);
        String vsId = doc.get_VersionSeries().get_Id().toString();
       
        // Call WorkplaceXT’s setCredentials servlet to obtain user token
        try {
       
        URL url = new URL(baseP8URL +
        "setCredentials?op=getUserToken&userId="
        + user + "&password=" + password + "&verify=true");
        HttpURLConnection p8con =
        (HttpURLConnection) url.openConnection();
        p8con.setRequestMethod("POST");
        p8con.connect();
        InputStream in = p8con.getInputStream();
        int c = -1;
        String tempUserToken = "";
        while ( (c=in.read()) >= 0) tempUserToken +=
        new Character((char)c).toString();
                String userToken = URLEncoder.encode(tempUserToken, "UTF-8");
                System.out.println("the user token "+userToken);
                String strURL = baseP8URL + "getContent?objectStoreName="
                + "Target" + "&vsId=" + vsId + "&objectType=document&ut=" //
                + userToken + "&impersonate=true";
        System.out.println("ssss"+ strURL);
        }
        catch (Exception e )
        {
            e.printStackTrace();
        }
               
    }

No comments:

Post a Comment