summaryrefslogtreecommitdiff
path: root/eaaf_core_utils
diff options
context:
space:
mode:
authorThomas <>2021-11-18 15:03:28 +0100
committerThomas <>2021-11-18 15:03:28 +0100
commit93c735c1122aeb336bd65bc45d6b14eaa980df06 (patch)
treeb422c48a481914b9dea6ee5c37ac8d88061b494a /eaaf_core_utils
parent803165322243cd0a83dd9e988b8dc19adfc167cb (diff)
downloadEAAF-Components-93c735c1122aeb336bd65bc45d6b14eaa980df06.tar.gz
EAAF-Components-93c735c1122aeb336bd65bc45d6b14eaa980df06.tar.bz2
EAAF-Components-93c735c1122aeb336bd65bc45d6b14eaa980df06.zip
add method to inject http headers into Apache HTTP-Client requests
Diffstat (limited to 'eaaf_core_utils')
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java
index 3058c9b5..dd6f69ee 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java
@@ -34,6 +34,7 @@ import javax.net.ssl.SSLContext;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
+import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
@@ -48,6 +49,7 @@ import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException;
import at.gv.egiz.eaaf.core.exceptions.EaafFactoryException;
import at.gv.egiz.eaaf.core.impl.data.Pair;
import at.gv.egiz.eaaf.core.impl.data.Triple;
+import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@@ -184,6 +186,23 @@ public class HttpUtils {
}
/**
+ * Inject HTTP header into http request.
+ *
+ * <p>The header is only set if HeaderValue is not null</p>
+ *
+ * @param req Http request object
+ * @param headerName HeaderName
+ * @param headerValue HeaderValue
+ */
+ public static void addHeaderIfNotEmpty(@NonNull HttpRequest req, @NonNull String headerName,
+ @Nullable String headerValue) {
+ if (StringUtils.isNotEmpty(headerValue)) {
+ req.addHeader(headerName, headerValue);
+
+ }
+ }
+
+ /**
* Initialize a {@link SSLContext} with a {@link KeyStore} that uses X509 Client
* authentication.
*