diff --git a/README.md b/README.md index ed326a4..3e7fa25 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ You can import it to your maven or gradle project as a dependency io.camunda camunda-operate-client-java - 8.1.7.0 + 8.1.7.1 ``` diff --git a/build.gradle b/build.gradle index 97ea54b..58fe9c8 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'io.camunda' -version = '8.1.7.0' +version = '8.1.7.1' sourceCompatibility = '8' repositories { diff --git a/src/main/java/io/camunda/operate/CamundaOperateClient.java b/src/main/java/io/camunda/operate/CamundaOperateClient.java index e1e0e33..5c311df 100644 --- a/src/main/java/io/camunda/operate/CamundaOperateClient.java +++ b/src/main/java/io/camunda/operate/CamundaOperateClient.java @@ -84,14 +84,28 @@ public BpmnModelInstance getProcessDefinitionModel(Long key) throws OperateExcep throw new OperateException(e); } } - - public static CloseableHttpResponse execute(CloseableHttpClient httpClient, ClassicHttpRequest request) throws IOException, OperateException { + public CloseableHttpResponse execute(CloseableHttpClient httpClient, ClassicHttpRequest request) throws IOException, OperateException { + return execute(httpClient, request, 0); + } + private CloseableHttpResponse execute(CloseableHttpClient httpClient, ClassicHttpRequest request, int count) throws IOException, OperateException { CloseableHttpResponse response = httpClient.execute(request); + if (response.getCode()==401 && count<=2) { + authentication.authenticate(this); + return execute(httpClient, request, ++count); + } if (response.getCode()>399) { - throw new OperateException("Authentication error : "+response.getCode()+" "+response.getReasonPhrase()); + throw createDetailedException(response, request); } return response; } + + private OperateException createDetailedException(CloseableHttpResponse response, ClassicHttpRequest request) throws IOException { + String details = ""; + if (request instanceof HttpPost) { + details+= "; Body : " + new String(((HttpPost) request).getEntity().getContent().readAllBytes(), StandardCharsets.UTF_8); + } + return new OperateException(request.getPath()+" : "+response.getCode()+" "+response.getReasonPhrase()+details); + } public ProcessInstance getProcessInstance(Long key) throws OperateException { return get(key, ProcessInstance.class); diff --git a/src/main/java/io/camunda/operate/auth/SaasAuthentication.java b/src/main/java/io/camunda/operate/auth/SaasAuthentication.java index 1ec28e4..3c54d1d 100644 --- a/src/main/java/io/camunda/operate/auth/SaasAuthentication.java +++ b/src/main/java/io/camunda/operate/auth/SaasAuthentication.java @@ -48,7 +48,7 @@ public void authenticate(CamundaOperateClient client) throws OperateException { httpPost.setEntity(new StringEntity(data)); try (CloseableHttpClient httpClient = HttpClients.createDefault()) { - try (CloseableHttpResponse response = CamundaOperateClient.execute(httpClient, httpPost)) { + try (CloseableHttpResponse response = client.execute(httpClient, httpPost)) { JsonNode responseBody = JsonUtils.toJsonNode(response.getEntity().getContent()); String token = responseBody.get("access_token").asText();