配置 Cloudant 驅動程式的進階功能
您可以在 Liberty 上使用 Cloudant Java 用戶端的進階功能。
開始之前
請參閱 Cloudant 配置主題在 Liberty 中,利用 Cloudant Java 用戶端程式庫來配置 CouchDB 連線功能,確定已配置 server.xml 中必要的資源。
關於這項作業
作為 Cloudant Java 用戶端的使用者,您在執行伺服器時可能會想要啟用 Java 2 安全,或將鑑別別名套用於資源參照。 或者,您也可以在不含任何 Websphere 整合特性的情況下,使用 Cloudant Java 用戶端。 下列步驟可以彼此獨立完成。
程序
- 如果您的伺服器是在啟用 Java 2 安全的情況下執行,便需要授予 cloudant 用戶端程式庫許可權。
例如,在 server.xml 中,您可以指定:
<javaPermission codebase="${shared.resource.dir}cloudant/cloudant-client-2.2.0.jar" className="java.security.AllPermission"/>
- 在 server.xml 檔中,建立一個預設儲存器鑑別別名元素,以提供一個用來接受資料庫鑑別的使用者名稱與密碼。
<cloudant ... containerAuthDataRef="cadr"/> <authData id="cadr" user="username" password="password"/>
提示: 您可以不指定預設儲存器鑑別別名,而使用 cloudant 元素的使用者名稱與密碼屬性。 如需相關資訊,請參閱 Liberty:密碼加密保護的限制,以瞭解如何維護配置檔中的密碼安全。 - 應用程式可以對連結中的每個資源參照,各指定一個儲存器管理鑑別別名。
指定為鑑別別名的值必須是伺服器配置中某個 authData 元素的 ID。
例如,在 ibm-web-bnd.xml 中,您可以指定:
<resource-ref name="java:module/env/cloudant/testDBRef" binding-name="cloudant/testDB"> <authentication-alias name="cadr"/> </resource-ref>
- 如果您想在應用程式中使用未受管理的 Cloudant 資源,不需要啟用 cloudant-1.0 特性,也不需要在 server.xml 中新增任何 cloudant 或 cloudantDatabase 元素。
當您使用未受管理的 Cloudant 時,Cloudant 程式庫有可能直接包裝在應用程式中,也可能在 server.xml 中配置某個程式庫:
<library name="cloudantLib"> <fileset dir="${shared.resource.dir}cloudant" includes="cloudant-client-2.2.0.jar commons-codec-1.6.jar commons-io-2.4.jar gson-2.2.4.jar"/> </library> <application ...> <classloader commonLibraryRef="cloudantLib"/> </application>
- 如果在 cloudant 配置元素上指定 JNDI 名稱,您可以利用 cloudant 配置元素來注入或查閱所配置的 ClientBuilder。
<cloudant id="builder" jndiName="cloudant/builder" ... />
利用 cloudant 配置元素來配置的 ClientBuilder 的注入或查閱範例。
import com.cloudant.client.api.*; //... @Resource(lookup="cloudant/builder", name="cloudant/resRef") ClientBuilder builder; public void useInjectedBuilder() { CloudantClient client = builder.build(); Database db = client.database("somedb", true); // use the db ... // Shutdown the connection manager for this client when you are done with it // note that this renders the CloudantClient instance unusable after this point client.shutdown(); } public void useBuilderLookup() throws NamingException { ClientBuilder builder = (ClientBuilder) new InitialContext().lookup("java:comp/env/cloudant/resRef"); CloudantClient client = builder.build(); Database db = client.database("somedb",true); // use the db ... // Shutdown the connection manager for this client when you are done with it // note that this renders the CloudantClient instance unusable after this point client.shutdown(); }


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twlp_couchdb_configdriver
檔名:twlp_couchdb_configdriver.html