List of usage examples for java.util.logging Level ALL
Level ALL
To view the source code for java.util.logging Level ALL.
Click Source Link
From source file:pl.otros.logview.gui.LogViewMainFrame.java
/** * @param args porgram CLI arguments/*w w w.ja va2 s .c o m*/ * @throws InitializationException * @throws InvocationTargetException * @throws InterruptedException */ public static void main(final String[] args) throws InitializationException, InterruptedException, InvocationTargetException { if (args.length > 0 && "-batch".equals(args[0])) { try { String[] batchArgs = new String[args.length - 1]; System.arraycopy(args, 1, batchArgs, 0, batchArgs.length); BatchProcessor.main(batchArgs); } catch (IOException e) { System.err.println("Error during batch processing: " + e.getMessage()); e.printStackTrace(); } catch (ConfigurationException e) { System.err.println("Error during batch processing: " + e.getMessage()); e.printStackTrace(); } return; } SingleInstanceRequestResponseDelegate singleInstanceRequestResponseDelegate = SingleInstanceRequestResponseDelegate .getInstance(); singleInstance = SingleInstance.request("OtrosLogViewer", singleInstanceRequestResponseDelegate, singleInstanceRequestResponseDelegate, args); if (singleInstance == null) { LOGGER.info("OtrosLogViewer is already running, params send using requestAction"); System.exit(0); } GuiJulHandler handler = new GuiJulHandler(); handler.setLevel(Level.ALL); Logger olvLogger = Logger.getLogger("pl.otros.logview"); olvLogger.setLevel(Level.ALL); olvLogger.addHandler(handler); LOGGER.info("Starting application"); OtrosSplash.setMessage("Starting application"); OtrosSplash.setMessage("Loading configuration"); final XMLConfiguration c = getConfiguration("config.xml"); if (!c.containsKey(ConfKeys.UUID)) { c.setProperty(ConfKeys.UUID, UUID.randomUUID().toString()); } IconsLoader.loadIcons(); OtrosSplash.setMessage("Loading icons"); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { try { OtrosSplash.setMessage("Loading L&F"); String lookAndFeel = c.getString("lookAndFeel", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); LOGGER.config("Initializing look and feelL: " + lookAndFeel); PlasticLookAndFeel.setTabStyle(Plastic3DLookAndFeel.TAB_STYLE_METAL_VALUE); UIManager.setLookAndFeel(lookAndFeel); } catch (Throwable e1) { LOGGER.warning("Cannot initialize LookAndFeel: " + e1.getMessage()); } try { final DataConfiguration c1 = new OtrosConfiguration(c); final LogViewMainFrame mf = new LogViewMainFrame(c1); // mf.exitAction was instantiated in the constructor (previous line) // Not sure retrieving this from most appropriate Apache config // object. mf.exitAction.setConfirm(c.getBoolean("generalBehavior.confirmExit", true)); /* TODO: Implement User Preferences screen or checkbox on exit widget * that will update the same config object something like: * c.setProperty("generalBehavior.confirmExit", newValue); */ mf.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { c.setProperty("gui.state", mf.getExtendedState()); if (mf.getExtendedState() == Frame.NORMAL) { c.setProperty("gui.width", mf.getWidth()); c.setProperty("gui.height", mf.getHeight()); } } @Override public void componentMoved(ComponentEvent e) { c.setProperty("gui.location.x", mf.getLocation().x); c.setProperty("gui.location.y", mf.getLocation().y); } }); mf.addWindowListener(mf.exitAction); SingleInstanceRequestResponseDelegate.openFilesFromStartArgs(mf.otrosApplication, Arrays.asList(args), mf.otrosApplication.getAppProperties().getCurrentDir()); } catch (InitializationException e) { LOGGER.log(Level.SEVERE, "Cannot initialize main frame", e); } } }); }
From source file:com.izforge.izpack.util.LogUtils.java
public static void loadConfiguration(final Properties configuration) throws IOException { if (OVERRIDE) { LogManager manager = LogManager.getLogManager(); // Merge global logging properties InputStream baseResourceStream = null; try {//from ww w. j a v a 2s. co m baseResourceStream = LogUtils.class.getResourceAsStream(LOGGING_BASE_CONFIGURATION); final Properties baseProps = new Properties(); baseProps.load(baseResourceStream); mergeLoggingConfiguration(configuration, baseProps); } finally { IOUtils.closeQuietly(baseResourceStream); } boolean mkdirs = false; String pattern = null; if (configuration.getProperty("handlers") != null && configuration.getProperty("handlers").contains(FILEHANDLER_CLASSNAME) && manager.getProperty("handlers").contains(FILEHANDLER_CLASSNAME)) { // IzPack maintains just one log file, don't override the existing handler type of it. // Special use case: Command line argument -logfile "wins" over the <log-file> tag. // Assumption at the moment for optimization: Just FileHandler is used for configurations from install.xml. return; } for (String key : configuration.stringPropertyNames()) { if (key.equals(FILEHANDLER_CLASSNAME + ".pattern")) { // Workaround for not normalized file paths, for example ${INSTALL_PATH}/../install_log/name.log // to get them working before creating ${INSTALL_PATH} in the // com.izforge.izpack.installer.unpacker.UnpackerBase.preUnpack phase // otherwise the FileHandler will fail when opening files already in constructor and not recover from that. pattern = FilenameUtils.normalize(configuration.getProperty(key)); configuration.setProperty(key, pattern); } else if (key.equals(FILEHANDLER_CLASSNAME + ".mkdirs")) { // This key goes beyond the capabilities of java.util.logging.FileHandler mkdirs = Boolean.parseBoolean(configuration.getProperty(key)); configuration.remove(key); } } if (mkdirs && pattern != null) { FileUtils.forceMkdirParent(new File(pattern)); } // Merge user settings compiled in final Properties userProps = new Properties(); InputStream userPropsStream = LogUtils.class .getResourceAsStream(ResourceManager.getInstallLoggingConfigurationResourceName()); try { if (userPropsStream != null) { userProps.load(userPropsStream); for (String userPropName : userProps.stringPropertyNames()) { if (userPropName.endsWith(".level") && !userPropName.startsWith(FILEHANDLER_CLASSNAME)) { String level = userProps.getProperty(userPropName); if (level != null) { configuration.setProperty(userPropName, level); } } } } } finally { IOUtils.closeQuietly(userPropsStream); } InputStream defaultResourceStream = null; try { defaultResourceStream = LogUtils.class.getResourceAsStream(LOGGING_CONFIGURATION); final Properties defaultProps = new Properties(); defaultProps.load(defaultResourceStream); mergeLoggingConfiguration(configuration, defaultProps); } finally { IOUtils.closeQuietly(defaultResourceStream); } if (Debug.isDEBUG()) { configuration.setProperty(FILEHANDLER_CLASSNAME + ".level", Level.FINE.toString()); configuration.setProperty(ConsoleHandler.class.getName() + ".level", Level.FINE.toString()); } // Set general log level which acts as filter in front of all handlers String fileLevelName = configuration.getProperty(FILEHANDLER_CLASSNAME + ".level", Level.ALL.toString()); Level fileLevel = Level.ALL; if (fileLevelName != null) { fileLevel = Level.parse(fileLevelName); } String consoleLevelName = configuration.getProperty(CONSOLEHANDLER_CLASSNAME + ".level", Level.INFO.toString()); Level consoleLevel = Level.INFO; if (consoleLevelName != null) { consoleLevel = Level.parse(consoleLevelName); } configuration.setProperty(".level", (fileLevel.intValue() < consoleLevel.intValue()) ? fileLevelName : consoleLevelName); final PipedOutputStream out = new PipedOutputStream(); final PipedInputStream in = new PipedInputStream(out); try { new Thread(new Runnable() { public void run() { try { configuration.store(out, null); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(out); } } }).start(); manager.readConfiguration(in); } finally { IOUtils.closeQuietly(in); } } }
From source file:org.jevis.ftpdatasource.FTPDataSource.java
@Override public List<InputStream> sendSampleRequest(JEVisObject channel) { List<InputStream> answerList = new ArrayList<InputStream>(); try {// w w w . j av a 2 s. c o m if (_ssl) { System.out.println("ftps connection"); _fc = new FTPSClient(); } else { _fc = new FTPClient(); } // _fc.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true)); if (_connectionTimeout != 0) { _fc.setConnectTimeout(_connectionTimeout.intValue() * 1000); } if (_readTimeout != 0) { _fc.setDataTimeout(_readTimeout.intValue() * 1000); } _fc.connect(_serverURL, _port); // _fc.setFileType(FTP.BINARY_FILE_TYPE, FTP.BINARY_FILE_TYPE); if (_fc.login(_userName, _password) == false) { org.apache.log4j.Logger.getLogger(this.getClass().getName()).log(org.apache.log4j.Level.ERROR, "No Login possible"); // throw new FetchingException(_id, FetchingExceptionType.CONNECTION_ERROR); } // _fc.setFileType(FTP.BINARY_FILE_TYPE); // _fc.setFileTransferMode(FTP.COMPRESSED_TRANSFER_MODE); _fc.setBufferSize(1024000); _fc.setUseEPSVwithIPv4(false); _fc.enterLocalPassiveMode(); InputStream answer = null; JEVisClass channelClass = channel.getJEVisClass(); JEVisType pathType = channelClass.getType(DataCollectorTypes.Channel.FTPChannel.PATH); String filePath = DatabaseHelper.getObjectAsString(channel, pathType); JEVisType readoutType = channelClass.getType(DataCollectorTypes.Channel.FTPChannel.LAST_READOUT); DateTime lastReadout = DatabaseHelper.getObjectAsDate(channel, readoutType, DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")); // String filePath = dp.getFilePath(); org.apache.log4j.Logger.getLogger(this.getClass().getName()).log(org.apache.log4j.Level.ALL, "SendSampleRequest2"); List<String> fileNames = DataSourceHelper.getFTPMatchedFileNames(_fc, lastReadout, filePath); // String currentFilePath = Paths.get(filePath).getParent().toString(); org.apache.log4j.Logger.getLogger(this.getClass().getName()).log(org.apache.log4j.Level.ALL, "Nr of Matched Files " + fileNames.size()); for (String fileName : fileNames) { org.apache.log4j.Logger.getLogger(this.getClass().getName()).log(org.apache.log4j.Level.ALL, "FileInputName: " + fileName); ByteArrayOutputStream out = new ByteArrayOutputStream(); // String query = Paths.get(fileName); org.apache.log4j.Logger.getLogger(this.getClass().getName()).log(org.apache.log4j.Level.ALL, "FTPQuery " + fileName); boolean retrieveFile = _fc.retrieveFile(fileName, out); org.apache.log4j.Logger.getLogger(this.getClass().getName()).log(org.apache.log4j.Level.ALL, "Request status: " + retrieveFile); InputStream inputStream = new ByteArrayInputStream(out.toByteArray()); answer = new BufferedInputStream(inputStream); // InputHandler inputConverter = InputHandlerFactory.getInputConverter(answer); // inputConverter.setFilePath(fileName); answerList.add(answer); } } catch (JEVisException ex) { java.util.logging.Logger.getLogger(FTPDataSource.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(FTPDataSource.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { System.out.println(ex.getMessage()); } if (answerList.isEmpty()) { org.apache.log4j.Logger.getLogger(this.getClass().getName()).log(org.apache.log4j.Level.ERROR, "Cant get any data from the device"); } return answerList; }
From source file:org.deviceconnect.android.manager.DConnectMessageService.java
@Override public void onCreate() { super.onCreate(); if (BuildConfig.DEBUG) { AndroidHandler handler = new AndroidHandler("dconnect.manager"); handler.setFormatter(new SimpleFormatter()); handler.setLevel(Level.ALL); mLogger.addHandler(handler);/*from w w w . j a v a2s. c o m*/ mLogger.setLevel(Level.ALL); } else { mLogger.setLevel(Level.OFF); } // ??? EventManager.INSTANCE.setController(new MemoryCacheController()); // Local OAuth?? LocalOAuth2Main.initialize(getApplicationContext()); // DConnect mSettings = DConnectSettings.getInstance(); mSettings.load(this); // ? mFileMgr = new FileManager(this); // ???Local OAuth mLocalOAuth = new DConnectLocalOAuth(this); // ???? mPluginMgr = new DevicePluginManager(this, mDConnectDomain); mPluginMgr.setEventListener(this); // ? addProfile(new AuthorizationProfile()); addProfile(new DConnectAvailabilityProfile()); addProfile(new DConnectServiceDiscoveryProfile(this, mPluginMgr)); addProfile(new DConnectFilesProfile(this)); addProfile(new DConnectSystemProfile(this, mPluginMgr)); // dConnect Manager???????????? setDeliveryProfile(new DConnectDeliveryProfile(mPluginMgr, mLocalOAuth, mSettings.requireOrigin())); }
From source file:com.machinepublishers.jbrowserdriver.diagnostics.Test.java
private void doTests() { JBrowserDriver driver = null;/* ww w . jav a2 s. co m*/ Thread shutdownHook = null; try { HttpServer.launch(TEST_PORT_HTTP); final File cacheDir = Files.createTempDirectory("jbd_test_cache").toFile(); final File userDataDir = Files.createTempDirectory("jbd_test_userdata").toFile(); shutdownHook = new Thread(new Runnable() { @Override public void run() { FileUtils.deleteQuietly(cacheDir); FileUtils.deleteQuietly(userDataDir); } }); Runtime.getRuntime().addShutdownHook(shutdownHook); final String mainPage = "http://" + InetAddress.getLoopbackAddress().getHostAddress() + ":" + TEST_PORT_HTTP; final int ajaxWait = 150; final Settings.Builder builder = Settings.builder().processes(TEST_PORTS_RMI) .screen(new Dimension(1024, 768)).logger(null).logJavascript(true).ajaxWait(ajaxWait) .cacheDir(cacheDir).cache(true).ignoreDialogs(false); driver = new JBrowserDriver(builder.build()); /* * Load a page */ driver.get(mainPage); test(driver.getStatusCode() == 200); long initialRequestId = HttpServer.previousRequestId(); /* * Load page from cache */ driver.get(mainPage); test(driver.getStatusCode() == 200); test(HttpServer.previousRequestId() == initialRequestId); boolean viaHeader = false; for (String line : HttpServer.previousRequest()) { if (line.toLowerCase().startsWith("via:")) { viaHeader = true; break; } } test(!viaHeader); /* * Driver reset */ driver.reset(); driver.get(mainPage); test(driver.getStatusCode() == 200); test(HttpServer.previousRequestId() == initialRequestId); driver.reset(builder.cacheDir(null).build()); driver.get(mainPage); test(driver.getStatusCode() == 200); test(HttpServer.previousRequestId() != initialRequestId); /* * Javascript logs */ int messages = 0; for (LogEntry entry : driver.manage().logs().get("javascript").filter(Level.ALL)) { ++messages; test(!StringUtils.isEmpty(entry.getMessage())); } test(messages == 3); /* * User-data directory */ driver.findElement(By.id("populate-local-storage")).click(); driver.findElement(By.id("load-from-local-storage")).click(); test("test-value".equals(driver.findElement(By.id("local-storage-value-holder")).getText())); driver.get(mainPage); driver.findElement(By.id("load-from-local-storage")).click(); test("test-value".equals(driver.findElement(By.id("local-storage-value-holder")).getText())); driver.reset(); driver.get(mainPage); driver.findElement(By.id("load-from-local-storage")).click(); test("".equals(driver.findElement(By.id("local-storage-value-holder")).getText())); driver.reset(builder.userDataDirectory(userDataDir).build()); driver.get(mainPage); driver.findElement(By.id("populate-local-storage")).click(); driver.findElement(By.id("load-from-local-storage")).click(); test("test-value".equals(driver.findElement(By.id("local-storage-value-holder")).getText())); driver.reset(); driver.get(mainPage); driver.findElement(By.id("load-from-local-storage")).click(); test("test-value".equals(driver.findElement(By.id("local-storage-value-holder")).getText())); /* * Select DOM elements */ test("test-data-attr".equals(driver.findElement(By.id("divtext1")).getAttribute("data-selected"))); test(driver.findElement(By.id("divtext1")).getAttribute("undefinedattr") == null); test(driver.findElement(By.id("divtext1")).getAttribute("innerText").equals("test1")); test(driver.findElements(By.name("divs")).size() == 2); test(driver.findElements(By.name("divs")).get(1).getAttribute("innerText").equals("test2")); test(driver.findElementByClassName("divclass").getAttribute("id").equals("divtext1")); test(driver.findElementsByClassName("divclass").get(1).getAttribute("id").equals("divtext2")); test(driver.findElementByCssSelector("#divtext1").getAttribute("id").equals("divtext1")); test(driver.findElementsByCssSelector("html > *").get(1).getAttribute("id").equals("testbody")); test(driver.findElementById("divtext1").getTagName().equals("div")); test(driver.findElementsById("divtext1").get(0).getTagName().equals("div")); test(driver.findElementByLinkText("anchor").getAttribute("id").equals("anchor1")); test(driver.findElementsByLinkText("anchor").get(1).getAttribute("id").equals("anchor2")); test(driver.findElementByName("divs").getAttribute("id").equals("divtext1")); test(driver.findElementsByName("divs").get(1).getAttribute("id").equals("divtext2")); test(driver.findElementByPartialLinkText("anch").getAttribute("id").equals("anchor1")); test(driver.findElementsByPartialLinkText("anch").get(1).getAttribute("id").equals("anchor2")); test(driver.findElementByTagName("div").getAttribute("id").equals("divtext1")); test(driver.findElementsByTagName("div").get(1).getAttribute("id").equals("divtext2")); test(driver.findElementByXPath("//*[@id='divtext1']").getAttribute("id").equals("divtext1")); test(driver.findElementByTagName("body").findElement(By.xpath("//*[@id='divtext1']")).getAttribute("id") .equals("divtext1")); test(driver.findElementsByXPath("//html/*").get(1).getAttribute("id").equals("testbody")); test(driver.findElement(By.xpath("//a[contains(@href,'1')]")).getAttribute("id").equals("anchor1")); test(driver.findElementsByXPath("//a[contains(@href,'!!!')]").isEmpty()); test(driver.findElementsByClassName("xx").isEmpty()); test(driver.findElementsByTagName("xx").isEmpty()); test(driver.findElementsByCssSelector("#xx").isEmpty()); Throwable error = null; try { driver.findElementByTagName("xx"); } catch (NoSuchElementException e) { error = e; } test(error != null); error = null; try { driver.findElementByCssSelector("#xx"); } catch (NoSuchElementException e) { error = e; } test(error != null); error = null; try { driver.findElementsByXPath("!!!"); } catch (WebDriverException e) { error = e; } test(error != null); error = null; try { driver.findElement(By.id("divtext1")).findElements(By.cssSelector("???")); } catch (WebDriverException e) { error = e; } test(error != null); /* * WebElement Equals/HashCode */ test(driver.findElements(By.name("divs")).get(0).equals(driver.findElements(By.name("divs")).get(0))); test(driver.findElements(By.name("divs")).get(0).hashCode() == driver.findElements(By.name("divs")) .get(0).hashCode()); /* * Typing text */ driver.findElement(By.id("text-input")).sendKeys("testing"); driver.findElement(By.id("text-input")).sendKeys(""); test(driver.findElement(By.id("text-input")).getAttribute("value").equals("testing")); driver.findElement(By.id("text-input")).sendKeys(JBrowserDriver.KEYBOARD_DELETE); test(driver.findElement(By.id("text-input")).getAttribute("value") == null); driver.findElement(By.id("text-input")).sendKeys("testing"); test(driver.findElement(By.id("text-input")).getAttribute("value").equals("testing")); driver.findElement(By.id("text-input")).clear(); test(driver.findElement(By.id("text-input")).getAttribute("value") == null); /* * Clicking on elements */ test(!driver.findElement(By.id("testoption2")).isSelected()); driver.findElement(By.id("testoption2")).click(); test(driver.findElement(By.id("testoption2")).isSelected()); driver.findElement(By.id("testoption1")).click(); test(driver.findElement(By.id("testoption1")).isSelected()); driver.findElement(By.id("anchor5")).click(); test("anchor clicked".equals(driver.findElement(By.id("testspan")).getText())); /* * Execute javascript */ test(((WebElement) driver.executeScript("return arguments[0];", driver.findElement(By.id("divtext1")))) .getAttribute("innerText").equals("test1")); test(((WebElement) driver.executeScript("return arguments[0].parentNode;", driver.findElement(By.id("divtext1")))).getTagName().equals("body")); test(((WebElement) ((JavascriptExecutor) driver.findElement(By.id("divtext1"))) .executeAsyncScript("arguments[0](this);")).getAttribute("innerText").equals("test1")); test((driver.executeAsyncScript("arguments[1](arguments[0].innerText);", driver.findElement(By.id("divtext1")))).equals("test1")); Map<String, Object> map = (Map<String, Object>) driver.executeScript("return {" + "key1:['value1','value2','value3'], " + "key2:5," + "key3:function(){return 'testing';}, " + "key4:undefined, key5:null, key6:1/0, key7:0/0, key8:'', key9:[], key10:{}, key11:[{},{}]," + "key12:document.getElementById('divtext1'), " + "key13:document.getElementsByName('divs'), " + "key14:[document.getElementById('divtext1'),document.getElementsByName('divs'),{subkey1:'subval1'}]};"); test(map.size() == 14); test(((List) map.get("key1")).size() == 3); test(((List) map.get("key1")).get(2).equals("value3")); test(((List) map.get("key1")).get(2) instanceof String); test(map.get("key2").equals(new Long(5))); test("function () {return 'testing';}".equals(map.get("key3")) || "function (){return 'testing';}".equals(map.get("key3"))); test(map.get("key4") == null); test(map.get("key5") == null); test(Double.isInfinite(((Double) map.get("key6")).doubleValue())); test(Double.isNaN(((Double) map.get("key7")).doubleValue())); test("".equals(map.get("key8"))); test(map.get("key9") instanceof List); test(map.get("key10") instanceof Map); test(((List) map.get("key11")).size() == 2); test(((Map) ((List) map.get("key11")).get(1)).isEmpty()); test("test1".equals(((WebElement) map.get("key12")).getAttribute("innerText"))); test(((List<WebElement>) map.get("key13")).size() == 2); test(((List<WebElement>) map.get("key13")).get(1).getAttribute("innerText").equals("test2")); test(((List) map.get("key14")).size() == 3); test(((List) ((List) map.get("key14")).get(1)).size() == 2); test(((WebElement) ((List) ((List) map.get("key14")).get(1)).get(1)).getAttribute("innerText") .equals("test2")); test(((Map) ((List) map.get("key14")).get(2)).size() == 1); test("subval1".equals(((Map) ((List) map.get("key14")).get(2)).get("subkey1"))); test(((List) driver.executeScript("return [];")).isEmpty()); test(((Map) driver.executeScript("return {};")).isEmpty()); error = null; try { driver.executeScript("invalid.execute()"); } catch (WebDriverException e) { error = e; } test(error != null); /* * DOM element properties */ WebElement element = driver.findElement(By.id("divtext1")); Point point = element.getLocation(); test(point.getX() > 0); test(point.getY() > 0); Dimension dimension = element.getSize(); test(dimension.width > 0); test(dimension.height > 0); Rectangle rect = element.getRect(); test(rect.x == point.getX()); test(rect.y == point.getY()); test(rect.width == dimension.getWidth()); test(rect.height == dimension.getHeight()); test("Testing\ntext.".equals(driver.findElement(By.id("text-node1")).getText())); test("".equals(driver.findElement(By.id("text-node2")).getText())); test("".equals(driver.findElement(By.id("text-node3")).getText())); List<WebElement> options = driver.findElementsByCssSelector("#testselect option"); test(options.size() == 2); test(options.get(0).isSelected()); test(!options.get(1).isSelected()); test(driver.findElementById("checkbox1").isSelected()); test(!driver.findElementById("checkbox2").isSelected()); /* * Cookie manager */ driver.manage().addCookie(new Cookie("testname", "testvalue")); Cookie cookie = driver.manage().getCookieNamed("testname"); test(cookie.getValue().equals("testvalue")); test(InetAddress.getLoopbackAddress().getHostAddress().equals(cookie.getDomain())); /* * Screenshots */ test(driver.getScreenshotAs(OutputType.BYTES).length > 0); /* * File Input Type */ driver.findElement(By.id("upload")).sendKeys("some-file"); test("event-test".equals(driver.findElement(By.id("file-input-onchange")).getText())); test(driver.findElement(By.id("upload")).getAttribute("value").endsWith("some-file")); /* * Javascript alerts */ driver.findElement(By.tagName("button")).click(); test(driver.switchTo().alert().getText().equals("test-alert")); driver.switchTo().alert().dismiss(); test(driver.switchTo().alert().getText().equals("test-confirm")); driver.switchTo().alert().dismiss(); test(driver.switchTo().alert().getText().equals("test-prompt")); driver.switchTo().alert().sendKeys("test-input"); driver.switchTo().alert().accept(); test(driver.findElement(By.id("testspan")).getAttribute("innerHTML").equals("test-input")); /* * Request headers */ List<String> request = HttpServer.previousRequest(); if (TEST_PORT_HTTP != 443 && TEST_PORT_HTTP != 80) { test(request.get(1).endsWith(":" + TEST_PORT_HTTP)); } test(request.size() > 1); Set<String> headers = new HashSet<String>(); for (String line : request) { if (line.contains(":")) { headers.add(line.split(":")[0].toLowerCase()); } } test(request.size() - 2 == headers.size()); /* * HTTP Post */ driver.findElement(By.id("form-submit")).click(); test(driver.getStatusCode() == 201); test("form-field=test-form-value" .equals(HttpServer.previousRequest().get(HttpServer.previousRequest().size() - 1))); /* * Frames */ driver.switchTo().frame(driver.findElementByTagName("iframe")); test(driver.findElementById("iframebody") != null); driver.switchTo().parentFrame(); test(driver.findElementById("testbody") != null); driver.switchTo().frame(0); test(driver.findElementById("iframebody") != null); driver.switchTo().defaultContent(); driver.switchTo().frame("testiframe"); test(driver.findElementById("iframebody") != null); driver.get(mainPage); test(driver.getPageSource() != null); driver.switchTo().frame(driver.findElementByTagName("iframe")); test(driver.findElementById("iframebody") != null); driver.switchTo().parentFrame(); driver.findElement(By.id("anchor3")).click(); test(driver.getPageSource() != null); driver.switchTo().frame(driver.findElementByTagName("iframe")); driver.findElement(By.id("iframe-anchor")).click(); //TODO iframe coord offset needed on any other methods? driver.pageWait(); test(HttpServer.previousRequest().get(0).startsWith("GET /iframe.htm?param=fromiframe")); driver.get(mainPage); driver.switchTo().frame(driver.findElementByTagName("iframe")); Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id("iframe-anchor"))); actions.click(); actions.build().perform(); driver.pageWait(); test(HttpServer.previousRequest().get(0).startsWith("GET /iframe.htm?param=fromiframe")); driver.get(mainPage); driver.switchTo().frame(driver.findElementByTagName("iframe")); driver.getMouse().click(((Locatable) driver.findElement(By.id("iframe-anchor"))).getCoordinates()); driver.getMouse().mouseMove(((Locatable) driver.findElement(By.id("iframe-anchor"))).getCoordinates(), 5, 5); driver.pageWait(); test(HttpServer.previousRequest().get(0).startsWith("GET /iframe.htm?param=fromiframe")); //TODO fingerprinting //System.out.println(driver.findElement(By.id("iframe-useragent")).getAttribute("innerHTML")); //System.out.println(driver.findElement(By.id("iframe-nested-useragent")).getAttribute("innerHTML")); /* * Redirects and cookies */ driver.get(mainPage + "/redirect/site1#testfragment"); test(HttpServer.previousRequestId() != initialRequestId); test(driver.getStatusCode() == 200); test(driver.getCurrentUrl().endsWith("/redirect/site2#testfragment")); cookie = driver.manage().getCookieNamed("JSESSIONID"); test(cookie.getValue().equals("ABC123")); test(InetAddress.getLoopbackAddress().getHostAddress().equals(cookie.getDomain())); /* * Cookies set by Javascript */ test("jsCookieValue1".equals(driver.manage().getCookieNamed("jsCookieName1").getValue())); test("jsCookieValue2".equals(driver.manage().getCookieNamed("jsCookieName2").getValue())); test("jsCookieValue3".equals(driver.manage().getCookieNamed("jsCookieName3").getValue())); test("jsCookieValue4".equals(driver.manage().getCookieNamed("jsCookieName4").getValue())); /* * Window size and position */ driver.manage().window().setSize(new Dimension(5000, 5000)); test(driver.manage().window().getSize().getWidth() == 1024); test(driver.manage().window().getSize().getHeight() == 768); driver.manage().window().setSize(new Dimension(800, 600)); test(driver.manage().window().getSize().getWidth() == 800); test(driver.manage().window().getSize().getHeight() == 600); driver.manage().window().setPosition(new Point(5000, 5000)); test(driver.manage().window().getPosition().getX() == 224); test(driver.manage().window().getPosition().getY() == 168); driver.manage().window().setPosition(new Point(20, 50)); test(driver.manage().window().getPosition().getX() == 20); test(driver.manage().window().getPosition().getY() == 50); driver.manage().window().maximize(); test(driver.manage().window().getPosition().getX() == 0); test(driver.manage().window().getPosition().getY() == 0); test(driver.manage().window().getSize().getWidth() == 1024); test(driver.manage().window().getSize().getHeight() == 768); driver.manage().window().setSize(new Dimension(800, 600)); driver.manage().window().setPosition(new Point(20, 50)); driver.manage().window().fullscreen(); test(driver.manage().window().getPosition().getX() == 0); test(driver.manage().window().getPosition().getY() == 0); test(driver.manage().window().getSize().getWidth() == 1024); test(driver.manage().window().getSize().getHeight() == 768); driver.manage().window().fullscreen(); test(driver.manage().window().getPosition().getX() == 20); test(driver.manage().window().getPosition().getY() == 50); test(driver.manage().window().getSize().getWidth() == 800); test(driver.manage().window().getSize().getHeight() == 600); driver.manage().window().setSize(new Dimension(400, 200)); driver.manage().window().setPosition(new Point(10, 30)); test(driver.manage().window().getPosition().getX() == 10); test(driver.manage().window().getPosition().getY() == 30); test(driver.manage().window().getSize().getWidth() == 400); test(driver.manage().window().getSize().getHeight() == 200); driver.manage().window().setSize(new Dimension(1024, 768)); test(driver.manage().window().getPosition().getX() == 0); test(driver.manage().window().getPosition().getY() == 0); test(driver.manage().window().getSize().getWidth() == 1024); test(driver.manage().window().getSize().getHeight() == 768); /* * Element visibility */ test(driver.findElement(By.id("iframe-anchor")).isDisplayed()); test(!driver.findElement(By.id("anchor-visibility-hidden")).isDisplayed()); test(!driver.findElement(By.id("anchor-display-none")).isDisplayed()); error = null; try { driver.findElement(By.id("anchor-visibility-hidden")).click(); } catch (ElementNotVisibleException e) { error = e; } test(error != null); error = null; try { driver.findElement(By.id("anchor-display-none")).click(); } catch (ElementNotVisibleException e) { error = e; } test(error != null); /* * Operations on elements that no longer exist */ WebElement body = driver.findElement(By.tagName("body")); test(!StringUtils.isEmpty(body.getAttribute("outerHTML"))); driver.get("about:blank"); error = null; try { body.getAttribute("outerHTML"); } catch (StaleElementReferenceException e) { error = e; } test(error != null); /* * Timeouts */ driver.manage().timeouts().pageLoadTimeout(1, TimeUnit.MILLISECONDS); error = null; try { driver.get(mainPage + "/wait-forever"); } catch (TimeoutException e) { error = e; } test(error != null); } catch (Throwable t) { outputError(testLabel("failed", curTest + 1, t)); } finally { try { driver.quit(); } catch (Throwable t) { outputError(toString(t)); } try { HttpServer.stop(); } catch (Throwable t) { outputError(toString(t)); } try { Runtime.getRuntime().removeShutdownHook(shutdownHook); shutdownHook.run(); } catch (Throwable t) { } } }
From source file:org.socraticgrid.presentationservices.resources.BaseResource.java
protected boolean checkApiCaller(String requestStr) { Logger.getLogger(BaseResource.class.getName()).setLevel(Level.ALL); getLogger().info("chekcAPI - req: " + requestStr); String strippedRequest = ""; try {/*w w w .j a va 2 s .co m*/ requestStr = URLDecoder.decode(requestStr, "UTF-8"); if (getProperty("checkApiRequests").equalsIgnoreCase("true")) { //actually check the api against the sha1 salt //first step it to bust up the queryString in the request. //fail if queryString is not right //else bust the incomming string into fields split on the ampersand //if it's checksum= field save off the actual checksum and toss the field away //else put the querystring back minus the checksum= pair if ((requestStr == null) || (requestStr.indexOf("checksum") < 0)) return false; else { String checksum = ""; String[] fields = requestStr.split("&"); for (int i = 0; i < fields.length; i++) { String string = fields[i]; System.out.println("fileds" + i + "--> " + string); if (string.indexOf("checksum=") > -1) checksum = string.substring(8); else { if (strippedRequest.equals("")) strippedRequest = string; else strippedRequest = strippedRequest + "&" + string; } } //remove the leading equalsign //if (checksum.startsWith("=")) checksum = checksum.substring(1); Logger.getLogger(BaseResource.class.getName()).log(Level.FINEST, "requestChecksum: " + checksum); Logger.getLogger(BaseResource.class.getName()).log(Level.FINEST, "strippedRequest: " + strippedRequest); String cs = getHash(strippedRequest, getProperty("apiSalt")); Logger.getLogger(BaseResource.class.getName()).log(Level.FINEST, "cs: " + cs); if ((cs == null) || (cs.equals(checksum) == false)) { Logger.getLogger(BaseResource.class.getName()).log(Level.INFO, "checksumError: checksum did not pass security check, request will be rejected: " + strippedRequest); return false; } Logger.getLogger(BaseResource.class.getName()).log(Level.INFO, "checksum ok: passed security check: " + strippedRequest); return true; } } else return true; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:org.pentaho.platform.plugin.action.eclipsebirt.BirtSystemListener.java
private IReportEngine createBIRTEngine() { try {/*from ww w . ja v a 2 s. co m*/ // Get the global settings for the BIRT engine from our system settings String birtHome = PentahoSystem.getApplicationContext().getSolutionPath("system/BIRT"); //$NON-NLS-1$ birtHome = birtHome.replaceAll("\\\\.\\\\", "\\\\"); //$NON-NLS-1$ //$NON-NLS-2$ String birtResourcePath = PentahoSystem.getApplicationContext() .getSolutionPath("system/BIRT/resources"); //$NON-NLS-1$ birtResourcePath = birtResourcePath.replaceAll("\\\\.\\\\", "\\\\"); //$NON-NLS-1$//$NON-NLS-2$ if (PentahoSystem.debug) { Logger.debug(BirtSystemListener.class.getName(), Messages.getString("BIRT.DEBUG_BIRT_HOME", birtHome)); //$NON-NLS-1$ } // Create an appropriate Config object EngineConfig config = new EngineConfig(); config.setEngineHome(birtHome); // Configuring where BIRT engine is installed config.setResourcePath(birtResourcePath); // Set the directory where the BIRT log files will go String logDest = PentahoSystem.getApplicationContext().getFileOutputPath("system/logs/BIRT"); //$NON-NLS-1$ // Set the logging level int loggingLevel = Logger.getLogLevel(); if (loggingLevel == ILogger.TRACE) { config.setLogConfig(logDest, Level.ALL); } else if (loggingLevel == ILogger.DEBUG) { config.setLogConfig(logDest, Level.FINE); } else if (loggingLevel == ILogger.INFO) { config.setLogConfig(logDest, Level.INFO); } else if (loggingLevel == ILogger.WARN) { config.setLogConfig(logDest, Level.WARNING); } else if (loggingLevel == ILogger.ERROR) { config.setLogConfig(logDest, Level.SEVERE); } else if (loggingLevel == ILogger.FATAL) { config.setLogConfig(logDest, Level.SEVERE); } // Register new image handler // Bart Maertens, 14/11/2007: Replace HTMLEmitterConfig with HTMLRenderOption. // HTMLEmitterConfig emitterConfig = new HTMLEmitterConfig(); // emitterConfig.setActionHandler(new HTMLActionHandler()); // emitterConfig.setImageHandler(new HTMLServerImageHandler()); // config.getEmitterConfigs().put(RenderOptionBase.OUTPUT_FORMAT_HTML, emitterConfig); IRenderOption option = new RenderOption(); option.setOutputFormat("html"); //$NON-NLS-1$ HTMLRenderOption renderOption = new HTMLRenderOption(option); renderOption.setImageDirectory(imageDirectory); config.getEmitterConfigs().put(IRenderOption.OUTPUT_FORMAT_HTML, renderOption); // Workaround for Eclipse bug 156877 String protocolHandler = System.getProperty("java.protocol.handler.pkgs"); //$NON-NLS-1$ if ((protocolHandler != null) && (protocolHandler.indexOf("org.jboss.net.protocol") != -1)) { //$NON-NLS-1$ StringTokenizer tok = new StringTokenizer(protocolHandler, "|"); //$NON-NLS-1$ StringBuffer newProtocolHandler = new StringBuffer(); String name; while (tok.hasMoreElements()) { name = tok.nextToken(); if (!name.equals("org.jboss.net.protocol")) { //$NON-NLS-1$ newProtocolHandler.append(name).append('|'); } } newProtocolHandler.setLength(Math.max(0, newProtocolHandler.length() - 1)); // chop the last '|' BirtSystemListener.workaroundProtocolHandler = System.setProperty("java.protocol.handler.pkgs", //$NON-NLS-1$ newProtocolHandler.toString()); } // End Workaround Platform.startup(config); IReportEngineFactory factory = (IReportEngineFactory) Platform .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY); IReportEngine engine = factory.createReportEngine(config); return engine; } catch (BirtException be) { BirtSystemListener.logger.error(null, be); Logger.error(BirtSystemListener.class.getName(), Messages.getErrorString("BIRT.ERROR_0008_INVALID_CONFIGURATION")); //$NON-NLS-1$ } return null; }
From source file:org.mili.core.logging.java.JavaAdapterTest.java
@Test public void shouldIsTraceEnabled() { log.setLevel(Level.FINEST); assertTrue(logger.isTraceEnabled()); log.setLevel(Level.ALL); assertTrue(logger.isTraceEnabled()); }
From source file:processing.app.Base.java
static public void initLogger() { Handler consoleHandler = new ConsoleLogger(); consoleHandler.setLevel(Level.ALL); consoleHandler.setFormatter(new LogFormatter("%1$tl:%1$tM:%1$tS [%4$7s] %2$s: %5$s%n")); Logger globalLogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); globalLogger.setLevel(consoleHandler.getLevel()); // Remove default Handler[] handlers = globalLogger.getHandlers(); for (Handler handler : handlers) { globalLogger.removeHandler(handler); }//from ww w . j a v a 2 s. c o m Logger root = Logger.getLogger(""); handlers = root.getHandlers(); for (Handler handler : handlers) { root.removeHandler(handler); } globalLogger.addHandler(consoleHandler); Logger.getLogger("cc.arduino.packages.autocomplete").setParent(globalLogger); Logger.getLogger("br.com.criativasoft.cpluslibparser").setParent(globalLogger); Logger.getLogger(Base.class.getPackage().getName()).setParent(globalLogger); }
From source file:org.ow2.mind.doc.Launcher.java
private static void initLogger() { final Handler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.ALL); logger.setLevel(Level.INFO);/*from w ww . j av a 2s.c o m*/ logger.setUseParentHandlers(false); logger.addHandler(consoleHandler); }