From defceef8afef538555c13d33e344a89a828a3d97 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Fri, 20 Dec 2013 12:35:28 +0100 Subject: inital --- src/main/java/at/gv/util/client/mms/MMSClient.java | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/main/java/at/gv/util/client/mms/MMSClient.java (limited to 'src/main/java/at/gv/util/client/mms/MMSClient.java') diff --git a/src/main/java/at/gv/util/client/mms/MMSClient.java b/src/main/java/at/gv/util/client/mms/MMSClient.java new file mode 100644 index 0000000..1195d3d --- /dev/null +++ b/src/main/java/at/gv/util/client/mms/MMSClient.java @@ -0,0 +1,93 @@ +package at.gv.util.client.mms; + +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; +import javax.net.ssl.SSLContext; +import javax.xml.namespace.QName; +import javax.xml.ws.BindingProvider; +import javax.xml.ws.WebServiceContext; +import javax.xml.ws.handler.Handler; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.gv.util.LaxHostNameVerifier; +import at.gv.util.LoggingHandler; +import at.gv.util.MiscUtil; +import at.gv.util.client.moaid.MOAIDClient; +import at.gv.util.config.EgovUtilConfiguration; +import at.gv.util.ex.EgovUtilException; +import at.gv.util.wsdl.mms.GetMandatesPortType; +import at.gv.util.wsdl.mms.GetMandatesService; +import at.gv.util.wsdl.szr.SZRException; +import at.gv.util.xsd.mms.GetMandatesRequest; +import at.gv.util.xsd.mms.GetMandatesResponse; + +import com.sun.xml.ws.developer.JAXWSProperties; + +public class MMSClient { + + @Resource + WebServiceContext wsContext; + + private EgovUtilConfiguration config = null; + Logger log = LoggerFactory.getLogger(MMSClient.class); + + public MMSClient() {} + + public MMSClient(EgovUtilConfiguration config) { + if (config == null) { + throw new NullPointerException("Parameter config must not be null."); + } + this.config = config; + + + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public GetMandatesResponse sendGetMandatesRequest(GetMandatesRequest request, String mmsServiceURL) throws SZRException, EgovUtilException { + MiscUtil.assertNotNull(request, "request"); + MiscUtil.assertNotNull(mmsServiceURL, "mmsServiceURL"); + + URL url = MOAIDClient.class.getResource("/wsdl/mms/mms.wsdl"); + GetMandatesService service = new GetMandatesService(url, new QName("http://reference.e-government.gv.at/namespace/mandates/mms/1.0/wsdl", "GetMandatesService")); + GetMandatesPortType port = service.getGetMandatesPort(); + + log.debug("MMS connection URL: " + mmsServiceURL); + BindingProvider bindingProvider = (BindingProvider) port; + Map requestContext = bindingProvider.getRequestContext(); + requestContext.put( + BindingProvider.ENDPOINT_ADDRESS_PROPERTY, mmsServiceURL); + + log.trace("Adding JAX-WS request/response trace handler."); + List handlerList = bindingProvider.getBinding().getHandlerChain(); + if (handlerList == null) { + handlerList = new ArrayList(); + } + LoggingHandler loggingHandler = new LoggingHandler(); + handlerList.add(loggingHandler); + bindingProvider.getBinding().setHandlerChain(handlerList); + + // check for ssl + if (mmsServiceURL.toLowerCase().startsWith("https")) { + log.trace("Using ssl for MMS client request."); + SSLContext sslContext = config.getMMSsslConfiguration().getSSLContext(false); + if (sslContext == null) { + throw new EgovUtilException("SSL context from configuration is empty. Please configure an SSL context in the configuration first."); + } + requestContext.put(JAXWSProperties.SSL_SOCKET_FACTORY, sslContext.getSocketFactory()); + + // check for lax hostname + if (this.config.getMMSsslConfiguration().useLaxHostNameVerifier()) { + log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use."); + requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier()); + } + } + return port.getMandatesOperation(request); + } + +} -- cgit v1.2.3