WEB开发网
开发学院软件开发Java 开放源码 CMS 入门,第 3 部分: 构建定制存储 阅读

开放源码 CMS 入门,第 3 部分: 构建定制存储

 2010-04-16 00:00:00 来源:WEB开发网   
核心提示: 现在可以参考 sforce Web 服务 API 附带的例子,并“借鉴”某些可用的代码,开放源码 CMS 入门,第 3 部分: 构建定制存储(10),毕竟没有必要从头开始,Login 方法(见清单 7)是一个基本的例子:它不需要对 Quick Start 例子作很多的修改

现在可以参考 sforce Web 服务 API 附带的例子,并“借鉴”某些可用的代码。毕竟没有必要从头开始。Login 方法(见清单 7)是一个基本的例子:它不需要对 Quick Start 例子作很多的修改。您只需提供自己的用户名和密码参数。

清单 7. Login

/* 
 * login sample Prompts for username and password, set class 
 * variable binding resets the url for the binding and adds the 
 * session header to the binding class variable 
 */ 
private boolean login() { 
  //for our new store we use class properties hard coded 
  //with our username and password. 
 
  if (un.length() == 0) { 
    return false; 
  } else { 
    System.out.println("un=" + un); 
  } 
  if (pw.length() == 0) { 
    return false; 
  } else { 
    System.out.println("pw=" + pw); 
  } 
 
  //Provide feed back while we create the web service binding 
  System.out.println("Creating the binding to the web service..."); 
 
  /* 
   * There are 2 ways to get the binding, one by passing a url 
   * to the getSoap() method of the SforceServiceLocator, the 
   * other by not passing a url. In the second case the binding 
   * will use the url contained in the wsdl file when the proxy 
   * was generated. 
   */ 
  try { 
    SforceServiceLocator locator = new SforceServiceLocator(); 
    binding = (SoapBindingStub) locator.getSoap(); 
     
  } catch (ServiceException ex) { 
    System.out.println("ERROR: createing binding to soap service, 
       error was: \n" 
      + ex.getMessage()); 
 
    return false; 
  } 
 
    // Time out after a minute 
  binding.setTimeout(60000); 
 
  //Attempt the login giving the user feedback 
  System.out.println("LOGGING IN NOW...."); 
  try { 
    loginResult = binding.login(un, pw); 
    System.out.println("loginResult.getServ 
    erUrl()=" + loginResult.getServerUrl()); 
    //the loginResult contains the user's ID and is used to 
    //on our CreateDocument and UpdateDocument methods. 
  } catch (LoginFault lf) { 
    System.out.println(lf.getExceptionMessage()); 
    //lf.printStackTrace(); 
    return false; 
  } catch (UnexpectedErrorFault uef) { 
    System.out.println(uef.getExceptionMessage()); 
    uef.printStackTrace(); 
    return false; 
  } catch (RemoteException re) { 
    System.out.println(re.getMessage()); 
    re.printStackTrace(); 
    return false; 
  } 
 
  System.out.println("\nThe session id is: " + loginResult.getSessionId()); 
  System.out.println("\nThe new serv 
  er url is: " + loginResult.getServerUrl()); 
 
  //set the session header for subsequent call authentication 
  try { 
    binding = (SoapBindingStub) new SforceServiceLocator() 
        .getSoap(new URL(loginResult.getServerUrl())); 
  } catch (ServiceException jre) { 
      System.out.println("ERROR: creating binding to soap 
      service, error was: \n" 
      + jre.getMessage()); 
 
    return false; 
  } catch (MalformedURLException e) { 
    e.printStackTrace(); 
  } 
 
  //Create a new session header object and set the session id to 
  //that returned by the login 
   
  _SessionHeader sh = new _SessionHeader(); 
  sh.setSessionId(loginResult.getSessionId()); 
  binding.setHeader("SforceService", "SessionHeader", sh); 
 
  loggedIn = true; 
   
  //set authorID 
  this.setSfAuthorId(loginResult.getUserId().getValue()); 
 
   
  // call the getServerTimestamp method 
  getServerTimestamp(); 
 
  return true; 
 
} 

上一页  5 6 7 8 9 10 

Tags:开放 源码 CMS

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接