Beispiel #1
0
 /**
  * This method performs create operation using request body.
  *
  * @param body POST Request Body
  * @return JSONObject as response
  * @throws DaoException Exception thrown
  */
 JSONObject internalCreate(HashMap<String, Object> body) throws DaoException {
   String url = this.getUrl();
   IRestAdapter rest = RestAdapterFactory.create(accessor);
   DcResponse res = rest.post(url, JSONObject.toJSONString(body), RestAdapter.CONTENT_TYPE_JSON);
   JSONObject json = (JSONObject) ((JSONObject) res.bodyAsJson().get("d")).get("results");
   return json;
 }
Beispiel #2
0
 /**
  * This method appends query string to execute Query for Search.
  *
  * @param query Query object
  * @return JSON response
  * @throws DaoException Exception thrown
  */
 @SuppressWarnings("unchecked")
 @Override
 public HashMap<String, Object> doSearch(Query query) throws DaoException {
   StringBuilder sb = new StringBuilder(this.getUrl());
   String qry = query.makeQueryString();
   if (qry != null && !"".equals(qry)) {
     sb.append("?" + qry);
   }
   IRestAdapter rest = RestAdapterFactory.create(accessor);
   DcResponse res = rest.get(sb.toString(), RestAdapter.CONTENT_TYPE_JSON);
   return (HashMap<String, Object>) ((JSONObject) res.bodyAsJson());
 }
Beispiel #3
0
 /**
  * This method performs retrieve operation.
  *
  * @param id composite key url encoding the target
  * @return JSONObject as response
  * @throws DaoException Exception thrown
  */
 JSONObject internalRetrieveMultikey(String id) throws DaoException {
   DcResponse res = internalRetrieveMultikeyAsDcResponse(id);
   JSONObject json = (JSONObject) ((JSONObject) res.bodyAsJson().get("d")).get("results");
   return json;
 }
  /**
   * スクリプトからExt_AWSSecurityTokenServiceのSessionToken取得が行えること. Extensionの
   * AWSSecurityTokenServiceテスト用。
   */
  @SuppressWarnings("unchecked")
  @Test
  public final void スクリプトからExt_AWSSecurityTokenServiceのSessionToken取得が行えること() {

    Properties properties = new Properties();
    InputStream configFileStream =
        ClassLoader.getSystemResourceAsStream("extension-test-config.properties");
    try {
      properties.load(configFileStream);
    } catch (IOException e) {
      fail("properties load failuer");
    }

    String url;
    String testSrc = "callExtension_AWSSecurityTokenService_getSessionToken.js";
    HttpUriRequest req = null;
    JSONObject requestBody = new JSONObject();
    requestBody.put("AccessKeyId", properties.getProperty("AccessKeyId"));
    requestBody.put("SecretAccessKey", properties.getProperty("SecretAccessKey"));
    requestBody.put("ProxyHost", properties.getProperty("ProxyHost", null));
    requestBody.put("ProxyPort", Integer.parseInt(properties.getProperty("ProxyPort", "80")));
    requestBody.put("ProxyUser", properties.getProperty("ProxyUser", null));
    requestBody.put("ProxyPassword", properties.getProperty("ProxyPassword", null));
    requestBody.put("durationSeconds", null);

    System.out.println(requestBody.toJSONString());
    try {
      if (isServiceTest) {
        // スクリプトの登録 (Davのput)
        putScript(testSrc, "test.js");
        url = requestUrl();
      } else {
        url = requestUrl(testSrc);
      }
      // サービスの実行(durationSeconds省略)
      req =
          new DcRequestBuilder()
              .url(url)
              .method("POST")
              .body(requestBody.toJSONString())
              .token(token)
              .build();
      req.setHeader(KEY_HEADER_BASEURL, baseUrl);
      String version = getVersion();
      if (version != null && !(version.equals(""))) {
        req.setHeader("X-Dc-Version", version);
      }

      HttpResponse objResponse;
      objResponse = httpClient.execute(req);
      DcResponse dcRes = new DcResponse(objResponse);

      assertEquals(HttpStatus.SC_OK, dcRes.getStatusCode());
      JSONObject credentials = (JSONObject) dcRes.bodyAsJson().get("Credentials");
      System.out.println(credentials.toJSONString());
      assertNotNull(credentials);

      // サービスの実行(durationSeconds指定)
      requestBody.put("durationSeconds", 900);
      req =
          new DcRequestBuilder()
              .url(url)
              .method("POST")
              .body(requestBody.toJSONString())
              .token(token)
              .build();
      req.setHeader(KEY_HEADER_BASEURL, baseUrl);
      version = getVersion();
      if (version != null && !(version.equals(""))) {
        req.setHeader("X-Dc-Version", version);
      }

      objResponse = httpClient.execute(req);
      dcRes = new DcResponse(objResponse);

      assertEquals(HttpStatus.SC_OK, dcRes.getStatusCode());
      credentials = (JSONObject) dcRes.bodyAsJson().get("Credentials");
      System.out.println(credentials.toJSONString());
      assertNotNull(credentials);

    } catch (DaoException e) {
      fail(e.getMessage());
    } catch (ClientProtocolException e) {
      fail(e.getMessage());
    } catch (IOException e) {
      fail(e.getMessage());
    } finally {
      if (isServiceTest) {
        // スクリプトの削除(Davのdel)
        try {
          testSvcCol.del("test.js");
        } catch (DaoException e) {
          fail(e.getMessage());
        }
      }
    }
  }