summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.
*