Board logo

标题: RESTful 项目中对 Cloudant 服务的封装使用(4) [打印本页]

作者: look_w    时间: 2018-11-16 13:33     标题: RESTful 项目中对 Cloudant 服务的封装使用(4)

创建 Cloudant 数据库到目前为止,你已经在 Bluemix 上创建了一个基于 liberty profile 的项目,并创建了一个 Cloudant NoSQL 的服务。接下来的问题是如何去管理这个 Cloudant 数据库。Cloudant 提供了一个 web 的 Dashboard,你可以在这个 Dashboard 上面管理你创建的数据库。选择页面左边导航条目中的 SERVICES 下的 Cloudant NoSQL DB 点击右上角的 Launch 按钮。
在 Database 页面的左上角点击 Add New Database,输入 crud 数据库名称,点击 Create 按钮。
图 16.创建 crud 数据库实例选择 crud 数据库,点击页面左边 All Documents 的加号,创建一个新的文档,如下图 17 所示。
图 17.创建一个文档Cloudant 服务使用配置清单 3.初始化 client
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public static CloseableHttpClient getClient() {
    CredentialsProvider provider = new BasicCredentialsProvider();
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
        username, password);
    provider.setCredentials(AuthScope.ANY, credentials);
    SSLContextBuilder builder = new SSLContextBuilder();
    try {
      builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
    } catch (NoSuchAlgorithmException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (KeyStoreException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    SSLConnectionSocketFactory sslsf = null;
    try {
      sslsf = new SSLConnectionSocketFactory(builder.build(),
          SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    } catch (KeyManagementException e) {
      e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    }
    return HttpClients.custom().setSSLSocketFactory(sslsf)
        .setDefaultCredentialsProvider(provider).build();
  }






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0