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.AbstractViewerIT.java

boolean canPerformViewConversionTest() {
    if (SwfToolManager.isActivated()) {
        return true;
    }//from  ww w  .  j  ava2s  .c o  m
    Logger.getAnonymousLogger().severe("SwfTools are not available, test is skipped.");
    Logger.getAnonymousLogger().severe("Please install pdf2swf and swfrender tools.");
    return false;
}

From source file:org.jenkinsci.remoting.protocol.impl.NetworkLayerTest.java

@Theory
public void doCloseRecv(NetworkLayerFactory serverFactory, NetworkLayerFactory clientFactory) throws Exception {
    Logger.getAnonymousLogger().log(Level.INFO, "serverFactory: {0} clientFactory: {1}", new Object[] {
            serverFactory.getClass().getSimpleName(), clientFactory.getClass().getSimpleName() });
    ProtocolStack<IOBufferMatcher> client = ProtocolStack
            .on(clientFactory.create(selector.hub(), serverToClient.source(), clientToServer.sink()))
            .build(new IOBufferMatcherLayer());

    ProtocolStack<IOBufferMatcher> server = ProtocolStack
            .on(serverFactory.create(selector.hub(), clientToServer.source(), serverToClient.sink()))
            .build(new IOBufferMatcherLayer());

    byte[] expected = "Here is some sample data".getBytes("UTF-8");
    ByteBuffer data = ByteBuffer.allocate(expected.length);
    data.put(expected);//from   ww  w  .  j  a  v a2s .com
    data.flip();
    server.get().send(data);
    client.get().awaitByteContent(is(expected));
    assertThat(client.get().asByteArray(), is(expected));
    server.get().closeRead();
    client.get().awaitClose();
}

From source file:com.vmware.photon.controller.api.client.resource.ApiBase.java

/**
 * Deletes an object as async.//  w w w .  j  a v  a 2s  .c om
 *
 * @param id
 * @param responseCallback
 * @throws IOException
 */
public final void deleteObjectAsync(final String id, final FutureCallback<Task> responseCallback)
        throws IOException {
    final String path = String.format("%s/%s", getBasePath(), id);

    this.restClient.performAsync(RestClient.Method.DELETE, path, null,
            new org.apache.http.concurrent.FutureCallback<HttpResponse>() {
                @Override
                public void completed(HttpResponse result) {
                    Task task = null;
                    try {
                        restClient.checkResponse(result, HttpStatus.SC_CREATED);
                        task = restClient.parseHttpResponse(result, new TypeReference<Task>() {
                        });
                    } catch (Throwable e) {
                        responseCallback.onFailure(e);
                    }

                    if (task != null) {
                        Logger.getAnonymousLogger().log(Level.INFO, String
                                .format("deleteObjectAsync returned task [%s] %s", this.toString(), path));
                        responseCallback.onSuccess(task);
                    } else {
                        Logger.getAnonymousLogger().log(Level.INFO,
                                String.format("deleteObjectAsync failed [%s] %s", this.toString(), path));
                    }
                }

                @Override
                public void failed(Exception ex) {
                    Logger.getAnonymousLogger().log(Level.INFO, "{}", ex);
                    responseCallback.onFailure(ex);
                }

                @Override
                public void cancelled() {
                    responseCallback.onFailure(
                            new RuntimeException(String.format("deleteAsync %s was cancelled", path)));
                }
            });
}

From source file:org.objectpocket.storage.blob.MultiZipBlobStore.java

@Override
public byte[] loadBlobData(Blob blob) throws IOException {
    if (blob == null) {
        return null;
    }//from  w ww.j  a v a2  s .c  o m
    String path = blob.getPath();
    if (path == null || path.trim().isEmpty()) {
        path = blob.getId();
    }
    if (blobContainerIndex == null) {
        initIndexAndReadFileSystems();
    }
    String blobContainerName = blobContainerIndex.get(path);
    if (blobContainerName == null) {
        Logger.getAnonymousLogger().warning("no blob container found for blob " + blob.getPath());
        return null;
    }

    FileSystem fsRead = getReadFileSystem(blobContainerName);

    Path fileInZip = fsRead.getPath(path);
    byte[] buf = null;
    try (InputStream in = Files.newInputStream(fileInZip)) {
        buf = IOUtils.toByteArray(in);
    }
    return buf;
}

From source file:org.apache.directory.studio.connection.core.io.jndi.LdifSearchLogger.java

/**
 * Inits the search logger./*from www. j a  va2s .c  om*/
 */
