aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/client
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-08-20 11:13:28 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-08-20 11:13:28 +0200
commit2b8a7df25878f546ace25373f44baeb026cf6d2b (patch)
tree8b236fdc42bc66beb16cc59b86258a7794285420 /src/main/java/at/gv/egiz/moazs/client
parent488ecf8632b7204b5da218643eb1631e2d3386ff (diff)
downloadmoa-zs-2b8a7df25878f546ace25373f44baeb026cf6d2b.tar.gz
moa-zs-2b8a7df25878f546ace25373f44baeb026cf6d2b.tar.bz2
moa-zs-2b8a7df25878f546ace25373f44baeb026cf6d2b.zip
Add Custom Http Headers to HTTP Clients
- Change app2mzs schema: Add Custom Headers to ClientType Element. - Set custom headers in ClientFactory. - Parse custom headers from spring environment. - Merge custom headers from two different profiles. - Add example to application.yaml. - Test conversion of custom headers from spring profile - Test merging and overriding custom headers.
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/client')
-rw-r--r--src/main/java/at/gv/egiz/moazs/client/ClientFactory.java10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/client/ClientFactory.java b/src/main/java/at/gv/egiz/moazs/client/ClientFactory.java
index d0a445b..94eb712 100644
--- a/src/main/java/at/gv/egiz/moazs/client/ClientFactory.java
+++ b/src/main/java/at/gv/egiz/moazs/client/ClientFactory.java
@@ -1,5 +1,6 @@
package at.gv.egiz.moazs.client;
+import at.gv.egiz.moazs.preprocess.ConfigUtil;
import at.gv.egiz.moazs.util.FileUtils;
import at.gv.egiz.moazs.util.StoreSOAPBodyBinaryInRepositoryInterceptor;
import at.gv.zustellung.app2mzs.xsd.ClientType;
@@ -10,6 +11,7 @@ import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.jaxws.JaxWsClientFactoryBean;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.cxf.message.Message;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.slf4j.Logger;
@@ -23,6 +25,7 @@ import javax.xml.ws.BindingProvider;
import javax.xml.ws.soap.SOAPBinding;
import static at.gv.zustellung.app2mzs.xsd.KeyStoreType.keyStoreTypeBuilder;
+import static java.util.stream.Collectors.toMap;
@Component
public class ClientFactory {
@@ -32,14 +35,16 @@ public class ClientFactory {
private final StoreSOAPBodyBinaryInRepositoryInterceptor storeResponseInterceptor;
private final SSLContextCreator sslContextCreator;
private final FileUtils fileUtils;
+ private final ConfigUtil configUtil;
@Autowired
public ClientFactory(StoreSOAPBodyBinaryInRepositoryInterceptor storeResponseInterceptor,
SSLContextCreator creator,
- FileUtils fileUtils) {
+ FileUtils fileUtils, ConfigUtil configUtil) {
this.storeResponseInterceptor = storeResponseInterceptor;
this.sslContextCreator = creator;
this.fileUtils = fileUtils;
+ this.configUtil = configUtil;
}
/**
@@ -68,6 +73,9 @@ public class ClientFactory {
httpClientPolicy.setReceiveTimeout(params.getReceiveTimeout().longValueExact());
http.setClient(httpClientPolicy);
+ var customHeaders = configUtil.convertHeadersToMap(params.getCustomHTTPHeader());
+ client.getRequestContext().put(Message.PROTOCOL_HEADERS, customHeaders);
+
if (params.getURL().startsWith("https")) {
TLSClientParameters tlsParams = setupTLSParams(params.getSSL());
http.setTlsClientParameters(tlsParams);