diff options
Diffstat (limited to 'src/main/java/at/gv/util/client')
-rw-r--r-- | src/main/java/at/gv/util/client/ur_V2/URClient.java | 90 |
1 files changed, 67 insertions, 23 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() { |