Search in sources :

Example 6 with Logger

use of java.util.logging.Logger in project GCViewer by chewiebug.

the class AbstractGCModelLoaderImpl method doInBackground.

@Override
protected GCModel doInBackground() throws Exception {
    setProgress(0);
    final GCModel result;
    try {
        result = loadGcModel();
    } catch (DataReaderException | RuntimeException e) {
        Logger logger = getGcResource().getLogger();
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, "Failed to load GCModel from " + getGcResource().getResourceName(), e);
        }
        throw e;
    }
    return result;
}
Also used : DataReaderException(com.tagtraum.perf.gcviewer.imp.DataReaderException) Logger(java.util.logging.Logger) GCModel(com.tagtraum.perf.gcviewer.model.GCModel)

Example 7 with Logger

use of java.util.logging.Logger in project che by eclipse.

the class LanguageServerFileTypeRegister method start.

@Override
public void start(final Callback<WsAgentComponent, Exception> callback) {
    Promise<List<LanguageDescriptionDTO>> registeredLanguages = serverLanguageRegistry.getSupportedLanguages();
    registeredLanguages.then(new Operation<List<LanguageDescriptionDTO>>() {

        @Override
        public void apply(List<LanguageDescriptionDTO> langs) throws OperationException {
            if (!langs.isEmpty()) {
                JsArrayString contentTypes = JsArrayString.createArray().cast();
                for (LanguageDescriptionDTO lang : langs) {
                    String primaryExtension = lang.getFileExtensions().get(0);
                    for (String ext : lang.getFileExtensions()) {
                        final FileType fileType = new FileType(resources.file(), ext);
                        fileTypeRegistry.registerFileType(fileType);
                        editorRegistry.registerDefaultEditor(fileType, editorProvider);
                        ext2langId.put(ext, lang.getLanguageId());
                    }
                    List<String> mimeTypes = lang.getMimeTypes();
                    if (mimeTypes.isEmpty()) {
                        mimeTypes = newArrayList("text/x-" + lang.getLanguageId());
                    }
                    for (String contentTypeId : mimeTypes) {
                        contentTypes.push(contentTypeId);
                        OrionContentTypeOverlay contentType = OrionContentTypeOverlay.create();
                        contentType.setId(contentTypeId);
                        contentType.setName(lang.getLanguageId());
                        contentType.setExtension(primaryExtension);
                        contentType.setExtends("text/plain");
                        // highlighting
                        OrionHighlightingConfigurationOverlay config = OrionHighlightingConfigurationOverlay.create();
                        config.setId(lang.getLanguageId() + ".highlighting");
                        config.setContentTypes(contentTypeId);
                        config.setPatterns(lang.getHighlightingConfiguration());
                        Logger logger = Logger.getLogger(LanguageServerFileTypeRegister.class.getName());
                        contentTypeRegistrant.registerFileType(contentType, config);
                    }
                }
                orionHoverRegistrant.registerHover(contentTypes, hoverProvider);
                orionOccurrencesRegistrant.registerOccurrencesHandler(contentTypes, occurrencesProvider);
            }
            callback.onSuccess(LanguageServerFileTypeRegister.this);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            callback.onFailure(new Exception(arg.getMessage(), arg.getCause()));
        }
    });
}
Also used : OrionHighlightingConfigurationOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionHighlightingConfigurationOverlay) LanguageDescriptionDTO(org.eclipse.che.api.languageserver.shared.lsapi.LanguageDescriptionDTO) OrionContentTypeOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionContentTypeOverlay) Operation(org.eclipse.che.api.promises.client.Operation) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) Logger(java.util.logging.Logger) OperationException(org.eclipse.che.api.promises.client.OperationException) PromiseError(org.eclipse.che.api.promises.client.PromiseError) FileType(org.eclipse.che.ide.api.filetypes.FileType) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 8 with Logger

use of java.util.logging.Logger in project android_frameworks_base by ParanoidAndroid.

the class CookiesTest method testCookiesAreNotLogged.

/**
     * Test that we don't log potentially sensitive cookie values.
     * http://b/3095990
     */
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
    // enqueue an HTTP response with a cookie that will be rejected
    server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
    server.play();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Logger logger = Logger.getLogger("org.apache.http");
    StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
    logger.addHandler(handler);
    try {
        HttpClient client = new DefaultHttpClient();
        client.execute(new HttpGet(server.getUrl("/").toURI()));
        handler.close();
        String log = out.toString("UTF-8");
        assertTrue(log, log.contains("password"));
        assertTrue(log, log.contains("fake.domain"));
        assertFalse(log, log.contains("secret"));
    } finally {
        logger.removeHandler(handler);
    }
}
Also used : MockResponse(com.google.mockwebserver.MockResponse) StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(java.util.logging.Logger) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 9 with Logger

use of java.util.logging.Logger in project MSEC by Tencent.

the class SendCmdsToAgentAndRun method doSendCmdsToAgentAndRun.

