예제 #1
0
 private void addParams(ClientRequest request) {
   if (map != null && !map.isEmpty()) {
     Iterator<String> it = map.keySet().iterator();
     while (it.hasNext()) {
       String key;
       request.queryParameter(key = it.next().toString(), map.get(key));
     }
   }
 }
  public void retrieveCity() throws Exception {
    ClientRequest request = new ClientRequest("http://api.geonames.org/postalCodeSearchJSON");
    request.queryParameter("postalcode", order.getZip());
    request.queryParameter("country", "DE");
    request.queryParameter("username", "camunda");
    request.accept("application/json");
    ClientResponse<String> response = request.get(String.class);

    JSONObject jsonObject = new JSONObject(response.getEntity());
    JSONArray jsonArray = jsonObject.getJSONArray("postalCodes");

    if (jsonArray.length() == 0) {
      throw new BpmnError("CITY_NOT_FOUND");
    }

    String city = jsonArray.getJSONObject(0).getString("placeName");

    log.info("### city retrieved: " + city);

    order.setCity(city);
  }
예제 #3
0
  @Ignore
  public void testDeleteMember() throws Exception {
    final String Path = "/members/1";
    ClientRequest webResource = new ClientRequest(BASE_URI + Path);

    ClientResponse response = null;

    ClientRequest resource = webResource;

    resource.queryParameter("auth_token", AUTH_TOKEN);

    response = resource.delete(ClientResponse.class);

    assertTrue(response.getStatus() == HTTP_STATUS_OK);
  }
  public <T> OpenStackResponse request(OpenStackRequest<T> request) {
    ClientRequest client =
        new ClientRequest(
            UriBuilder.fromUri(request.endpoint() + "/" + request.path()),
            ClientRequest.getDefaultExecutor(),
            providerFactory);

    for (Map.Entry<String, List<Object>> entry : request.queryParams().entrySet()) {
      for (Object o : entry.getValue()) {
        client = client.queryParameter(entry.getKey(), String.valueOf(o));
      }
    }

    for (Entry<String, List<Object>> h : request.headers().entrySet()) {
      StringBuilder sb = new StringBuilder();
      for (Object v : h.getValue()) {
        sb.append(String.valueOf(v));
      }
      client.header(h.getKey(), sb);
    }

    if (request.entity() != null) {
      client.body(request.entity().getContentType(), request.entity().getEntity());
    }

    ClientResponse<T> response;

    try {
      response = client.httpMethod(request.method().name(), request.returnType());
    } catch (Exception e) {
      throw new RuntimeException("Unexpected client exception", e);
    }

    if (response.getStatus() == HttpStatus.SC_OK
        || response.getStatus() == HttpStatus.SC_CREATED
        || response.getStatus() == HttpStatus.SC_NO_CONTENT) {
      return new RESTEasyResponse(response);
    }

    response.releaseConnection();

    throw new OpenStackResponseException(
        response.getResponseStatus().getReasonPhrase(), response.getStatus());
  }