- Client client = ClientBuilder.newClient(new ClientConfig());
- String content = GsonUtil.beanToJson(ruleCreateRequest);
- WebTarget webTarget = client.target(url);
- Response response = webTarget.request(MediaType.APPLICATION_JSON)
- .put(Entity.entity(content, MediaType.APPLICATION_JSON));
- suc = response.getStatus() == 200;
+ String content = "";
+ try {
+ content = GsonUtil.beanToJson(ruleCreateRequest);
+ } catch (Exception e) {
+ throw new CorrelationException("Failed to convert the message object to a json string.", e);
+ }
+ HashMap<String, String> headers = new HashMap<>();
+ headers.put("Content-Type", MediaType.APPLICATION_JSON);
+ headers.put("Accept", MediaType.APPLICATION_JSON);
+ HttpResponse httpResponse;
+ CloseableHttpClient httpClient = null;
+ HttpPut httpPut = new HttpPut(url);
+ try {
+ httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);
+ httpResponse = HttpsUtils
+ .put(httpPut, headers, new HashMap<>(), new StringEntity(content), httpClient);
+ } catch (UnsupportedEncodingException e) {
+ throw new CorrelationException("Failed to create https entity.", e);
+ } catch (Exception e) {
+ throw new CorrelationException(e.getMessage());
+ } finally {
+ httpPut.releaseConnection();
+ closeHttpClient(httpClient);
+ }
+ if (httpResponse != null) {
+ suc = httpResponse.getStatusLine().getStatusCode() == 200;
+ }