@Test public void validFileWithUserPara() throws Exception { File file = File.createTempFile("wollmuxTest", ".conf"); try (MockServerClient client = new MockServerClient("localhost", port); BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { writer.write(String.format("CONF_SERVER \"http: writer.newLine(); writer.write("USERNAME \"test.user\""); writer.flush(); client .when( HttpRequest.request().withMethod("POST").withBody(StringBody.subString("test.user"))) .respond(HttpResponse.response().withStatusCode(200) .withHeader(new Header("Content-Type", "application/json; charset=utf-8")) .withBody("DEFAULT_CONTEXT \"test_server_user\"")); ConfigThingy test = WollMuxFiles.parseWollMuxConf(file); assertEquals("test_server_user", test.getString("DEFAULT_CONTEXT", null), "Got wrong DEFAULT_CONTEXT"); } }
protected static ConfigThingy parseWollMuxConf(File wollMuxConfigFile) { wollmuxConf = new ConfigThingy(""); if (wollMuxConfigFile != null && wollMuxConfigFile.exists() && wollMuxConfigFile.isFile()) { try { wollmuxConf = new ConfigThingy("", wollMuxConfigFile.toURI().toURL()); String serverURI = wollmuxConf.getString("CONF_SERVER", null); if (serverURI != null) { String user = wollmuxConf.getString("USERNAME", System.getProperty("user.name")); HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder().uri(URI.create(serverURI)) .header("Content-Type", "application/json") .POST(BodyPublishers.ofString(("{ \"username\":\"" + user + "\"}"))) .timeout(Duration.ofSeconds(5)).build(); HttpResponse<String> response = client.send(request, BodyHandlers.ofString()); wollmuxConf = new ConfigThingy("", response.body()); } } catch (HttpTimeoutException ex) { LOGGER.error("Serverrespond takes more than 5 seconds", ex); } catch (Exception e) { LOGGER.error("", e); } } else { LOGGER.info(WOLLMUX_NOCONF); } return wollmuxConf; }
WollMuxFiles { protected static ConfigThingy parseWollMuxConf(File wollMuxConfigFile) { wollmuxConf = new ConfigThingy(""); if (wollMuxConfigFile != null && wollMuxConfigFile.exists() && wollMuxConfigFile.isFile()) { try { wollmuxConf = new ConfigThingy("", wollMuxConfigFile.toURI().toURL()); String serverURI = wollmuxConf.getString("CONF_SERVER", null); if (serverURI != null) { String user = wollmuxConf.getString("USERNAME", System.getProperty("user.name")); HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder().uri(URI.create(serverURI)) .header("Content-Type", "application/json") .POST(BodyPublishers.ofString(("{ \"username\":\"" + user + "\"}"))) .timeout(Duration.ofSeconds(5)).build(); HttpResponse<String> response = client.send(request, BodyHandlers.ofString()); wollmuxConf = new ConfigThingy("", response.body()); } } catch (HttpTimeoutException ex) { LOGGER.error("Serverrespond takes more than 5 seconds", ex); } catch (Exception e) { LOGGER.error("", e); } } else { LOGGER.info(WOLLMUX_NOCONF); } return wollmuxConf; } }
WollMuxFiles { protected static ConfigThingy parseWollMuxConf(File wollMuxConfigFile) { wollmuxConf = new ConfigThingy(""); if (wollMuxConfigFile != null && wollMuxConfigFile.exists() && wollMuxConfigFile.isFile()) { try { wollmuxConf = new ConfigThingy("", wollMuxConfigFile.toURI().toURL()); String serverURI = wollmuxConf.getString("CONF_SERVER", null); if (serverURI != null) { String user = wollmuxConf.getString("USERNAME", System.getProperty("user.name")); HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder().uri(URI.create(serverURI)) .header("Content-Type", "application/json") .POST(BodyPublishers.ofString(("{ \"username\":\"" + user + "\"}"))) .timeout(Duration.ofSeconds(5)).build(); HttpResponse<String> response = client.send(request, BodyHandlers.ofString()); wollmuxConf = new ConfigThingy("", response.body()); } } catch (HttpTimeoutException ex) { LOGGER.error("Serverrespond takes more than 5 seconds", ex); } catch (Exception e) { LOGGER.error("", e); } } else { LOGGER.info(WOLLMUX_NOCONF); } return wollmuxConf; } private  WollMuxFiles(); }
WollMuxFiles { protected static ConfigThingy parseWollMuxConf(File wollMuxConfigFile) { wollmuxConf = new ConfigThingy(""); if (wollMuxConfigFile != null && wollMuxConfigFile.exists() && wollMuxConfigFile.isFile()) { try { wollmuxConf = new ConfigThingy("", wollMuxConfigFile.toURI().toURL()); String serverURI = wollmuxConf.getString("CONF_SERVER", null); if (serverURI != null) { String user = wollmuxConf.getString("USERNAME", System.getProperty("user.name")); HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder().uri(URI.create(serverURI)) .header("Content-Type", "application/json") .POST(BodyPublishers.ofString(("{ \"username\":\"" + user + "\"}"))) .timeout(Duration.ofSeconds(5)).build(); HttpResponse<String> response = client.send(request, BodyHandlers.ofString()); wollmuxConf = new ConfigThingy("", response.body()); } } catch (HttpTimeoutException ex) { LOGGER.error("Serverrespond takes more than 5 seconds", ex); } catch (Exception e) { LOGGER.error("", e); } } else { LOGGER.info(WOLLMUX_NOCONF); } return wollmuxConf; } private  WollMuxFiles(); static boolean isDebugMode(); static boolean initLocalization(ConfigThingy config); static File getWollMuxDir(); static File getWollMuxConfFile(); static File getLosCacheFile(); static ConfigThingy getWollmuxConf(); static URL getDefaultContext(); static URL makeURL(String urlStr); static void determineDefaultContext(); static String getWollMuxConfLoggingMode(ConfigThingy config); static String dumpInfo(); static String dumpOOoConfiguration(String nodePath); static String dumpNode(Object element, String spaces); static void writeConfToFile(File file, ConfigThingy conf); }
WollMuxFiles { protected static ConfigThingy parseWollMuxConf(File wollMuxConfigFile) { wollmuxConf = new ConfigThingy(""); if (wollMuxConfigFile != null && wollMuxConfigFile.exists() && wollMuxConfigFile.isFile()) { try { wollmuxConf = new ConfigThingy("", wollMuxConfigFile.toURI().toURL()); String serverURI = wollmuxConf.getString("CONF_SERVER", null); if (serverURI != null) { String user = wollmuxConf.getString("USERNAME", System.getProperty("user.name")); HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder().uri(URI.create(serverURI)) .header("Content-Type", "application/json") .POST(BodyPublishers.ofString(("{ \"username\":\"" + user + "\"}"))) .timeout(Duration.ofSeconds(5)).build(); HttpResponse<String> response = client.send(request, BodyHandlers.ofString()); wollmuxConf = new ConfigThingy("", response.body()); } } catch (HttpTimeoutException ex) { LOGGER.error("Serverrespond takes more than 5 seconds", ex); } catch (Exception e) { LOGGER.error("", e); } } else { LOGGER.info(WOLLMUX_NOCONF); } return wollmuxConf; } private  WollMuxFiles(); static boolean isDebugMode(); static boolean initLocalization(ConfigThingy config); static File getWollMuxDir(); static File getWollMuxConfFile(); static File getLosCacheFile(); static ConfigThingy getWollmuxConf(); static URL getDefaultContext(); static URL makeURL(String urlStr); static void determineDefaultContext(); static String getWollMuxConfLoggingMode(ConfigThingy config); static String dumpInfo(); static String dumpOOoConfiguration(String nodePath); static String dumpNode(Object element, String spaces); static void writeConfToFile(File file, ConfigThingy conf);  }