function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rajbarath GovindanRajbarath Govindan 

retrieve knowledge article page using FrontDoor.jsp In java Code

We would want to extract Salesforce knowledge articles as PDF. We tried using Frontdoor.jsp to login through java code. (as a precursor, to get the session id to pass to frontdoor jsp, we call connector class to get the connection.) Our requirement is to read the html response of the knowledge article page and then save that as PDF. However a desired html response is not obtained which can be converted into PDF. We are g
 
EnterpriseConnection connection= null;
     
      
                  ConnectorConfig config = new ConnectorConfig();
                  config.setUsername("xxxxx");
                  config.setPassword("xxxxx");
                  config.setAuthEndpoint("https://na.my.salesforce.com"
                              + "/services/Soap/c/32.0");
 
                  try {
                        connection = Connector.newConnection(config);
                        LOGGER.info("LOGGER::::Enterprise Connection established");
                        LOGGER.info("LOGGER::::Auth EndPoint: "
                                    + config.getAuthEndpoint());
                        LOGGER.info("LOGGER::::Service EndPoint: "
                                    + config.getServiceEndpoint());
                        LOGGER.info("LOGGER::::Username: " + config.getUsername());
                  } catch (ApiFault apiFault) {
                        LOGGER.log(
                                    Level.ALL,
                                    "Exception Occured while connecting to Salesforce due to Api Fault",
                                    apiFault);
                        connection = null;
                        throw apiFault;
                  }
           
 
      LOGGER.info("Session id" +connection.getSessionHeader().getSessionId());
      String sUrl="https://na.my.salesforce.com/secur/frontdoor.jsp?sid="+connection.getSessionHeader().getSessionId()+"&retURL=/knowledge/articlePrintableView.apexp?id=kA0f00000000JgZ";
      HttpClient httpclient = new HttpClient();
      GetMethod get = null;try{
      get = new GetMethod(sUrl);
      get.addRequestHeader("Content-Type" , "plain/text");
      httpclient.executeMethod(get);
                    
      LOGGER.info("Response code"+get.getStatusCode());
   
    if(get.getStatusCode()==404||get.getStatusCode()==503)
    {
      LOGGER.info("Webpage Not Available. Please Run after some time ");
     
    }
    }catch(Exception e){
      e.printStackTrace();
      }
      LOGGER.info("oupu"+get.getResponseBodyAsStream());
Here is the response we get when it is printed out on console.
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"></head><body><script>var tm=null;function lhdoredir(){tm&&(window.clearTimeout(tm),tm=null);window.location.replace?window.location.replace("https://na.my.salesforce.com/knowledge/articlePrintableView.apexp?id=kA0f00000000JgZ"):window.location.href="https://na.my.salesforce.com/knowledge/articlePrintableView.apexp?id=kA0f00000000JgZ"}window.setTimeout?tm=window.setTimeout(lhdoredir,1E3):lhdoredir();var SFDCSessionVars={"uid":"005i0000003UV8J","exp":1435209016000,"host":"test.salesforce.com","oid":"00De0000005VPg9","server":"https://test.salesforce.com/login/sessionserver190.html","act":"u"};SFDCSessionVars.callback=lhdoredir;</script><script src="/jslibrary/1427810574000/sfdc/SfdcSessionBase190.js"></script><noscript>You do not have Javascript enabled. Javascript is required to use salesforce.com. Please enable Javascript, then click <a href="https://na.my.salesforce.com/knowledge/articlePrintableView.apexp?id=kA0f00000000JgZ">here</a> to continue.</noscript></body></html>
If there are any guidance to how to proceed that would really help?
 
Ross KerrRoss Kerr
If you have the user name and password you can login through the URL, https://na.my.salesforce.com/?un=[user name]&pw=[password]&startURL=/knowledge/articlePrintableView.apexp?id=kA0f00000000JgZ.

startURL will need to be URLEncoded.

We have been having the same problem using an auth token with frontdoor.jsp and are using this as a workaround for now.