diff --git a/build.gradle b/build.gradle index b0540b2..c8ab767 100644 --- a/build.gradle +++ b/build.gradle @@ -8,13 +8,16 @@ plugins { id 'groovy' } project.ext.moduleName = 'com.synopsys.integration.integration-rest' project.ext.junitShowStandardStreams = 'true' -version = '7.1.3-SNAPSHOT' +version = '8.0.0-SNAPSHOT' description = 'A library wrapping http communication for integrations.' apply plugin: 'com.synopsys.integration.library' dependencies { - api 'com.synopsys.integration:integration-common:24.2.0' + api 'com.synopsys.integration:integration-common:24.2.1' + + api 'org.apache.httpcomponents:httpclient:4.5.13' + api 'org.apache.httpcomponents:httpmime:4.5.13' testImplementation 'org.codehaus.groovy:groovy-all:2.4.12' testImplementation 'com.squareup.okhttp3:mockwebserver:3.9.0' diff --git a/src/main/java/com/synopsys/integration/rest/HttpMethod.java b/src/main/java/com/synopsys/integration/rest/HttpMethod.java index fcd1d9a..f0ceaf4 100644 --- a/src/main/java/com/synopsys/integration/rest/HttpMethod.java +++ b/src/main/java/com/synopsys/integration/rest/HttpMethod.java @@ -22,6 +22,8 @@ */ package com.synopsys.integration.rest; +import org.apache.commons.lang3.StringUtils; + public enum HttpMethod { GET, PUT, @@ -32,4 +34,8 @@ public enum HttpMethod { OPTIONS, TRACE; + public static HttpMethod fromMethod(String method) { + return HttpMethod.valueOf(StringUtils.upperCase(method)); + } + } diff --git a/src/main/java/com/synopsys/integration/rest/response/DefaultResponse.java b/src/main/java/com/synopsys/integration/rest/response/DefaultResponse.java index 8855c39..1700eac 100644 --- a/src/main/java/com/synopsys/integration/rest/response/DefaultResponse.java +++ b/src/main/java/com/synopsys/integration/rest/response/DefaultResponse.java @@ -43,6 +43,8 @@ import org.apache.http.impl.client.CloseableHttpClient; import com.synopsys.integration.exception.IntegrationException; +import com.synopsys.integration.rest.HttpMethod; +import com.synopsys.integration.rest.HttpUrl; import com.synopsys.integration.rest.RestConstants; import com.synopsys.integration.rest.exception.IntegrationRestException; @@ -210,8 +212,17 @@ public void throwExceptionForError() throws IntegrationRestException { } String messageFormat = "There was a problem trying to %s %s, response was %s %s%s."; - String message = String.format(messageFormat, request.getMethod(), request.getURI().toString(), statusCode, statusCodeDescription, reasonPhraseDescription); - throw new IntegrationRestException(statusCode, statusMessage, httpResponseContent, message); + HttpMethod httpMethod = HttpMethod.fromMethod(request.getMethod()); + //ejk - seems unlikey that we'd get here without a valid url... + HttpUrl httpUrl = null; + try { + httpUrl = new HttpUrl(request.getURI()); + } catch (IntegrationException ignored) { + //ignored + } + + String message = String.format(messageFormat, httpMethod, httpUrl.string(), statusCode, statusCodeDescription, reasonPhraseDescription); + throw new IntegrationRestException(httpMethod, httpUrl, statusCode, statusMessage, httpResponseContent, message); } }