From 2b8a7df25878f546ace25373f44baeb026cf6d2b Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Tue, 20 Aug 2019 11:13:28 +0200 Subject: 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. --- src/main/java/at/gv/egiz/moazs/client/ClientFactory.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/main/java/at/gv/egiz/moazs/client') 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); -- cgit v1.2.3