private void initSearchLogger(Connection connection) {
    Logger logger = Logger.getAnonymousLogger();
    loggers.put(connection.getId(), logger);
    logger.setLevel(Level.ALL);

    String logfileName = ConnectionManager.getSearchLogFileName(connection);
    try {
        FileHandler fileHandler = new FileHandler(logfileName, getFileSizeInKb() * 1000, getFileCount(), true);
        fileHandlers.put(connection.getId(), fileHandler);
        fileHandler.setFormatter(new Formatter() {
            public String format(LogRecord record) {
                return record.getMessage();
            }
        });
        logger.addHandler(fileHandler);
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:controllers.transformer.ExcelTransformer.java

public byte[] getBytes() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Sheet1");

    if (results == null) {
        results = survey.resultCollection;
    }//from  w  w w.java2  s  .  c o  m

    /** Header **/
    HSSFRow row = sheet.createRow(0);
    int fieldcounter = 0;
    row.createCell(fieldcounter++).setCellValue("ResultId");
    row.createCell(fieldcounter++).setCellValue("SurveyId");
    row.createCell(fieldcounter++).setCellValue("Title");
    row.createCell(fieldcounter++).setCellValue("Start time");
    row.createCell(fieldcounter++).setCellValue("End time");
    row.createCell(fieldcounter++).setCellValue("Date Sent");
    row.createCell(fieldcounter++).setCellValue("User");
    row.createCell(fieldcounter++).setCellValue("Phone Number");
    row.createCell(fieldcounter++).setCellValue("Lat");
    row.createCell(fieldcounter++).setCellValue("Lon");

    /** Header Fields**/
    for (Question question : survey.getQuestions()) {
        row.createCell(fieldcounter++).setCellValue(question.label);
    }

    int countrow = 0;
    row = sheet.createRow(++countrow);

    //SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss Z");

    for (NdgResult result : results) {
        fieldcounter = 0;
        row.createCell(fieldcounter++).setCellValue(result.resultId);
        row.createCell(fieldcounter++).setCellValue(result.survey.surveyId);
        row.createCell(fieldcounter++).setCellValue(result.title);
        row.createCell(fieldcounter++).setCellValue(dateFormat.format(result.startTime));
        row.createCell(fieldcounter++).setCellValue(dateFormat.format(result.endTime));

        if (result.dateSent != null) {
            row.createCell(fieldcounter++).setCellValue(dateFormat.format(result.dateSent));
        } else {
            row.createCell(fieldcounter++).setCellValue("");
        }

        row.createCell(fieldcounter++).setCellValue(result.ndgUser.username);
        row.createCell(fieldcounter++).setCellValue(result.ndgUser.phoneNumber);
        row.createCell(fieldcounter++).setCellValue(result.latitude);
        row.createCell(fieldcounter++).setCellValue(result.longitude);

        for (Question question : survey.getQuestions()) {//to ensure right answer order
            Collection<Answer> answers = CollectionUtils.intersection(question.answerCollection,
                    result.answerCollection);//only one should left, hope that it does not modify results
            if (answers.isEmpty()) {
                row.createCell(fieldcounter++).setCellValue("");
            } else if (answers.size() == 1) {
                Answer answer = answers.iterator().next();
                if (answer.question.questionType.typeName.equalsIgnoreCase(QuestionTypesConsts.IMAGE)) {//TODO handle other binary data
                    row.createCell(fieldcounter++).setCellValue(storeImagesAndGetValueToExport(survey.surveyId,
                            result.resultId, answer.id, answer.binaryData));
                } else if (answer.question.questionType.typeName.equalsIgnoreCase(QuestionTypesConsts.INT)) {
                    Integer value = Integer.valueOf(answer.textData);
                    row.createCell(fieldcounter++).setCellValue(value);
                } else if (answer.question.questionType.typeName
                        .equalsIgnoreCase(QuestionTypesConsts.DECIMAL)) {
                    Float value = Float.valueOf(answer.textData);
                    row.createCell(fieldcounter++).setCellValue(value);
                } else {
                    String value = answer.textData;
                    value = value.trim().replaceAll("\n", "");
                    row.createCell(fieldcounter++).setCellValue(value);
                }
            } else {
                Logger.getAnonymousLogger().log(Level.WARNING,
                        "to many answers. ResID={0}questioId={1}answerCount={2}",
                        new Object[] { result.resultId, question.id, question.answerCollection.size() });
                break;
            }
        }
        row = sheet.createRow(++countrow);
    }
    try {
        wb.write(out);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return out.toByteArray();
}

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

/**
 * Execute MulVAL on the topology and return the attack graph
 *
 * @return the associated attack graph object
 *//*w  w w.  j  ava 2s . c  o  m*/
public static AttackGraph generateAttackGraphWithMulValUsingAlreadyGeneratedMulVALInputFile() {
    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, "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());

        return ag;

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

    return null;
}

From source file:spout.mddb.MddbFeatureExtractorSpout.java

/**
 * When this method is called, Storm is requesting that the Spout emit tuples to the
 * output collector. This method should be non-blocking, so if the Spout has no tuples
 * to emit, this method should return. nextTuple, ack, and fail are all called in a tight
 * loop in a single thread in the spout task. When there are no tuples to emit, it is courteous
 * to have nextTuple sleep for a short amount of time (like a single millisecond)
 * so as not to waste too much CPU./*from   w  w w.  j  av a 2s  .c  o m*/
 */

@Override
public synchronized void nextTuple() {
    if (peekableScanner == null) {
        Logger.getAnonymousLogger().log(Level.INFO,
                MessageFormat.format("No more featureVectors. Visit {0} later", taskId));
    } else {
        try {
            if (peekableScanner.hasNext()) {
                tupleBeingProcessed = peekableScanner.next();
            }
            final List<Map<String, List<Double>>> dict = SpoutUtils.pythonDictToJava(tupleBeingProcessed);
            for (Map<String, List<Double>> map : dict) {
                // hack
                //noinspection ToArrayCallWithZeroLengthArrayArgument
                final Double[] features = map.get("chi2").toArray(new Double[0]);
                //noinspection ToArrayCallWithZeroLengthArrayArgument
                final Double[] moreFeatures = map.get("chi1").toArray(new Double[0]);
                final Double[] both = (Double[]) ArrayUtils.addAll(features, moreFeatures);
                collector.emit(new Values(messageId++, ArrayUtils.toPrimitive(both)));
            }
            peekableScanner = moveSpoutForward();
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
}

From source file:com.devnexus.ting.web.controller.AndroidLoginController.java

/**
 * This will verify tokens sent from an Authenticated Android device that
 * the user is who the user says it is./*from w  w w  . j  a  v  a 2s . c o  m*/
 * <p/>
 * Additionally it will create an account if one does not exist.
 */
@RequestMapping(value = "/s/loginAndroid", method = RequestMethod.POST)
@ResponseBody
public String login(HttpServletRequest request, HttpServletResponse response) {

    try {

        AndroidAuthentication auth = GSON.fromJson(request.getReader(), AndroidAuthentication.class);
        String accessToken = auth.idToken;

        GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(new NetHttpTransport(),
                new JacksonFactory()).setAudience(Arrays.asList(CLIENT_ID))
                        // If you retrieved the token on Android using the
                        // Play Services 8.3 API or newer, set
                        // the issuer to "https://accounts.google.com".
                        // Otherwise, set the issuer to
                        // "accounts.google.com". If you need to verify
                        // tokens from multiple sources, build
                        // a GoogleIdTokenVerifier for each issuer and try
                        // them both.
                        .setIssuer("https://accounts.google.com").build();

        GoogleIdToken idToken = verifier.verify(accessToken);
        Payload payload = idToken.getPayload();

        User user;
        try {
            user = (User) userService.loadUserByUsername("google:" + payload.getSubject());
        } catch (UsernameNotFoundException e) {
            user = new User();
            user.setEmail(payload.getEmail());
            user.setUsername("google:" + payload.getSubject());
            user.setUserAuthorities(new HashSet<UserAuthority>(1));
            user.getUserAuthorities().add(new UserAuthority(user, AuthorityType.APP_USER));
            user.setFirstName((String) payload.get("given_name"));
            user.setLastName((String) payload.get("family_name"));
            byte[] password = new byte[16];
            new SecureRandom().nextBytes(password);
            user.setPassword(Arrays.toString(password));

            try {
                userService.addUser(user);
            } catch (DuplicateUserException ex) {
                Logger.getLogger(AndroidLoginController.class.getName()).log(Level.SEVERE, null, ex);
                throw new RuntimeException(ex);
            }

            user = (User) userService.loadUserByUsername(user.getUsername());

        }

        MobileSignIn signIn = new MobileSignIn();
        signIn.setToken(new BigInteger(512, new SecureRandom()).toString(32));
        signIn.setUser(user);
        user.getMobileTokens().add(signIn);

        userService.updateUser(user);

        return "{\"token\":\"" + signIn.getToken() + "\"}";

    } catch (IOException | GeneralSecurityException e) {
        Logger.getAnonymousLogger().log(Level.SEVERE, e.getMessage(), e);

        throw new RuntimeException(e);
    }

}

From source file:com.prod.intelligent7.engineautostart.ConnectDaemonService.java

@Override
public void onCreate() {
    ramFileName = MainActivity.package_name + ".profile";
    log = Logger.getAnonymousLogger();
    log.info(getPackageName() + "Got Activated ");
    serverHeartBit = 60 * 1000;//from   www.j a  v a  2 s.  com
    urgentMailBox = new ArrayList<String>();
    if (mDaemon == null || !mDaemon.isAlive())
        startDaemon();
    scheduleAlarm = null;
    alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    //startScheduledJobs();
    //new screen off handling
    /*
    bugPresent = true;
    screenIsOff = false;
    final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    screenOnOffReceiver = new ScreenReceiver();
    registerReceiver(screenOnOffReceiver, filter);
    powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    WakeLockManager.acquire(this, "screenBugPartial", PowerManager.PARTIAL_WAKE_LOCK);
    registerAccelerometerListener();
    */
    startScheduleAlarms();
}