diff options
Diffstat (limited to 'src/main/java/at/gv/util/client/zuserech')
-rw-r--r-- | src/main/java/at/gv/util/client/zuserech/ZuseRechClient.java | 140 | ||||
-rw-r--r-- | src/main/java/at/gv/util/client/zuserech/ZuseRechClientException.java | 23 |
2 files changed, 163 insertions, 0 deletions
diff --git a/src/main/java/at/gv/util/client/zuserech/ZuseRechClient.java b/src/main/java/at/gv/util/client/zuserech/ZuseRechClient.java new file mode 100644 index 0000000..74ed951 --- /dev/null +++ b/src/main/java/at/gv/util/client/zuserech/ZuseRechClient.java @@ -0,0 +1,140 @@ +package at.gv.util.client.zuserech; + +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.szr.SZRException; +import at.gv.util.wsdl.zuserech.ClearingPortType; +import at.gv.util.wsdl.zuserech.ClearingService; +import at.gv.util.wsdl.zuserech.ValidateTokenPortType; +import at.gv.util.wsdl.zuserech.ValidateTokenService; +import at.gv.util.xsd.zuserech.ClearingRequestType; +import at.gv.util.xsd.zuserech.ClearingResponseType; +import at.gv.util.xsd.zuserech.ValidateTokenRequest; +import at.gv.util.xsd.zuserech.ValidateTokenResponse; + +import com.sun.xml.ws.developer.JAXWSProperties; + +public class ZuseRechClient { + + @Resource + WebServiceContext wsContext; + + private EgovUtilConfiguration config = null; + Logger log = LoggerFactory.getLogger(ZuseRechClient.class); + + public ZuseRechClient() {} + + public ZuseRechClient(EgovUtilConfiguration config) { + if (config == null) { + throw new NullPointerException("Parameter config must not be null."); + } + this.config = config; + + + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public ClearingResponseType sendClearingRequest(ClearingRequestType csr, String csrServiceURL) throws SZRException, EgovUtilException { + MiscUtil.assertNotNull(csr, "csr"); + MiscUtil.assertNotNull(csrServiceURL, "csrServiceURL"); + + URL url = MOAIDClient.class.getResource("/wsdl/zkopf/zsuerech.wsdl"); + ClearingService service = new ClearingService(url, new QName("http://reference.e-government.gv.at/namespaces/zustellung/rech/wsdl", "ClearingService")); + ClearingPortType port = service.getClearingPort(); + + log.debug("Clearing service connection URL: " + csrServiceURL); + BindingProvider bindingProvider = (BindingProvider) port; + Map<String, Object> requestContext = bindingProvider.getRequestContext(); + requestContext.put( + BindingProvider.ENDPOINT_ADDRESS_PROPERTY, csrServiceURL); + + log.trace("Adding JAX-WS request/response trace handler."); + List<Handler> 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 (csrServiceURL.toLowerCase().startsWith("https")) { + log.trace("Using ssl for clearing service client request."); + SSLContext sslContext = config.getClearingsslConfiguration().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.getClearingsslConfiguration().useLaxHostNameVerifier()) { + log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use."); + requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier()); + } + } + return port.clearingOperation(csr); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public ValidateTokenResponse sendValidateTokenRequest(ValidateTokenRequest vtr, String vtrServiceURL) throws SZRException, EgovUtilException { + MiscUtil.assertNotNull(vtr, "vtr"); + MiscUtil.assertNotNull(vtrServiceURL, "csrServiceURL"); + + URL url = MOAIDClient.class.getResource("/wsdl/zkopf/zsuerech.wsdl"); + ValidateTokenService service = new ValidateTokenService(url, new QName("http://reference.e-government.gv.at/namespaces/zustellung/rech/wsdl", "ValidateTokenService")); + ValidateTokenPortType port = service.getValidateTokenPort(); + + log.debug("Validate token service connection URL: " + vtrServiceURL); + BindingProvider bindingProvider = (BindingProvider) port; + Map<String, Object> requestContext = bindingProvider.getRequestContext(); + requestContext.put( + BindingProvider.ENDPOINT_ADDRESS_PROPERTY, vtrServiceURL); + + log.trace("Adding JAX-WS request/response trace handler."); + List<Handler> 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 (vtrServiceURL.toLowerCase().startsWith("https")) { + log.trace("Using ssl for clearing service client request."); + SSLContext sslContext = config.getClearingsslConfiguration().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.getClearingsslConfiguration().useLaxHostNameVerifier()) { + log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use."); + requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier()); + } + } + return port.validateTokenOperation(vtr); + } + + +} diff --git a/src/main/java/at/gv/util/client/zuserech/ZuseRechClientException.java b/src/main/java/at/gv/util/client/zuserech/ZuseRechClientException.java new file mode 100644 index 0000000..5cdcf33 --- /dev/null +++ b/src/main/java/at/gv/util/client/zuserech/ZuseRechClientException.java @@ -0,0 +1,23 @@ +package at.gv.util.client.zuserech; + +public class ZuseRechClientException extends Exception { + + private static final long serialVersionUID = 5173056345209288701L; + + public ZuseRechClientException() { + super(); + } + + public ZuseRechClientException(String message, Throwable cause) { + super(message, cause); + } + + public ZuseRechClientException(String message) { + super(message); + } + + public ZuseRechClientException(Throwable cause) { + super(cause); + } + +} |