diff options
author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2014-03-07 12:34:28 +0100 |
---|---|---|
committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2014-03-07 12:34:28 +0100 |
commit | 655d20aa34b819720b20165dc6aeea032df224cc (patch) | |
tree | 8ce293f8043bfb08c218ee94494519a747bdd84c /src/main/java/at/gv | |
parent | 269cee30ed94b35b9c774470e590c03f92186e8a (diff) | |
download | egovutils-655d20aa34b819720b20165dc6aeea032df224cc.tar.gz egovutils-655d20aa34b819720b20165dc6aeea032df224cc.tar.bz2 egovutils-655d20aa34b819720b20165dc6aeea032df224cc.zip |
* switch to secondary UR service if primary service throws an exception
* make http timeout configurable
Diffstat (limited to 'src/main/java/at/gv')
3 files changed, 72 insertions, 24 deletions
diff --git a/src/main/java/at/gv/util/client/ur_V2/URClient.java b/src/main/java/at/gv/util/client/ur_V2/URClient.java index e7766e0..edf68c8 100644 --- a/src/main/java/at/gv/util/client/ur_V2/URClient.java +++ b/src/main/java/at/gv/util/client/ur_V2/URClient.java @@ -325,7 +325,22 @@ public class URClient { body.setSearchCriteria(sct); - SearchResponseType srt = this.urSuche.searchByExample(body); + //request UR service + SearchResponseType srt = null; + try { + srt = this.urSuche.searchByExample(body); + + } catch (javax.xml.ws.soap.SOAPFaultException e) { + //request secondary service + switchTOSecondarySystem(e); + srt = this.urSuche.searchByExample(body); + + } catch (com.sun.xml.ws.client.ClientTransportException e) { + //request secondary service + switchTOSecondarySystem(e); + srt = this.urSuche.searchByExample(body); + + } // check number of records found // int numFound = 0; @@ -345,26 +360,71 @@ public class URClient { return srt.getResultRecords().getResultRecord(); } + private void switchTOSecondarySystem(Exception e) throws URClientException { + log.warn("Request primary UR service failed with error \"" + e.getMessage() +"\". " + + "Switch to secondary UR service."); + + String urURL = config.getURSecondaryProductionEnvironmentURL(); + try { + setURServiceURL(urURL); + + } catch (EgovUtilException e1) { + log.error("Switch to secodary UR service FAILED!", e1); + throw new URClientException(e1.getMessage(), 0); + } + } + + private void setURServiceURL(String urURL) throws EgovUtilException { + // set UR Service URL + + log.trace("UR connection URL: " + urURL); + BindingProvider bindingProvider = (BindingProvider) urSuche; + Map<String, Object> requestContext = bindingProvider.getRequestContext(); + requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, urURL); + + //set HTTP Client Timeout (Default Timeout 60sec) + //requestContext.put(JAXWSProperties.CONNECT_TIMEOUT, this.config.getHTTPRequestTimeout()); + requestContext.put(JAXWSProperties.CONNECT_TIMEOUT, 15000); + + //check for ssl + if (urURL.toLowerCase().startsWith("https")) { + log.trace("Using ssl for SZR client request."); + SSLContext sslContext = this.config.getURsslConfiguration().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.getURsslConfiguration().useLaxHostNameVerifier()) { + log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use."); + requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier()); + } + } + + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) private void initialize() throws EgovUtilException { URL url = URClient.class.getResource("/wsdl/ur_V2/URSucheService.wsdl"); URSucheService urService = null; - String urURL = null; urService = new URSucheService(url, new QName("urn:at:statistik:ur:ws", "URSucheService")); urSuche = urService.getURSucheService(); + BindingProvider bindingProvider = (BindingProvider) urSuche; + + //set service URLs + String urURL = null; if (config.isURTestEnvironment()) { log.trace("Initializing UR test configuration."); - urURL = config.getURTestEnvironmentURL(); + urURL = config.getURTestEnvironmentURL(); } else { log.trace("Initializing UR productive configuration."); urURL = config.getURProductionEnvironmentURL(); } - log.trace("UR connection URL: " + urURL); - BindingProvider bindingProvider = (BindingProvider) urSuche; - Map<String, Object> requestContext = bindingProvider.getRequestContext(); - requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, urURL); + setURServiceURL(urURL); log.trace("Adding JAX-WS request/response trace handler."); List<Handler> handlerList = bindingProvider.getBinding().getHandlerChain(); @@ -383,22 +443,6 @@ public class URClient { szrSOAPHandler.configure(pvpToken); handlerList.add(szrSOAPHandler); bindingProvider.getBinding().setHandlerChain(handlerList); - - //check for ssl - if (urURL.toLowerCase().startsWith("https")) { - log.trace("Using ssl for SZR client request."); - SSLContext sslContext = this.config.getURsslConfiguration().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.getURsslConfiguration().useLaxHostNameVerifier()) { - log.trace("LaxHostnameVerifier enabled. This setting is not recommended to use."); - requestContext.put(JAXWSProperties.HOSTNAME_VERIFIER, new LaxHostNameVerifier()); - } - } } private String createURSearchId() { diff --git a/src/main/java/at/gv/util/config/EgovUtilConfiguration.java b/src/main/java/at/gv/util/config/EgovUtilConfiguration.java index 44768dd..216e1f5 100644 --- a/src/main/java/at/gv/util/config/EgovUtilConfiguration.java +++ b/src/main/java/at/gv/util/config/EgovUtilConfiguration.java @@ -45,6 +45,7 @@ public interface EgovUtilConfiguration { boolean isURTestEnvironment(); String getURProductionEnvironmentURL(); String getURTestEnvironmentURL(); + String getURSecondaryProductionEnvironmentURL(); PvpTokenType getURPVPToken(); JaxWsSSLConfiguration getClearingsslConfiguration(); diff --git a/src/main/java/at/gv/util/config/EgovUtilPropertiesConfiguration.java b/src/main/java/at/gv/util/config/EgovUtilPropertiesConfiguration.java index 7de17aa..67873f3 100644 --- a/src/main/java/at/gv/util/config/EgovUtilPropertiesConfiguration.java +++ b/src/main/java/at/gv/util/config/EgovUtilPropertiesConfiguration.java @@ -295,6 +295,9 @@ public class EgovUtilPropertiesConfiguration implements EgovUtilConfiguration { return this.props.getProperty("egovutil.ur.test.url"); } + public String getURSecondaryProductionEnvironmentURL() { + return this.props.getProperty("egovutil.ur.prod.secondary.url"); + } public JaxWsSSLConfiguration getMISsslConfiguration() { return missslConfiguration; @@ -349,7 +352,7 @@ public class EgovUtilPropertiesConfiguration implements EgovUtilConfiguration { } public int getHTTPRequestTimeout() { - return Integer.parseInt(this.props.getProperty("egovutil.usp.http.timeout","60000")); + return Integer.parseInt(this.props.getProperty("egovutil.http.timeout","60000")); } public JaxWsSSLConfiguration getERsBsslConfiguration() { |