Example usage for java.util.logging Logger getAnonymousLogger

List of usage examples for java.util.logging Logger getAnonymousLogger

Introduction

In this page you can find the example usage for java.util.logging Logger getAnonymousLogger.

Prototype

public static Logger getAnonymousLogger() 

Source Link

Document

Create an anonymous Logger.

Usage

From source file:org.silverpeas.core.viewer.service.ViewServiceCacheDemonstrationTestBefore.java

@Test
public void demonstrateCache() throws Exception {
    if (canPerformViewConversionTest()) {
        SimpleDocument document = getSimpleDocumentNamed("file.odt");
        long start = System.currentTimeMillis();
        DocumentView documentView = viewService.getDocumentView(ViewerContext.from(document));
        assertDocumentView(documentView);
        long end = System.currentTimeMillis();
        long conversionDuration = end - start;
        Logger.getAnonymousLogger().info(
                "Conversion duration + cache in " + DurationFormatUtils.formatDurationHMS(conversionDuration));
        assertThat(conversionDuration, greaterThan(250l));
        saveInTemporaryPath(ViewServiceCacheDemonstrationTestSuite.CONVERSION_DURATION_FILE_NAME,
                String.valueOf(conversionDuration));
        saveInTemporaryPath(ViewServiceCacheDemonstrationTestSuite.DOCUMENT_VIEW_FILE_NAME,
                SerializationUtil.serializeAsString(documentView));
    }/*from   w ww  .  j a v  a  2  s  .co m*/
}

From source file:org.silverpeas.core.viewer.service.ViewServiceNoCacheDemonstrationTestBefore.java

@Test
public void demonstrateNoCache() throws Exception {
    if (canPerformViewConversionTest()) {
        SimpleDocument document = getSimpleDocumentNamed("file.odt");
        long start = System.currentTimeMillis();
        DocumentView documentView = viewService.getDocumentView(ViewerContext.from(document));
        assertDocumentView(documentView);
        long end = System.currentTimeMillis();
        long conversionDuration = end - start;
        Logger.getAnonymousLogger().info("Conversion duration without cache in "
                + DurationFormatUtils.formatDurationHMS(conversionDuration));
        assertThat(conversionDuration, greaterThan(250l));
        saveInTemporaryPath(ViewServiceNoCacheDemonstrationTestSuite.CONVERSION_DURATION_FILE_NAME,
                String.valueOf(conversionDuration));
        saveInTemporaryPath(ViewServiceNoCacheDemonstrationTestSuite.DOCUMENT_VIEW_FILE_NAME,
                SerializationUtil.serializeAsString(documentView));
    }//from   ww w. j  a  va2s.  com
}

From source file:alma.acs.tmcdb.compare.TestHighLevelNodes.java

