开放源码 CMS 入门,第 3 部分: 构建定制存储
2010-04-16 00:00:00 来源:WEB开发网现在可以参考 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;
}
- ››CmsTop采集图文教程
- ››cmstop如何更换系统默认模板
- ››CmsTop大众版视频教程之:文章采集教程
- ››CMS行业价值和方向在哪里 究竟还剩下些什么?
- ››开放的云让业务更“闪亮”
- ››开放源码 CMS 入门,第 1 部分: 下载、安装和开始...
- ››开放源码 CMS 入门,第 2 部分: 通过 Eclipse 构建...
- ››开放源码 CMS 入门,第 3 部分: 构建定制存储
- ››开放源码 CMS 入门,第 5 部分: 为 Jakarta Slide...
- ››开放源码 CMS 入门,第 6 部分: 为 Jakarta Slide...
- ››CMS阅读功能 for v 7.5
- ››开放标准、开放源码和 Domino 6: 通过 Python 和 ...
更多精彩
赞助商链接