@Test public void shouldParseInSequenceConnectOptions() throws Exception { File configFile = null; try { configFile = createTempFileFromResource("org/kaazing/gateway/server/config/parse/data/gateway-config-in-sequence-connect" + "-options.xml"); parser.parse(configFile); } finally { if (configFile != null) { configFile.delete(); } } }
public GatewayConfigDocument parse(final File configFile) throws Exception { long time = 0; if (LOGGER.isDebugEnabled()) { time = System.currentTimeMillis(); } String configFileName = configFile.getName(); GatewayConfigDocument config = null; XmlOptions parseOptions = new XmlOptions(); parseOptions.setLoadLineNumbers(); parseOptions.setLoadLineNumbers(XmlOptions.LOAD_LINE_NUMBERS_END_ELEMENT); parseOptions.setLoadStripWhitespace(); parseOptions.setLoadStripComments(); File translatedConfigFile; try { translatedConfigFile = getTranslatedConfigFile(configFile); } catch (Exception e) { Throwable rootCause = getRootCause(e); if (rootCause == null) { rootCause = e; } if (LOGGER.isDebugEnabled()) { LOGGER.error("Error upgrading XML: " + rootCause, rootCause); } else { LOGGER.error("Error upgrading XML: " + rootCause); } if (e instanceof IllegalArgumentException) { throw e; } else { throw new GatewayConfigParserException(e.getMessage()); } } List<String> xmlParseErrors = new ArrayList<>(); try { config = GatewayConfigDocument.Factory.parse(new FileInputStream(translatedConfigFile), parseOptions); } catch (Exception e) { xmlParseErrors.add("Invalid XML: " + getRootCause(e).getMessage()); } if (xmlParseErrors.isEmpty()) { GatewayConfigDocument.GatewayConfig gatewayConfig = config.getGatewayConfig(); PropertiesType properties = gatewayConfig.getProperties(); Map<String, String> propertiesMap = new HashMap<>(); if (properties != null) { for (PropertyType propertyType : properties.getPropertyArray()) { propertiesMap.put(propertyType.getName(), propertyType.getValue()); } } InputStream xmlInjectedIn = new PipedInputStream(); OutputStream xmlInjectedOut = new PipedOutputStream((PipedInputStream) xmlInjectedIn); ExecutorService xmlInjectedExecutor = Executors.newSingleThreadExecutor(); Future<Boolean> xmlInjectedFuture = xmlInjectedExecutor.submit(new XMLParameterInjector(new FileInputStream( translatedConfigFile), xmlInjectedOut, propertiesMap, configuration, xmlParseErrors)); if (LOGGER.isTraceEnabled()) { xmlInjectedIn = bufferToTraceLog(xmlInjectedIn, "Gateway config file '" + configFileName + "' post parameter injection", LOGGER); } InputStream xmlTransformedIn = new PipedInputStream(); OutputStream xmlTransformedOut = new PipedOutputStream((PipedInputStream) xmlTransformedIn); ExecutorService xmlTransformedExecutor = Executors.newSingleThreadExecutor(); Future<Boolean> xmlTransformedFuture = xmlTransformedExecutor.submit( new XSLTransformer(xmlInjectedIn, xmlTransformedOut, GATEWAY_CONFIG_ANNOTATE_TYPES_XSL)); if (LOGGER.isTraceEnabled()) { xmlTransformedIn = bufferToTraceLog(xmlTransformedIn, "Gateway config file '" + configFileName + "' post XSL transformation", LOGGER); } try { config = GatewayConfigDocument.Factory.parse(xmlTransformedIn, parseOptions); } catch (Exception e) { try { if (xmlInjectedFuture.get()) { if (xmlTransformedFuture.get()) { throw e; } } } catch (Exception n) { xmlParseErrors.add("Invalid XML: " + getRootCause(n).getMessage()); } } finally { xmlInjectedFuture.cancel(true); xmlInjectedExecutor.shutdownNow(); xmlTransformedFuture.cancel(true); xmlTransformedExecutor.shutdownNow(); } } validateGatewayConfig(config, xmlParseErrors); if (LOGGER.isDebugEnabled()) { LOGGER.debug("parsed " + " gateway config file '" + configFileName + "' in [" + (System.currentTimeMillis() - time) + " ms]"); } return config; }
GatewayConfigParser { public GatewayConfigDocument parse(final File configFile) throws Exception { long time = 0; if (LOGGER.isDebugEnabled()) { time = System.currentTimeMillis(); } String configFileName = configFile.getName(); GatewayConfigDocument config = null; XmlOptions parseOptions = new XmlOptions(); parseOptions.setLoadLineNumbers(); parseOptions.setLoadLineNumbers(XmlOptions.LOAD_LINE_NUMBERS_END_ELEMENT); parseOptions.setLoadStripWhitespace(); parseOptions.setLoadStripComments(); File translatedConfigFile; try { translatedConfigFile = getTranslatedConfigFile(configFile); } catch (Exception e) { Throwable rootCause = getRootCause(e); if (rootCause == null) { rootCause = e; } if (LOGGER.isDebugEnabled()) { LOGGER.error("Error upgrading XML: " + rootCause, rootCause); } else { LOGGER.error("Error upgrading XML: " + rootCause); } if (e instanceof IllegalArgumentException) { throw e; } else { throw new GatewayConfigParserException(e.getMessage()); } } List<String> xmlParseErrors = new ArrayList<>(); try { config = GatewayConfigDocument.Factory.parse(new FileInputStream(translatedConfigFile), parseOptions); } catch (Exception e) { xmlParseErrors.add("Invalid XML: " + getRootCause(e).getMessage()); } if (xmlParseErrors.isEmpty()) { GatewayConfigDocument.GatewayConfig gatewayConfig = config.getGatewayConfig(); PropertiesType properties = gatewayConfig.getProperties(); Map<String, String> propertiesMap = new HashMap<>(); if (properties != null) { for (PropertyType propertyType : properties.getPropertyArray()) { propertiesMap.put(propertyType.getName(), propertyType.getValue()); } } InputStream xmlInjectedIn = new PipedInputStream(); OutputStream xmlInjectedOut = new PipedOutputStream((PipedInputStream) xmlInjectedIn); ExecutorService xmlInjectedExecutor = Executors.newSingleThreadExecutor(); Future<Boolean> xmlInjectedFuture = xmlInjectedExecutor.submit(new XMLParameterInjector(new FileInputStream( translatedConfigFile), xmlInjectedOut, propertiesMap, configuration, xmlParseErrors)); if (LOGGER.isTraceEnabled()) { xmlInjectedIn = bufferToTraceLog(xmlInjectedIn, "Gateway config file '" + configFileName + "' post parameter injection", LOGGER); } InputStream xmlTransformedIn = new PipedInputStream(); OutputStream xmlTransformedOut = new PipedOutputStream((PipedInputStream) xmlTransformedIn); ExecutorService xmlTransformedExecutor = Executors.newSingleThreadExecutor(); Future<Boolean> xmlTransformedFuture = xmlTransformedExecutor.submit( new XSLTransformer(xmlInjectedIn, xmlTransformedOut, GATEWAY_CONFIG_ANNOTATE_TYPES_XSL)); if (LOGGER.isTraceEnabled()) { xmlTransformedIn = bufferToTraceLog(xmlTransformedIn, "Gateway config file '" + configFileName + "' post XSL transformation", LOGGER); } try { config = GatewayConfigDocument.Factory.parse(xmlTransformedIn, parseOptions); } catch (Exception e) { try { if (xmlInjectedFuture.get()) { if (xmlTransformedFuture.get()) { throw e; } } } catch (Exception n) { xmlParseErrors.add("Invalid XML: " + getRootCause(n).getMessage()); } } finally { xmlInjectedFuture.cancel(true); xmlInjectedExecutor.shutdownNow(); xmlTransformedFuture.cancel(true); xmlTransformedExecutor.shutdownNow(); } } validateGatewayConfig(config, xmlParseErrors); if (LOGGER.isDebugEnabled()) { LOGGER.debug("parsed " + " gateway config file '" + configFileName + "' in [" + (System.currentTimeMillis() - time) + " ms]"); } return config; } }
GatewayConfigParser { public GatewayConfigDocument parse(final File configFile) throws Exception { long time = 0; if (LOGGER.isDebugEnabled()) { time = System.currentTimeMillis(); } String configFileName = configFile.getName(); GatewayConfigDocument config = null; XmlOptions parseOptions = new XmlOptions(); parseOptions.setLoadLineNumbers(); parseOptions.setLoadLineNumbers(XmlOptions.LOAD_LINE_NUMBERS_END_ELEMENT); parseOptions.setLoadStripWhitespace(); parseOptions.setLoadStripComments(); File translatedConfigFile; try { translatedConfigFile = getTranslatedConfigFile(configFile); } catch (Exception e) { Throwable rootCause = getRootCause(e); if (rootCause == null) { rootCause = e; } if (LOGGER.isDebugEnabled()) { LOGGER.error("Error upgrading XML: " + rootCause, rootCause); } else { LOGGER.error("Error upgrading XML: " + rootCause); } if (e instanceof IllegalArgumentException) { throw e; } else { throw new GatewayConfigParserException(e.getMessage()); } } List<String> xmlParseErrors = new ArrayList<>(); try { config = GatewayConfigDocument.Factory.parse(new FileInputStream(translatedConfigFile), parseOptions); } catch (Exception e) { xmlParseErrors.add("Invalid XML: " + getRootCause(e).getMessage()); } if (xmlParseErrors.isEmpty()) { GatewayConfigDocument.GatewayConfig gatewayConfig = config.getGatewayConfig(); PropertiesType properties = gatewayConfig.getProperties(); Map<String, String> propertiesMap = new HashMap<>(); if (properties != null) { for (PropertyType propertyType : properties.getPropertyArray()) { propertiesMap.put(propertyType.getName(), propertyType.getValue()); } } InputStream xmlInjectedIn = new PipedInputStream(); OutputStream xmlInjectedOut = new PipedOutputStream((PipedInputStream) xmlInjectedIn); ExecutorService xmlInjectedExecutor = Executors.newSingleThreadExecutor(); Future<Boolean> xmlInjectedFuture = xmlInjectedExecutor.submit(new XMLParameterInjector(new FileInputStream( translatedConfigFile), xmlInjectedOut, propertiesMap, configuration, xmlParseErrors)); if (LOGGER.isTraceEnabled()) { xmlInjectedIn = bufferToTraceLog(xmlInjectedIn, "Gateway config file '" + configFileName + "' post parameter injection", LOGGER); } InputStream xmlTransformedIn = new PipedInputStream(); OutputStream xmlTransformedOut = new PipedOutputStream((PipedInputStream) xmlTransformedIn); ExecutorService xmlTransformedExecutor = Executors.newSingleThreadExecutor(); Future<Boolean> xmlTransformedFuture = xmlTransformedExecutor.submit( new XSLTransformer(xmlInjectedIn, xmlTransformedOut, GATEWAY_CONFIG_ANNOTATE_TYPES_XSL)); if (LOGGER.isTraceEnabled()) { xmlTransformedIn = bufferToTraceLog(xmlTransformedIn, "Gateway config file '" + configFileName + "' post XSL transformation", LOGGER); } try { config = GatewayConfigDocument.Factory.parse(xmlTransformedIn, parseOptions); } catch (Exception e) { try { if (xmlInjectedFuture.get()) { if (xmlTransformedFuture.get()) { throw e; } } } catch (Exception n) { xmlParseErrors.add("Invalid XML: " + getRootCause(n).getMessage()); } } finally { xmlInjectedFuture.cancel(true); xmlInjectedExecutor.shutdownNow(); xmlTransformedFuture.cancel(true); xmlTransformedExecutor.shutdownNow(); } } validateGatewayConfig(config, xmlParseErrors); if (LOGGER.isDebugEnabled()) { LOGGER.debug("parsed " + " gateway config file '" + configFileName + "' in [" + (System.currentTimeMillis() - time) + " ms]"); } return config; } GatewayConfigParser();  GatewayConfigParser(Properties configuration); }
GatewayConfigParser { public GatewayConfigDocument parse(final File configFile) throws Exception { long time = 0; if (LOGGER.isDebugEnabled()) { time = System.currentTimeMillis(); } String configFileName = configFile.getName(); GatewayConfigDocument config = null; XmlOptions parseOptions = new XmlOptions(); parseOptions.setLoadLineNumbers(); parseOptions.setLoadLineNumbers(XmlOptions.LOAD_LINE_NUMBERS_END_ELEMENT); parseOptions.setLoadStripWhitespace(); parseOptions.setLoadStripComments(); File translatedConfigFile; try { translatedConfigFile = getTranslatedConfigFile(configFile); } catch (Exception e) { Throwable rootCause = getRootCause(e); if (rootCause == null) { rootCause = e; } if (LOGGER.isDebugEnabled()) { LOGGER.error("Error upgrading XML: " + rootCause, rootCause); } else { LOGGER.error("Error upgrading XML: " + rootCause); } if (e instanceof IllegalArgumentException) { throw e; } else { throw new GatewayConfigParserException(e.getMessage()); } } List<String> xmlParseErrors = new ArrayList<>(); try { config = GatewayConfigDocument.Factory.parse(new FileInputStream(translatedConfigFile), parseOptions); } catch (Exception e) { xmlParseErrors.add("Invalid XML: " + getRootCause(e).getMessage()); } if (xmlParseErrors.isEmpty()) { GatewayConfigDocument.GatewayConfig gatewayConfig = config.getGatewayConfig(); PropertiesType properties = gatewayConfig.getProperties(); Map<String, String> propertiesMap = new HashMap<>(); if (properties != null) { for (PropertyType propertyType : properties.getPropertyArray()) { propertiesMap.put(propertyType.getName(), propertyType.getValue()); } } InputStream xmlInjectedIn = new PipedInputStream(); OutputStream xmlInjectedOut = new PipedOutputStream((PipedInputStream) xmlInjectedIn); ExecutorService xmlInjectedExecutor = Executors.newSingleThreadExecutor(); Future<Boolean> xmlInjectedFuture = xmlInjectedExecutor.submit(new XMLParameterInjector(new FileInputStream( translatedConfigFile), xmlInjectedOut, propertiesMap, configuration, xmlParseErrors)); if (LOGGER.isTraceEnabled()) { xmlInjectedIn = bufferToTraceLog(xmlInjectedIn, "Gateway config file '" + configFileName + "' post parameter injection", LOGGER); } InputStream xmlTransformedIn = new PipedInputStream(); OutputStream xmlTransformedOut = new PipedOutputStream((PipedInputStream) xmlTransformedIn); ExecutorService xmlTransformedExecutor = Executors.newSingleThreadExecutor(); Future<Boolean> xmlTransformedFuture = xmlTransformedExecutor.submit( new XSLTransformer(xmlInjectedIn, xmlTransformedOut, GATEWAY_CONFIG_ANNOTATE_TYPES_XSL)); if (LOGGER.isTraceEnabled()) { xmlTransformedIn = bufferToTraceLog(xmlTransformedIn, "Gateway config file '" + configFileName + "' post XSL transformation", LOGGER); } try { config = GatewayConfigDocument.Factory.parse(xmlTransformedIn, parseOptions); } catch (Exception e) { try { if (xmlInjectedFuture.get()) { if (xmlTransformedFuture.get()) { throw e; } } } catch (Exception n) { xmlParseErrors.add("Invalid XML: " + getRootCause(n).getMessage()); } } finally { xmlInjectedFuture.cancel(true); xmlInjectedExecutor.shutdownNow(); xmlTransformedFuture.cancel(true); xmlTransformedExecutor.shutdownNow(); } } validateGatewayConfig(config, xmlParseErrors); if (LOGGER.isDebugEnabled()) { LOGGER.debug("parsed " + " gateway config file '" + configFileName + "' in [" + (System.currentTimeMillis() - time) + " ms]"); } return config; } GatewayConfigParser();  GatewayConfigParser(Properties configuration); GatewayConfigDocument parse(final File configFile); }
GatewayConfigParser { public GatewayConfigDocument parse(final File configFile) throws Exception { long time = 0; if (LOGGER.isDebugEnabled()) { time = System.currentTimeMillis(); } String configFileName = configFile.getName(); GatewayConfigDocument config = null; XmlOptions parseOptions = new XmlOptions(); parseOptions.setLoadLineNumbers(); parseOptions.setLoadLineNumbers(XmlOptions.LOAD_LINE_NUMBERS_END_ELEMENT); parseOptions.setLoadStripWhitespace(); parseOptions.setLoadStripComments(); File translatedConfigFile; try { translatedConfigFile = getTranslatedConfigFile(configFile); } catch (Exception e) { Throwable rootCause = getRootCause(e); if (rootCause == null) { rootCause = e; } if (LOGGER.isDebugEnabled()) { LOGGER.error("Error upgrading XML: " + rootCause, rootCause); } else { LOGGER.error("Error upgrading XML: " + rootCause); } if (e instanceof IllegalArgumentException) { throw e; } else { throw new GatewayConfigParserException(e.getMessage()); } } List<String> xmlParseErrors = new ArrayList<>(); try { config = GatewayConfigDocument.Factory.parse(new FileInputStream(translatedConfigFile), parseOptions); } catch (Exception e) { xmlParseErrors.add("Invalid XML: " + getRootCause(e).getMessage()); } if (xmlParseErrors.isEmpty()) { GatewayConfigDocument.GatewayConfig gatewayConfig = config.getGatewayConfig(); PropertiesType properties = gatewayConfig.getProperties(); Map<String, String> propertiesMap = new HashMap<>(); if (properties != null) { for (PropertyType propertyType : properties.getPropertyArray()) { propertiesMap.put(propertyType.getName(), propertyType.getValue()); } } InputStream xmlInjectedIn = new PipedInputStream(); OutputStream xmlInjectedOut = new PipedOutputStream((PipedInputStream) xmlInjectedIn); ExecutorService xmlInjectedExecutor = Executors.newSingleThreadExecutor(); Future<Boolean> xmlInjectedFuture = xmlInjectedExecutor.submit(new XMLParameterInjector(new FileInputStream( translatedConfigFile), xmlInjectedOut, propertiesMap, configuration, xmlParseErrors)); if (LOGGER.isTraceEnabled()) { xmlInjectedIn = bufferToTraceLog(xmlInjectedIn, "Gateway config file '" + configFileName + "' post parameter injection", LOGGER); } InputStream xmlTransformedIn = new PipedInputStream(); OutputStream xmlTransformedOut = new PipedOutputStream((PipedInputStream) xmlTransformedIn); ExecutorService xmlTransformedExecutor = Executors.newSingleThreadExecutor(); Future<Boolean> xmlTransformedFuture = xmlTransformedExecutor.submit( new XSLTransformer(xmlInjectedIn, xmlTransformedOut, GATEWAY_CONFIG_ANNOTATE_TYPES_XSL)); if (LOGGER.isTraceEnabled()) { xmlTransformedIn = bufferToTraceLog(xmlTransformedIn, "Gateway config file '" + configFileName + "' post XSL transformation", LOGGER); } try { config = GatewayConfigDocument.Factory.parse(xmlTransformedIn, parseOptions); } catch (Exception e) { try { if (xmlInjectedFuture.get()) { if (xmlTransformedFuture.get()) { throw e; } } } catch (Exception n) { xmlParseErrors.add("Invalid XML: " + getRootCause(n).getMessage()); } } finally { xmlInjectedFuture.cancel(true); xmlInjectedExecutor.shutdownNow(); xmlTransformedFuture.cancel(true); xmlTransformedExecutor.shutdownNow(); } } validateGatewayConfig(config, xmlParseErrors); if (LOGGER.isDebugEnabled()) { LOGGER.debug("parsed " + " gateway config file '" + configFileName + "' in [" + (System.currentTimeMillis() - time) + " ms]"); } return config; } GatewayConfigParser();  GatewayConfigParser(Properties configuration); GatewayConfigDocument parse(final File configFile);  }