diff --git a/qqq-backend-core/src/main/resources/log4j2.xml b/qqq-backend-core/src/main/resources/log4j2.xml index 60ffc1f6..df03564e 100644 --- a/qqq-backend-core/src/main/resources/log4j2.xml +++ b/qqq-backend-core/src/main/resources/log4j2.xml @@ -25,6 +25,7 @@ + diff --git a/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtil.java b/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtil.java index 300a60b7..bdb45aea 100644 --- a/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtil.java +++ b/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/BaseAPIActionUtil.java @@ -743,6 +743,10 @@ public class BaseAPIActionUtil case OAUTH2 -> request.setHeader("Authorization", "Bearer " + getOAuth2Token()); case API_KEY_QUERY_PARAM -> addApiKeyQueryParamToRequest(request); case CUSTOM -> handleCustomAuthorization(request); + case NONE -> + { + /* nothing to do here */ + } default -> throw new IllegalArgumentException("Unexpected authorization type: " + backendMetaData.getAuthorizationType()); } } @@ -1174,6 +1178,16 @@ public class BaseAPIActionUtil + /******************************************************************************* + ** + *******************************************************************************/ + protected QHttpResponse getQHttpResponse(HttpResponse response) throws Exception + { + return (new QHttpResponse(response)); + } + + + /******************************************************************************* ** *******************************************************************************/ @@ -1207,7 +1221,7 @@ public class BaseAPIActionUtil try(CloseableHttpResponse response = executeHttpRequest(request, httpClient)) { - QHttpResponse qResponse = new QHttpResponse(response); + QHttpResponse qResponse = getQHttpResponse(response); logOutboundApiCall(request, qResponse); diff --git a/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/QHttpResponse.java b/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/QHttpResponse.java index bb32cfd7..72069b3e 100644 --- a/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/QHttpResponse.java +++ b/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/actions/QHttpResponse.java @@ -40,6 +40,7 @@ public class QHttpResponse private String statusReasonPhrase; private List
headerList; private String content; + private byte[] contentBytes; @@ -53,11 +54,47 @@ public class QHttpResponse + /******************************************************************************* + ** Constructor for QHttpResponse that allows reading content as bytes + ** + *******************************************************************************/ + public QHttpResponse(HttpResponse httpResponse, boolean readContentAsBytes) throws Exception + { + if(!readContentAsBytes) + { + new QHttpResponse(httpResponse); + return; + } + + setGeneralHttpResponseData(httpResponse); + if(this.statusCode == null || this.statusCode != 204) + { + this.contentBytes = httpResponse.getEntity().getContent().readAllBytes(); + } + } + + + /******************************************************************************* ** Constructor for qHttpResponse ** *******************************************************************************/ public QHttpResponse(HttpResponse httpResponse) throws Exception + { + setGeneralHttpResponseData(httpResponse); + if(this.statusCode == null || this.statusCode != 204) + { + this.content = EntityUtils.toString(httpResponse.getEntity()); + } + } + + + + /******************************************************************************* + ** Sets data into this entity from an HttpResponse but doesnt read response data + ** + *******************************************************************************/ + private void setGeneralHttpResponseData(HttpResponse httpResponse) throws Exception { this.headerList = Arrays.asList(httpResponse.getAllHeaders()); if(httpResponse.getStatusLine() != null) @@ -69,11 +106,6 @@ public class QHttpResponse this.statusProtocolVersion = httpResponse.getStatusLine().getProtocolVersion().toString(); } } - - if(this.statusCode == null || this.statusCode != 204) - { - this.content = EntityUtils.toString(httpResponse.getEntity()); - } } @@ -242,4 +274,35 @@ public class QHttpResponse return (this); } + + + /******************************************************************************* + ** Getter for contentBytes + *******************************************************************************/ + public byte[] getContentBytes() + { + return (this.contentBytes); + } + + + + /******************************************************************************* + ** Setter for contentBytes + *******************************************************************************/ + public void setContentBytes(byte[] contentBytes) + { + this.contentBytes = contentBytes; + } + + + + /******************************************************************************* + ** Fluent setter for contentBytes + *******************************************************************************/ + public QHttpResponse withContentBytes(byte[] contentBytes) + { + this.contentBytes = contentBytes; + return (this); + } + } diff --git a/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/model/AuthorizationType.java b/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/model/AuthorizationType.java index 9a4f750c..614df755 100644 --- a/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/model/AuthorizationType.java +++ b/qqq-backend-module-api/src/main/java/com/kingsrook/qqq/backend/module/api/model/AuthorizationType.java @@ -33,5 +33,6 @@ public enum AuthorizationType BASIC_AUTH_USERNAME_PASSWORD, CUSTOM, OAUTH2, + NONE, API_KEY_QUERY_PARAM, }