public TestHighLevelNodes(String name) {
    super(name);/*from  w ww  .j a  v a2  s  .  c  o m*/
    String rdbIOR = "corbaloc::" + ACSPorts.getIP() + ":" + "3012/CDB"; // ACSPorts.getCDBPort() + "/CDB";
    String xmlIOR = "corbaloc::" + ACSPorts.getIP() + ":" + "3013/CDB"; // ACSPorts.getCDBPort() + "/CDB";
    String args[] = {};
    logger = Logger.getAnonymousLogger();
    Properties props = new Properties();
    props.setProperty("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
    props.setProperty("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");
    orb = ORB.init(args, props);
    xmlDAL = JDALHelper.narrow(orb.string_to_object(xmlIOR));
    xmlAccess = new CDBAccess(orb, logger);
    xmlAccess.setDAL(xmlDAL);
    rdbDAL = JDALHelper.narrow(orb.string_to_object(rdbIOR));
    rdbAccess = new CDBAccess(orb, logger);
    rdbAccess.setDAL(rdbDAL);
}

From source file:org.sample.endpoint.TestServlet.java

/**
 * Processes requests for both HTTP// w ww  .  j a v  a 2  s . c o m
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet TestServlet</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>");
        Client client = ClientBuilder.newClient();
        client.register(new LoggingFilter(Logger.getAnonymousLogger(), true));
        WebTarget target = client.target("http://" + request.getServerName() + ":" + request.getServerPort()
                + request.getContextPath() + "/webresources/fruit");

        // POST
        out.print("POSTing...<br>");
        target.request().post(Entity.text("apple"));
        out.format("POSTed %1$s ...<br>", "apple");

        // PUT
        out.print("<br>PUTing...<br>");
        target.request().put(Entity.text("banana"));
        out.format("PUTed %1$s ...<br>", "banana");

        // GET (all)
        out.print("<br>GETing...<br>");
        String r = target.request().get(String.class);
        out.format("GETed %1$s items ...<br>", r);

        // GET (one)
        out.print("<br>GETing...<br>");
        r = target.path("apple").request().get(String.class);
        out.format("GETed %1$s items ...<br>", r);

        // DELETE
        out.print("<br>DELETEing...<br>");
        target.path("banana").request().delete();
        out.format("DELETEed %1$s items ...<br>", "banana");

        // GET (all)
        out.print("<br>GETing...<br>");
        r = target.request().get(String.class);
        out.format("GETed %1$s items ...<br>", r);

        out.println("</body>");
        out.println("</html>");
    }
}

From source file:com.dclab.preparation.ReadTest.java

public String handleZip(final ZipFile zf, final ZipEntry ze) throws IOException {

    if (ze.isDirectory()) {
        System.out.println(ze.getName() + " is folder ");
    } else if (ze.getName().endsWith(".xml")) {
        Logger.getAnonymousLogger().info("process file " + ze.getName());

        String s = ze.toString();

        // ByteBuffer bb = ByteBuffer.allocate(MAX_CAPACITY);
        InputStream is = zf.getInputStream(ze);

        byte[] bytes = IOUtils.toByteArray(is);

        return extract(new String(bytes));

        //scan( sr );
    }//from  ww  w .  j  a v a 2s  .  c o m
    return null;
}

From source file:org.javascool.compiler.JVSClassLoader.java

/**
 * Cherche une classe dans le classpath actuel et dans le rpertoire fournit au classloader
 *
 * @param className La classe  charger//from www. j  av a2 s  . co  m
 * @return L'objet reprsentant une classe en Java
 * @throws ClassNotFoundException Dans le cas o aucune classe n'as pu tre trouv.
 */
@Override
public Class<?> findClass(String className) throws ClassNotFoundException {
    byte classByte[];
    Class<?> result;

    result = classes.get(className); // On vrifie qu'elle n'est pas dans le cache
    if (result != null) {
        return result;
    }

    try { // On cherche si c'est une classe systme
        return findSystemClass(className);
    } catch (Exception e) {
        Logger.getAnonymousLogger().log(Level.OFF, className + " n'est pas une classe systme");
    }

    try { // Ou qu'elle est dans le chargeur parent
        return JVSClassLoader.class.getClassLoader().loadClass(className);
    } catch (Exception e) {
        Logger.getAnonymousLogger().log(Level.OFF, className + " n'est pas une classe du chargeur parent");
    }

    try { // On regarde aprs si elle n'est pas chez nous.
          // On en cre le pointeur vers le fichier de la classe
        File clazz = FileUtils.getFile(location, decomposePathForAClass(className));
        if (!clazz.exists()) { // Si le fichier de la classe n'existe pas, alors on cre une erreur
            throw new FileNotFoundException("Le fichier : " + clazz.toString() + " n'existe pas");
        }
        // On lit le fichier
        classByte = FileUtils.readFileToByteArray(clazz);
        // On dfinit la classe
        result = defineClass(className, classByte, 0, classByte.length, null);
        // On la stocke en cache
        classes.put(className, result);
        // On retourne le rsultat
        return result;
    } catch (Exception e) {
        throw new ClassNotFoundException(e.getMessage(), e);
    }
    //
}

From source file:org.objectpocket.util.IdSupport.java

/**
 * returns id for object that has been read from json string
 * //from w w  w . j  ava 2  s .c om
 * @param obj
 * @param idFromProxyIn
 * @return
 */
public static String getId(Object obj, String idFromProxyIn) {
    if (idFromProxyIn.startsWith(OP_REF_STRING)) {
        String typeName = obj.getClass().getName();
        if (!idFieldForType_ObjectsFromStore.containsKey(typeName)) {
            String fieldName = idFromProxyIn.substring(OP_REF_STRING.length(), idFromProxyIn.length());
            Field field = FieldUtils.getField(obj.getClass(), fieldName, true);
            idFieldForType_ObjectsFromStore.put(typeName, field);
        }
        Field field = idFieldForType_ObjectsFromStore.get(typeName);
        try {
            idFromProxyIn = (String) field.get(obj);
        } catch (IllegalAccessException e) {
            Logger.getAnonymousLogger().log(Level.WARNING,
                    "Could not read id from field " + field.getName() + " for class " + obj.getClass(), e);
        }
    }
    return idFromProxyIn;
}

From source file:JarClassLoader.java

/** 
 * Adds a jar file from the filesystems into the jar loader list.
 * //w  w  w. ja  v a 2  s  .co  m
 * @param jarfile The full path to the jar file.
 */
public void addJarFile(String jarfile) {
    try {
        URL url = new URL("file:" + jarfile);
        addURL(url);
    } catch (IOException ex) {
        Logger.getAnonymousLogger().log(Level.WARNING, "Error adding jar file", ex);
    }
}

From source file:org.fiware.cybercaptor.server.api.InformationSystemManagement.java

/**
 * Execute MulVAL on the topology and return the attack graph
 *
 * @param informationSystem the input network
 * @return the associated attack graph object
 *//*from   ww w.j  ava  2  s.com*/
public static AttackGraph prepareInputsAndExecuteMulVal(InformationSystem informationSystem) {
    if (informationSystem == null)
        return null;
    try {
        //Load MulVAL properties

        String mulvalPath = ProjectProperties.getProperty("mulval-path");
        String xsbPath = ProjectProperties.getProperty("xsb-path");
        String outputFolderPath = ProjectProperties.getProperty("output-path");

        File mulvalInputFile = new File(ProjectProperties.getProperty("mulval-input"));

        File mulvalOutputFile = new File(outputFolderPath + "/AttackGraph.xml");
        if (mulvalOutputFile.exists()) {
            mulvalOutputFile.delete();
        }
        Logger.getAnonymousLogger().log(Level.INFO, "Genering MulVAL inputs");
        informationSystem.exportToMulvalDatalogFile(mulvalInputFile.getAbsolutePath());

        Logger.getAnonymousLogger().log(Level.INFO, "Launching MulVAL");
        ProcessBuilder processBuilder = new ProcessBuilder(mulvalPath + "/utils/graph_gen.sh",
                mulvalInputFile.getAbsolutePath(), "-l");

        if (ProjectProperties.getProperty("mulval-rules-path") != null) {
            processBuilder.command().add("-r");
            processBuilder.command().add(ProjectProperties.getProperty("mulval-rules-path"));
        }

        processBuilder.directory(new File(outputFolderPath));
        processBuilder.environment().put("MULVALROOT", mulvalPath);
        String path = System.getenv("PATH");
        processBuilder.environment().put("PATH", mulvalPath + "/utils/:" + xsbPath + ":" + path);
        Process process = processBuilder.start();
        process.waitFor();

        if (!mulvalOutputFile.exists()) {
            Logger.getAnonymousLogger().log(Level.INFO, "Empty attack graph!");
            return null;
        }

        MulvalAttackGraph ag = new MulvalAttackGraph(mulvalOutputFile.getAbsolutePath());

        ag.loadMetricsFromTopology(informationSystem);

        return ag;

    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Classes.Database.java

/**
 * Makes a save SQL statement and executes it
 *
 * @param sql       The query, use an "?" at the place of a input. Like this:
 *                  INSERT INTO TABLE('name', 'lastname' , enz ) VALUES(?,?, enz);
 * @param arguments The arguments correspont to same questionmark.
 * @return The generated key/*from   w ww.j av a  2s. c o m*/
 * @throws SQLException
 */
public Integer setDatabase(String sql, Object... arguments) {
    Connection conn = null;
    PreparedStatement psta = null;
    ResultSet rs = null;

    try {
        Class.forName("com.mysql.jdbc.Driver");
        conn = DriverManager.getConnection(url, username, password);
        psta = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);

        EscapeSQL(psta, arguments);

        psta.executeUpdate();
        rs = psta.getGeneratedKeys();
        if (rs != null && rs.next()) {
            if (rs.getInt(1) == 0) { //maybe errors
                return -1;
            }
            return rs.getInt(1);
        }
        return -1;
    } catch (SQLException e) {
        Logger.getAnonymousLogger().log(Level.WARNING, "SQL Error: " + e.getMessage(), e);
        return -1;
    } catch (ClassNotFoundException e) {
        Logger.getAnonymousLogger().log(Level.WARNING, "Class Error " + e.getMessage(), e);
        return -1;
    } finally {
        if (conn != null) {
            //close and commit
            Logger.getAnonymousLogger().log(Level.INFO, "Commit" + sql);
            try {
                conn.commit();
            } catch (SQLException e) {
                Logger.getAnonymousLogger().log(Level.WARNING, e.getMessage(), e);
            }
            try {
                conn.close();
            } catch (SQLException e) {
                Logger.getAnonymousLogger().log(Level.WARNING, e.getMessage(), e);
            }
        }

        if (psta != null) {
            try {
                psta.close();
            } catch (SQLException e) {
                Logger.getAnonymousLogger().log(Level.WARNING, e.getMessage(), e);
            }
        }

        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                Logger.getAnonymousLogger().log(Level.WARNING, e.getMessage(), e);
            }
        }
    }
}