private String doSendCmdsToAgentAndRun(SendCmdsToAgentAndRunRequest request, StringBuffer outputFileName) {
    Socket socket = new Socket();
    Logger logger = Logger.getLogger("remote_shell");
    try {
        File file = new File(request.getLocalFileFullName());
        //����ִ�к���������ļ�������
        String outFileName = String.format("/tmp/output_%d.txt", (int) (Math.random() * Integer.MAX_VALUE));
        outputFileName.delete(0, outputFileName.length());
        outputFileName.append(outFileName);
        //�������ļ�����ǩ��
        String signature = "";
        if (Main.privateKey != null) {
            signature = geneSignature(request.getLocalFileFullName());
        }
        socket.connect(new InetSocketAddress(request.getRemoteServerIP(), 9981), 1000);
        String s = "{\"handleClass\":\"SendCmdsToAgentAndRun\", \"requestBody\":{" + "\"cmdFileLength\":" + String.format("%d", file.length()) + ", \"outputFileName\":\"" + outFileName + "\"" + ", \"signature\":\"" + signature + "\"" + "}}";
        s = Tools.getLengthField(s.length()) + s;
        socket.getOutputStream().write(s.getBytes());
        logger.info(String.format("write json complete.%s", s));
        //send file content
        FileInputStream fileInputStream = new FileInputStream(file);
        byte[] buf = new byte[10240];
        int total_len = 0;
        while (true) {
            int len = fileInputStream.read(buf);
            if (len <= 0) {
                break;
            }
            total_len += len;
            socket.getOutputStream().write(buf, 0, len);
        }
        logger.info(String.format("write file bytes number:%d", total_len));
        socket.shutdownOutput();
        ;
        //recv the response
        // length field 10bytes
        total_len = 0;
        while (total_len < 10) {
            int len = socket.getInputStream().read(buf, total_len, 10 - total_len);
            if (len <= 0) {
                return "recv response failed!";
            }
            total_len += len;
        }
        int jsonLen = new Integer(new String(buf, 0, total_len).trim()).intValue();
        if (jsonLen < 2) {
            return "response json string empty";
        }
        logger.info(String.format("response json string len:%d", jsonLen));
        total_len = 0;
        while (jsonLen < buf.length && total_len < jsonLen) {
            int len = socket.getInputStream().read(buf, total_len, jsonLen - total_len);
            if (len <= 0) {
                break;
            }
            total_len += len;
        }
        logger.info(String.format("read agent response bytes number:%d", total_len));
        String jsonStr = new String(buf, 0, total_len);
        JSONObject jsonObject = new JSONObject(jsonStr);
        String message = jsonObject.getString("message");
        int status = jsonObject.getInt("status");
        if (status == 0) {
            return "success";
        } else {
            return message;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return e.toString();
    }
}
Also used : JSONObject(org.json.JSONObject) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) Logger(java.util.logging.Logger) File(java.io.File) Socket(java.net.Socket) FileInputStream(java.io.FileInputStream)

Example 10 with Logger

use of java.util.logging.Logger in project MSEC by Tencent.

the class SendCmdsToAgentAndRun method exec.

public SendCmdsToAgentAndRunResponse exec(SendCmdsToAgentAndRunRequest request) {
    Logger logger = Logger.getLogger("remote_shell");
    logger.setLevel(Level.ALL);
    logger.info(String.format("I will send cmd to agent, [%s][%s]", request.getLocalFileFullName(), request.getRemoteServerIP()));
    StringBuffer sb = new StringBuffer();
    String result = doSendCmdsToAgentAndRun(request, sb);
    if (result.equals("success")) {
        logger.info(String.format("output file name: %s", sb.toString()));
        SendCmdsToAgentAndRunResponse response = new SendCmdsToAgentAndRunResponse();
        response.setMessage("success");
        response.setOutputFileName(sb.toString());
        response.setStatus(0);
        return response;
    } else {
        SendCmdsToAgentAndRunResponse response = new SendCmdsToAgentAndRunResponse();
        response.setMessage(result);
        response.setStatus(100);
        return response;
    }
}
Also used : SendCmdsToAgentAndRunResponse(comm_with_client.response.SendCmdsToAgentAndRunResponse) Logger(java.util.logging.Logger)

Aggregations

Logger (java.util.logging.Logger)362 LogRecord (java.util.logging.LogRecord)43 Test (org.junit.Test)41 Handler (java.util.logging.Handler)35 File (java.io.File)18 IOException (java.io.IOException)18 ConsoleHandler (java.util.logging.ConsoleHandler)15 SimpleFormatter (java.util.logging.SimpleFormatter)15 Level (java.util.logging.Level)11 LogManager (java.util.logging.LogManager)10 ArrayList (java.util.ArrayList)8 StreamHandler (java.util.logging.StreamHandler)8 ResourceBundle (java.util.ResourceBundle)7 MockResponse (com.google.mockwebserver.MockResponse)6 Properties (java.util.Properties)6 HashMap (java.util.HashMap)5 FileHandler (java.util.logging.FileHandler)5 TestLogHandler (com.google.common.testing.TestLogHandler)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileInputStream (java.io.FileInputStream)4