コード例 #1
0
  public String request(Link link, String acceptedMediaType, ServiceParameter... serviceParameters)
      throws MalformedURLException, HttpClientException, SocketTimeoutException, OpenShiftException,
          UnsupportedEncodingException {
    String save = client.getAcceptedMediaType();
    client.setAcceptedMediaType(acceptedMediaType);

    HttpMethod httpMethod = link.getHttpMethod();
    URL url = getUrl(link.getHref());
    Map<String, Object> parameters = toMap(serviceParameters);

    LOGGER.trace("Requesting {} on {}", httpMethod.name(), url);
    LOGGER.info("Requesting {} on {}", httpMethod.name(), url);

    String response = client.get(url);

    client.setAcceptedMediaType(save);

    return response;
  }
コード例 #2
0
  private String request(URL url, HttpMethod httpMethod, Map<String, Object> parameters)
      throws HttpClientException, SocketTimeoutException, OpenShiftException,
          UnsupportedEncodingException {
    LOGGER.trace("Requesting {} on {}", httpMethod.name(), url);
    LOGGER.info("Requesting {} on {}", httpMethod.name(), url);

    switch (httpMethod) {
      case GET:
        return client.get(url);
      case POST:
        return client.post(parameters, url);
      case PUT:
        return client.put(parameters, url);
      case DELETE:
        return client.delete(parameters, url);
      default:
        throw new OpenShiftException("Unexpected HTTP method {0}", httpMethod.toString());
    }
  }