Search in sources :

Example 6 with Filter

use of org.glassfish.hk2.api.Filter in project Payara by payara.

the class GetProtocol method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    // Check that a configuration can be found
    if (targetUtil.getConfig(target) == null) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_CONFIG), target));
        return;
    }
    Config config = targetUtil.getConfig(target);
    // Check that a matching listener can be found
    List<Protocol> protocols = config.getNetworkConfig().getProtocols().getProtocol();
    Optional<Protocol> optionalProtocol = protocols.stream().filter(protocol -> protocol.getName().equals(protocolName)).findFirst();
    if (!optionalProtocol.isPresent()) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_PROTOCOL), protocolName, target));
        return;
    }
    Protocol protocol = optionalProtocol.get();
    // Write message body
    report.appendMessage(String.format("Name: %s\n", protocol.getName()));
    // Write HTTP config options
    report.appendMessage("\nHTTP:\n");
    report.appendMessage(String.format("Server Name: %s\n", protocol.getHttp().getServerName()));
    report.appendMessage(String.format("Max Connections: %s seconds\n", protocol.getHttp().getMaxConnections()));
    report.appendMessage(String.format("Default Virtual Server: %s\n", protocol.getHttp().getDefaultVirtualServer()));
    report.appendMessage(String.format("Server Header: %s\n", protocol.getHttp().getServerHeader()));
    report.appendMessage(String.format("X-Powered-By: %s\n", protocol.getHttp().getXpoweredBy()));
    if (verbose) {
        report.appendMessage(String.format("Request Timeout: %s seconds\n", protocol.getHttp().getRequestTimeoutSeconds()));
        report.appendMessage(String.format("Timeout: %s seconds\n", protocol.getHttp().getTimeoutSeconds()));
        report.appendMessage(String.format("DNS Lookup Enabled: %s\n", protocol.getHttp().getDnsLookupEnabled()));
        report.appendMessage(String.format("X Frame Options: %s\n", protocol.getHttp().getXframeOptions()));
    }
    // Write HTTP/2 config options
    report.appendMessage("\nHTTP/2:\n");
    report.appendMessage(String.format("Enabled: %s\n", protocol.getHttp().isHttp2Enabled()));
    if (protocol.getHttp().isHttp2Enabled()) {
        report.appendMessage(String.format("Push Enabled: %s\n", protocol.getHttp().isHttp2PushEnabled()));
        report.appendMessage(String.format("Cipher Check: %s\n", !protocol.getHttp().isHttp2DisableCipherCheck()));
        if (verbose) {
            report.appendMessage(String.format("Max Concurrent Streams: %s\n", protocol.getHttp().getHttp2MaxConcurrentStreams()));
            report.appendMessage(String.format("Initial Window Size: %s bytes\n", protocol.getHttp().getHttp2InitialWindowSizeInBytes()));
            report.appendMessage(String.format("Max Frame Payload Size: %s bytes\n", protocol.getHttp().getHttp2MaxFramePayloadSizeInBytes()));
            report.appendMessage(String.format("Max Header List Size: %s bytes\n", protocol.getHttp().getHttp2MaxHeaderListSizeInBytes()));
            report.appendMessage(String.format("Streams High Water Mark: %s\n", protocol.getHttp().getHttp2StreamsHighWaterMark()));
            report.appendMessage(String.format("Clean Percentage: %s\n", protocol.getHttp().getHttp2CleanPercentage()));
            report.appendMessage(String.format("Clean Frequency Check: %s\n", protocol.getHttp().getHttp2CleanFrequencyCheck()));
        }
    }
    // Write the variables as properties
    Properties properties = new Properties();
    properties.put("name", protocol.getName());
    properties.put("serverName", protocol.getHttp().getServerName() == null ? "null" : protocol.getHttp().getServerName());
    properties.put("maxConnections", protocol.getHttp().getMaxConnections());
    properties.put("defaultVirtualServer", protocol.getHttp().getDefaultVirtualServer());
    properties.put("serverHeader", protocol.getHttp().getServerHeader());
    properties.put("xPoweredBy", protocol.getHttp().getXpoweredBy());
    properties.put("requestTimeoutSeconds", protocol.getHttp().getRequestTimeoutSeconds());
    properties.put("timeoutSeconds", protocol.getHttp().getTimeoutSeconds());
    properties.put("dnsLookupEnabled", protocol.getHttp().getDnsLookupEnabled());
    properties.put("xFrameOptions", protocol.getHttp().getXframeOptions());
    properties.put("http2Enabled", protocol.getHttp().isHttp2Enabled());
    properties.put("http2MaxConcurrentStreams", protocol.getHttp().getHttp2MaxConcurrentStreams());
    properties.put("http2InitialWindowSizeInBytes", protocol.getHttp().getHttp2InitialWindowSizeInBytes());
    properties.put("http2MaxFramePayloadSizeInBytes", protocol.getHttp().getHttp2MaxFramePayloadSizeInBytes());
    properties.put("http2MaxHeaderListSizeInBytes", protocol.getHttp().getHttp2MaxHeaderListSizeInBytes());
    properties.put("http2StreamsHighWaterMark", protocol.getHttp().getHttp2StreamsHighWaterMark());
    properties.put("http2CleanPercentage", protocol.getHttp().getHttp2CleanPercentage());
    properties.put("http2CleanFrequencyCheck", protocol.getHttp().getHttp2CleanFrequencyCheck());
    properties.put("http2DisableCipherCheck", protocol.getHttp().isHttp2DisableCipherCheck());
    properties.put("http2PushEnabled", protocol.getHttp().isHttp2PushEnabled());
    report.setExtraProperties(properties);
}
Also used : Param(org.glassfish.api.Param) LogFacade(org.glassfish.web.admin.LogFacade) RestEndpoint(org.glassfish.api.admin.RestEndpoint) CommandLock(org.glassfish.api.admin.CommandLock) MessageFormat(java.text.MessageFormat) I18n(org.glassfish.api.I18n) PerLookup(org.glassfish.hk2.api.PerLookup) Inject(javax.inject.Inject) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) ExecuteOn(org.glassfish.api.admin.ExecuteOn) RuntimeType(org.glassfish.api.admin.RuntimeType) RestEndpoints(org.glassfish.api.admin.RestEndpoints) AdminCommand(org.glassfish.api.admin.AdminCommand) Properties(java.util.Properties) TargetType(org.glassfish.config.support.TargetType) Logger(java.util.logging.Logger) List(java.util.List) Target(org.glassfish.internal.api.Target) Service(org.jvnet.hk2.annotations.Service) AdminCommandContext(org.glassfish.api.admin.AdminCommandContext) CommandTarget(org.glassfish.config.support.CommandTarget) HttpService(com.sun.enterprise.config.serverbeans.HttpService) Optional(java.util.Optional) SystemPropertyConstants(com.sun.enterprise.util.SystemPropertyConstants) Config(com.sun.enterprise.config.serverbeans.Config) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) Properties(java.util.Properties)

Example 7 with Filter

use of org.glassfish.hk2.api.Filter in project Payara by payara.

the class LogManagerService method postConstruct.

/**
 * Initialize the loggers
 */
@Override
public void postConstruct() {
    // if the system property is already set, we don't need to do anything
    if (System.getProperty("java.util.logging.config.file") != null) {
        System.out.println("\n\n\n#!## LogManagerService.postConstruct : java.util.logging.config.file=" + System.getProperty("java.util.logging.config.file"));
        return;
    }
    // logging.properties massaging.
    final LogManager logMgr = LogManager.getLogManager();
    File logging = null;
    // reset settings
    try {
        logging = getLoggingFile();
        System.setProperty("java.util.logging.config.file", logging.getAbsolutePath());
        String rootFolder = env.getProps().get(com.sun.enterprise.util.SystemPropertyConstants.INSTALL_ROOT_PROPERTY);
        String templateDir = rootFolder + File.separator + "lib" + File.separator + "templates";
        File src = new File(templateDir, ServerEnvironmentImpl.kLoggingPropertiesFileName);
        File dest = new File(env.getConfigDirPath(), ServerEnvironmentImpl.kLoggingPropertiesFileName);
        System.out.println("\n\n\n#!## LogManagerService.postConstruct : rootFolder=" + rootFolder);
        System.out.println("#!## LogManagerService.postConstruct : templateDir=" + templateDir);
        System.out.println("#!## LogManagerService.postConstruct : src=" + src);
        System.out.println("#!## LogManagerService.postConstruct : dest=" + dest);
        if (!logging.exists()) {
            LOGGER.log(Level.FINE, "{0} not found, creating new file from template.", logging.getAbsolutePath());
            FileUtils.copy(src, dest);
            logging = new File(env.getConfigDirPath(), ServerEnvironmentImpl.kLoggingPropertiesFileName);
        }
        logMgr.readConfiguration();
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, LogFacade.ERROR_READING_CONF_FILE, e);
    }
    FormatterDelegate agentDelegate = null;
    if (agent != null) {
        agentDelegate = new AgentFormatterDelegate(agent);
    }
    // force the ConsoleHandler to use GF formatter
    String formatterClassName = null;
    try {
        Map<String, String> props = getLoggingProperties();
        formatterClassName = props.get(CONSOLEHANDLER_FORMATTER_PROPERTY);
        if (formatterClassName == null || formatterClassName.isEmpty()) {
            formatterClassName = UniformLogFormatter.class.getName();
        }
        consoleHandlerFormatterDetail = formatterClassName;
        excludeFields = props.get(EXCLUDE_FIELDS_PROPERTY);
        multiLineMode = Boolean.parseBoolean(props.get(MULTI_LINE_MODE_PROPERTY));
        if (formatterClassName.equals(UniformLogFormatter.class.getName())) {
            // used to support UFL formatter in GF.
            UniformLogFormatter formatter = new UniformLogFormatter();
            String cname = "com.sun.enterprise.server.logging.GFFileHandler";
            recordBeginMarker = props.get(cname + ".logFormatBeginMarker");
            if (recordBeginMarker == null || ("").equals(recordBeginMarker)) {
                LOGGER.log(Level.FINE, "Record begin marker is not a proper value so using default.");
                recordBeginMarker = RECORD_BEGIN_MARKER;
            }
            recordEndMarker = props.get(cname + ".logFormatEndMarker");
            if (recordEndMarker == null || ("").equals(recordEndMarker)) {
                LOGGER.log(Level.FINE, "Record end marker is not a proper value so using default.");
                recordEndMarker = RECORD_END_MARKER;
            }
            recordFieldSeparator = props.get(cname + ".logFormatFieldSeparator");
            if (recordFieldSeparator == null || ("").equals(recordFieldSeparator) || recordFieldSeparator.length() > 1) {
                LOGGER.log(Level.FINE, "Log Format field separator is not a proper value so using default.");
                recordFieldSeparator = RECORD_FIELD_SEPARATOR;
            }
            recordDateFormat = props.get(cname + ".logFormatDateFormat");
            if (recordDateFormat != null && !("").equals(recordDateFormat)) {
                SimpleDateFormat sdf = new SimpleDateFormat(recordDateFormat);
                try {
                    sdf.format(new Date());
                } catch (Exception e) {
                    LOGGER.log(Level.FINE, "Date Format specified is wrong so using default.");
                    recordDateFormat = RECORD_DATE_FORMAT;
                }
            } else {
                LOGGER.log(Level.FINE, "Date Format specified is wrong so using default.");
                recordDateFormat = RECORD_DATE_FORMAT;
            }
            formatter.setRecordBeginMarker(recordBeginMarker);
            formatter.setRecordEndMarker(recordEndMarker);
            formatter.setRecordDateFormat(recordDateFormat);
            formatter.setRecordFieldSeparator(recordFieldSeparator);
            formatter.setExcludeFields(excludeFields);
            formatter.setMultiLineMode(multiLineMode);
            for (Handler handler : logMgr.getLogger("").getHandlers()) {
                // only get the ConsoleHandler
                if (handler.getClass().equals(ConsoleHandler.class)) {
                    handler.setFormatter(formatter);
                    break;
                }
            }
        } else if (formatterClassName.equals(ODLLogFormatter.class.getName())) {
            // used to support ODL formatter in GF.
            ODLLogFormatter formatter = new ODLLogFormatter();
            formatter.setExcludeFields(excludeFields);
            formatter.setMultiLineMode(multiLineMode);
            for (Handler handler : logMgr.getLogger("").getHandlers()) {
                // only get the ConsoleHandler
                if (handler.getClass().equals(ConsoleHandler.class)) {
                    handler.setFormatter(formatter);
                    break;
                }
            }
        } else if (formatterClassName.equals(JSONLogFormatter.class.getName())) {
            JSONLogFormatter formatter = new JSONLogFormatter();
            formatter.setExcludeFields(excludeFields);
            for (Handler handler : logMgr.getLogger("").getHandlers()) {
                // only get the ConsoleHandler
                if (handler.getClass().equals(ConsoleHandler.class)) {
                    handler.setFormatter(formatter);
                    break;
                }
            }
        }
        // setting default attributes value for all properties
        serverLogFileDetail = props.get(SERVER_LOG_FILE_PROPERTY);
        handlerDetail = props.get(HANDLER_PROPERTY);
        handlerServices = props.get(HANDLER_SERVICES_PROPERTY);
        if (handlerServices == null) {
            handlerServices = "";
        }
        consoleHandlerFormatterDetail = props.get(CONSOLEHANDLER_FORMATTER_PROPERTY);
        gffileHandlerFormatterDetail = props.get(GFFILEHANDLER_FORMATTER_PROPERTY);
        rotationOnTimeLimitInMinutesDetail = props.get(ROTATIONTIMELIMITINMINUTES_PROPERTY);
        flushFrequencyDetail = props.get(FLUSHFREQUENCY_PROPERTY);
        filterHandlerDetails = props.get(FILEHANDLER_LIMIT_PROPERTY);
        logToFileDetail = props.get(LOGTOFILE_PROPERTY);
        logToConsoleDetail = props.get(LOGTOCONSOLE_PROPERTY);
        rotationInTimeLimitInBytesDetail = props.get(ROTATIONLIMITINBYTES_PROPERTY);
        useSystemLoggingDetail = props.get(USESYSTEMLOGGING_PROPERTY);
        fileHandlerCountDetail = props.get(FILEHANDLER_COUNT_PROPERTY);
        retainErrorsStaticticsDetail = props.get(RETAINERRORSSTATICTICS_PROPERTY);
        log4jVersionDetail = props.get(LOG4J_VERSION_PROPERTY);
        maxHistoryFilesDetail = props.get(MAXHISTORY_FILES_PROPERTY);
        rotationOnDateChangeDetail = props.get(ROTATIONONDATECHANGE_PROPERTY);
        fileHandlerPatternDetail = props.get(FILEHANDLER_PATTERN_PROPERTY);
        fileHandlerFormatterDetail = props.get(FILEHANDLER_FORMATTER_PROPERTY);
        logFormatDateFormatDetail = props.get(LOGFORMAT_DATEFORMAT_PROPERTY);
        compressOnRotationDetail = props.get(COMPRESS_ON_ROTATION_PROPERTY);
        // Payara Notification Logging
        payaraNotificationLogFileDetail = props.get(PAYARA_NOTIFICATION_LOG_FILE_PROPERTY);
        payaraNotificationlogToFileDetail = props.get(PAYARA_NOTIFICATION_LOGTOFILE_PROPERTY);
        payaraNotificationLogRotationOnDateChangeDetail = props.get(PAYARA_NOTIFICATION_LOG_ROTATIONONDATECHANGE_PROPERTY);
        payaraNotificationLogRotationOnTimeLimitInMinutesDetail = props.get(PAYARA_NOTIFICATION_LOG_ROTATIONTIMELIMITINMINUTES_PROPERTY);
        payaraNotificationLogRotationInTimeLimitInBytesDetail = props.get(PAYARA_NOTIFICATION_LOG_ROTATIONLIMITINBYTES_PROPERTY);
        payaraNotificationLogmaxHistoryFilesDetail = props.get(PAYARA_NOTIFICATION_LOG_MAXHISTORY_FILES_PROPERTY);
        payaraNotificationLogCompressOnRotationDetail = props.get(PAYARA_NOTIFICATION_LOG_COMPRESS_ON_ROTATION_PROPERTY);
        payaraJsonUnderscorePrefix = props.get(PAYARA_JSONLOGFORMATTER_UNDERSCORE);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, LogFacade.ERROR_APPLYING_CONF, e);
    }
    Collection<Handler> handlers = getHandlerServices();
    if (handlers != null && handlers.size() > 0) {
        // add the new handlers to the root logger
        for (Handler handler : handlers) {
            addHandler(handler);
        }
    }
    // Logger.getLogger() is still synchronized.
    synchronized (java.util.logging.Logger.class) {
        synchronized (logMgr) {
            Enumeration<String> loggerNames = logMgr.getLoggerNames();
            while (loggerNames.hasMoreElements()) {
                String loggerName = loggerNames.nextElement();
                Logger logger = logMgr.getLogger(loggerName);
                if (logger == null) {
                    continue;
                }
                for (Handler handler : logger.getHandlers()) {
                    Formatter formatter = handler.getFormatter();
                    if (formatter != null && formatter instanceof UniformLogFormatter) {
                        ((UniformLogFormatter) formatter).setDelegate(agentDelegate);
                    }
                }
            }
        }
    }
    // add the filter if there is one
    try {
        Map<String, String> map = getLoggingProperties();
        String filterClassName = map.get(LoggingXMLNames.xmltoPropsMap.get("log-filter"));
        if (filterClassName != null) {
            Filter filterClass = habitat.getService(Filter.class, filterClassName);
            Logger rootLogger = Logger.getLogger("");
            if (rootLogger != null) {
                rootLogger.setFilter(filterClass);
            }
        }
    } catch (java.io.IOException ex) {
    }
    // redirect stderr and stdout, a better way to do this
    // http://blogs.sun.com/nickstephen/entry/java_redirecting_system_out_and
    Logger _ologger = LogFacade.STDOUT_LOGGER;
    stdoutOutputStream = new LoggingOutputStream(_ologger, Level.INFO);
    LoggingOutputStream.LoggingPrintStream pout = stdoutOutputStream.new LoggingPrintStream(stdoutOutputStream);
    System.setOut(pout);
    Logger _elogger = LogFacade.STDERR_LOGGER;
    stderrOutputStream = new LoggingOutputStream(_elogger, Level.SEVERE);
    LoggingOutputStream.LoggingPrintStream perr = stderrOutputStream.new LoggingPrintStream(stderrOutputStream);
    System.setErr(perr);
    // finally listen to changes to the logging.properties file
    if (logging != null) {
        fileMonitoring.monitors(logging, new FileMonitoring.FileChangeListener() {

            @Override
            public void changed(File changedFile) {
                synchronized (gfHandlers) {
                    try {
                        Map<String, String> props = getLoggingProperties();
                        loggerReference = new Vector<Logger>();
                        if (props == null)
                            return;
                        // Set<String> keys = props.keySet();
                        for (Map.Entry<String, String> entry : props.entrySet()) {
                            String a = entry.getKey();
                            String val = entry.getValue();
                            if (a.endsWith(".level")) {
                                String n = a.substring(0, a.lastIndexOf(".level"));
                                Level l = Level.parse(val);
                                if (gfHandlers.containsKey(n)) {
                                    // check if this is one of our handlers
                                    Handler h = (Handler) gfHandlers.get(n);
                                    h.setLevel(l);
                                } else if (n.equals("java.util.logging.ConsoleHandler")) {
                                    Logger logger = Logger.getLogger("");
                                    Handler[] h = logger.getHandlers();
                                    for (int i = 0; i < h.length; i++) {
                                        String name = h[i].toString();
                                        if (name.contains("java.util.logging.ConsoleHandler"))
                                            h[i].setLevel(l);
                                    }
                                } else {
                                    // Assume it is a logger
                                    Logger appLogger = Logger.getLogger(n);
                                    appLogger.setLevel(l);
                                    loggerReference.add(appLogger);
                                }
                            } else if (a.equals(SERVER_LOG_FILE_PROPERTY)) {
                                // check if file name was changed and send notification
                                if (!val.equals(serverLogFileDetail)) {
                                    PropertyChangeEvent pce = new PropertyChangeEvent(this, a, serverLogFileDetail, val);
                                    UnprocessedChangeEvents ucel = new UnprocessedChangeEvents(new UnprocessedChangeEvent(pce, "server log filename changed."));
                                    List<UnprocessedChangeEvents> b = new ArrayList();
                                    b.add(ucel);
                                    ucl.unprocessedTransactedEvents(b);
                                }
                            } else if (a.equals(HANDLER_PROPERTY)) {
                                if (!val.equals(handlerDetail)) {
                                    generateAttributeChangeEvent(HANDLER_PROPERTY, handlerDetail, props);
                                }
                            } else if (a.equals(HANDLER_SERVICES_PROPERTY)) {
                                if (!val.equals(handlerServices)) {
                                    generateAttributeChangeEvent(HANDLER_SERVICES_PROPERTY, handlerServices, props);
                                }
                            } else if (a.equals(CONSOLEHANDLER_FORMATTER_PROPERTY)) {
                                if (!val.equals(consoleHandlerFormatterDetail)) {
                                    generateAttributeChangeEvent(CONSOLEHANDLER_FORMATTER_PROPERTY, consoleHandlerFormatterDetail, props);
                                }
                            } else if (a.equals(GFFILEHANDLER_FORMATTER_PROPERTY)) {
                                if (!val.equals(gffileHandlerFormatterDetail)) {
                                    generateAttributeChangeEvent(GFFILEHANDLER_FORMATTER_PROPERTY, gffileHandlerFormatterDetail, props);
                                }
                            } else if (a.equals(ROTATIONTIMELIMITINMINUTES_PROPERTY)) {
                                if (!val.equals(rotationOnTimeLimitInMinutesDetail)) {
                                    generateAttributeChangeEvent(ROTATIONTIMELIMITINMINUTES_PROPERTY, rotationOnTimeLimitInMinutesDetail, props);
                                }
                            } else if (a.equals(FLUSHFREQUENCY_PROPERTY)) {
                                if (!val.equals(flushFrequencyDetail)) {
                                    generateAttributeChangeEvent(FLUSHFREQUENCY_PROPERTY, flushFrequencyDetail, props);
                                }
                            } else if (a.equals(FILEHANDLER_LIMIT_PROPERTY)) {
                                if (!val.equals(filterHandlerDetails)) {
                                    generateAttributeChangeEvent(FILEHANDLER_LIMIT_PROPERTY, filterHandlerDetails, props);
                                }
                            } else if (a.equals(LOGTOFILE_PROPERTY)) {
                                if (!val.equals(logToFileDetail)) {
                                    generateAttributeChangeEvent(LOGTOFILE_PROPERTY, logToFileDetail, props);
                                }
                            } else if (a.equals(LOGTOCONSOLE_PROPERTY)) {
                                if (!val.equals(logToConsoleDetail)) {
                                    generateAttributeChangeEvent(LOGTOCONSOLE_PROPERTY, logToConsoleDetail, props);
                                }
                            } else if (a.equals(ROTATIONLIMITINBYTES_PROPERTY)) {
                                if (!val.equals(rotationInTimeLimitInBytesDetail)) {
                                    generateAttributeChangeEvent(ROTATIONLIMITINBYTES_PROPERTY, rotationInTimeLimitInBytesDetail, props);
                                }
                            } else if (a.equals(USESYSTEMLOGGING_PROPERTY)) {
                                if (!val.equals(useSystemLoggingDetail)) {
                                    generateAttributeChangeEvent(USESYSTEMLOGGING_PROPERTY, useSystemLoggingDetail, props);
                                }
                            } else if (a.equals(FILEHANDLER_COUNT_PROPERTY)) {
                                if (!val.equals(fileHandlerCountDetail)) {
                                    generateAttributeChangeEvent(FILEHANDLER_COUNT_PROPERTY, fileHandlerCountDetail, props);
                                }
                            } else if (a.equals(RETAINERRORSSTATICTICS_PROPERTY)) {
                                if (!val.equals(retainErrorsStaticticsDetail)) {
                                    generateAttributeChangeEvent(RETAINERRORSSTATICTICS_PROPERTY, retainErrorsStaticticsDetail, props);
                                }
                            } else if (a.equals(LOG4J_VERSION_PROPERTY)) {
                                if (!val.equals(log4jVersionDetail)) {
                                    generateAttributeChangeEvent(LOG4J_VERSION_PROPERTY, log4jVersionDetail, props);
                                }
                            } else if (a.equals(MAXHISTORY_FILES_PROPERTY)) {
                                if (!val.equals(maxHistoryFilesDetail)) {
                                    generateAttributeChangeEvent(MAXHISTORY_FILES_PROPERTY, maxHistoryFilesDetail, props);
                                }
                            } else if (a.equals(ROTATIONONDATECHANGE_PROPERTY)) {
                                if (!val.equals(rotationOnDateChangeDetail)) {
                                    generateAttributeChangeEvent(ROTATIONONDATECHANGE_PROPERTY, rotationOnDateChangeDetail, props);
                                }
                            } else if (a.equals(FILEHANDLER_PATTERN_PROPERTY)) {
                                if (!val.equals(fileHandlerPatternDetail)) {
                                    generateAttributeChangeEvent(FILEHANDLER_PATTERN_PROPERTY, fileHandlerPatternDetail, props);
                                }
                            } else if (a.equals(FILEHANDLER_FORMATTER_PROPERTY)) {
                                if (!val.equals(fileHandlerFormatterDetail)) {
                                    generateAttributeChangeEvent(FILEHANDLER_FORMATTER_PROPERTY, fileHandlerFormatterDetail, props);
                                }
                            } else if (a.equals(LOGFORMAT_DATEFORMAT_PROPERTY)) {
                                if (!val.equals(logFormatDateFormatDetail)) {
                                    generateAttributeChangeEvent(LOGFORMAT_DATEFORMAT_PROPERTY, logFormatDateFormatDetail, props);
                                }
                            } else if (a.equals(EXCLUDE_FIELDS_PROPERTY)) {
                                val = (val == null) ? "" : val;
                                excludeFields = (excludeFields == null) ? "" : excludeFields;
                                if (!val.equals(excludeFields)) {
                                    generateAttributeChangeEvent(EXCLUDE_FIELDS_PROPERTY, excludeFields, props);
                                }
                            } else if (a.equals(MULTI_LINE_MODE_PROPERTY)) {
                                String oldVal = Boolean.toString(multiLineMode);
                                if (!val.equalsIgnoreCase(oldVal)) {
                                    generateAttributeChangeEvent(MULTI_LINE_MODE_PROPERTY, oldVal, props);
                                }
                            } else if (a.equals(COMPRESS_ON_ROTATION_PROPERTY)) {
                                if (!val.equals(compressOnRotationDetail)) {
                                    generateAttributeChangeEvent(COMPRESS_ON_ROTATION_PROPERTY, compressOnRotationDetail, props);
                                }
                            } else if (a.equals(PAYARA_NOTIFICATION_LOG_FILE_PROPERTY)) {
                                if (!val.equals(payaraNotificationLogFileDetail)) {
                                    generateAttributeChangeEvent(PAYARA_NOTIFICATION_LOG_FILE_PROPERTY, payaraNotificationLogFileDetail, props);
                                }
                            } else if (a.equals(PAYARA_NOTIFICATION_LOGTOFILE_PROPERTY)) {
                                if (!val.equals(payaraNotificationlogToFileDetail)) {
                                    generateAttributeChangeEvent(PAYARA_NOTIFICATION_LOGTOFILE_PROPERTY, payaraNotificationlogToFileDetail, props);
                                }
                            } else if (a.equals(PAYARA_NOTIFICATION_LOG_ROTATIONTIMELIMITINMINUTES_PROPERTY)) {
                                if (!val.equals(payaraNotificationLogRotationOnTimeLimitInMinutesDetail)) {
                                    generateAttributeChangeEvent(PAYARA_NOTIFICATION_LOG_ROTATIONTIMELIMITINMINUTES_PROPERTY, payaraNotificationLogRotationOnTimeLimitInMinutesDetail, props);
                                }
                            } else if (a.equals(PAYARA_NOTIFICATION_LOG_ROTATIONLIMITINBYTES_PROPERTY)) {
                                if (!val.equals(payaraNotificationLogRotationInTimeLimitInBytesDetail)) {
                                    generateAttributeChangeEvent(PAYARA_NOTIFICATION_LOG_ROTATIONLIMITINBYTES_PROPERTY, payaraNotificationLogRotationInTimeLimitInBytesDetail, props);
                                }
                            } else if (a.equals(PAYARA_NOTIFICATION_LOG_MAXHISTORY_FILES_PROPERTY)) {
                                if (!val.equals(payaraNotificationLogmaxHistoryFilesDetail)) {
                                    generateAttributeChangeEvent(PAYARA_NOTIFICATION_LOG_MAXHISTORY_FILES_PROPERTY, payaraNotificationLogmaxHistoryFilesDetail, props);
                                }
                            } else if (a.equals(PAYARA_NOTIFICATION_LOG_COMPRESS_ON_ROTATION_PROPERTY)) {
                                if (!val.equals(payaraNotificationLogCompressOnRotationDetail)) {
                                    generateAttributeChangeEvent(PAYARA_NOTIFICATION_LOG_COMPRESS_ON_ROTATION_PROPERTY, payaraNotificationLogCompressOnRotationDetail, props);
                                }
                            }
                        }
                        LOGGER.log(Level.INFO, LogFacade.UPDATED_LOG_LEVELS);
                    } catch (Exception e) {
                        LOGGER.log(Level.SEVERE, LogFacade.ERROR_APPLYING_CONF, e);
                    }
                }
            }

            @Override
            public void deleted(File deletedFile) {
                LOGGER.log(Level.WARNING, LogFacade.CONF_FILE_DELETED, deletedFile.getAbsolutePath());
            }
        });
    }
    // Log the messages that were generated very early before this Service
    // started.  Just use our own logger...
    List<EarlyLogger.LevelAndMessage> catchUp = EarlyLogger.getEarlyMessages();
    if (!catchUp.isEmpty()) {
        for (EarlyLogger.LevelAndMessage levelAndMessage : catchUp) {
            LOGGER.log(levelAndMessage.getLevel(), levelAndMessage.getMessage());
        }
        catchUp.clear();
    }
    ArrayBlockingQueue<LogRecord> catchEarlyMessage = EarlyLogHandler.earlyMessages;
    while (!catchEarlyMessage.isEmpty()) {
        LogRecord logRecord = catchEarlyMessage.poll();
        if (logRecord != null) {
            LOGGER.log(logRecord);
        }
    }
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) FileMonitoring(org.glassfish.api.admin.FileMonitoring) Formatter(java.util.logging.Formatter) JSONLogFormatter(fish.payara.enterprise.server.logging.JSONLogFormatter) EarlyLogger(com.sun.enterprise.util.EarlyLogger) EarlyLogger(com.sun.enterprise.util.EarlyLogger) PropertyChangeEvent(java.beans.PropertyChangeEvent) JSONLogFormatter(fish.payara.enterprise.server.logging.JSONLogFormatter) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) LoggingOutputStream(com.sun.common.util.logging.LoggingOutputStream) PayaraNotificationFileHandler(fish.payara.enterprise.server.logging.PayaraNotificationFileHandler) EarlyLogHandler(com.sun.enterprise.module.bootstrap.EarlyLogHandler) IOException(java.io.IOException) IOException(java.io.IOException) AgentFormatterDelegate(com.sun.enterprise.v3.logging.AgentFormatterDelegate) IOException(java.io.IOException) AgentFormatterDelegate(com.sun.enterprise.v3.logging.AgentFormatterDelegate) java.util(java.util) RunLevel(org.glassfish.hk2.runlevel.RunLevel) InitRunLevel(org.glassfish.internal.api.InitRunLevel) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 8 with Filter

use of org.glassfish.hk2.api.Filter in project Payara by payara.

the class ConfigApiTest method prepareAdminSubject.

private Subject prepareAdminSubject() {
    final ServiceLocator locator = getBaseServiceLocator();
    if (locator != null) {
        final List<ServiceHandle<? extends Object>> adminIdentities = /*                
                    (List<ServiceHandle<? extends Object>>) getBaseServiceLocator().getAllServices(
                    new Filter() {

                @Override
                public boolean matches(Descriptor d) {
                    if (d == null) {
                        return false;
                    }
                    final Set<String> contracts = d.getAdvertisedContracts();
                    return (contracts == null ? false : contracts.contains("org.glassfish.internal.api.InternalSystemAdmin"));
                }
            });
*/
        AccessController.doPrivileged(new PrivilegedAction<List<ServiceHandle<? extends Object>>>() {

            public List<ServiceHandle<? extends Object>> run() {
                List<ServiceHandle<? extends Object>> identities = (List<ServiceHandle<? extends Object>>) getBaseServiceLocator().getAllServices(new Filter() {

                    @Override
                    public boolean matches(Descriptor d) {
                        if (d == null) {
                            return false;
                        }
                        final Set<String> contracts = d.getAdvertisedContracts();
                        return (contracts == null ? false : contracts.contains("org.glassfish.internal.api.InternalSystemAdmin"));
                    }
                });
                return identities;
            }
        });
        if (!adminIdentities.isEmpty()) {
            final Object adminIdentity = adminIdentities.get(0);
            try {
                final Method getSubjectMethod = adminIdentity.getClass().getDeclaredMethod("getSubject", Subject.class);
                return (Subject) getSubjectMethod.invoke(adminIdentity);
            } catch (Exception ex) {
            // ignore - fallback to creating a subject explicitly that
            // should match the GlassFish admin identity
            }
        }
    }
    final Subject s = new Subject();
    s.getPrincipals().add(new PrincipalImpl("asadmin"));
    s.getPrincipals().add(new PrincipalImpl("_InternalSystemAdministrator_"));
    return s;
}
Also used : Set(java.util.Set) Method(java.lang.reflect.Method) Subject(javax.security.auth.Subject) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Filter(org.glassfish.hk2.api.Filter) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) Descriptor(org.glassfish.hk2.api.Descriptor) List(java.util.List)

Aggregations

ActionReport (org.glassfish.api.ActionReport)4 Config (com.sun.enterprise.config.serverbeans.Config)3 List (java.util.List)3 Optional (java.util.Optional)3 Properties (java.util.Properties)3 Logger (java.util.logging.Logger)3 TargetType (org.glassfish.config.support.TargetType)3 HttpService (com.sun.enterprise.config.serverbeans.HttpService)2 SystemPropertyConstants (com.sun.enterprise.util.SystemPropertyConstants)2 MessageFormat (java.text.MessageFormat)2 Set (java.util.Set)2 Inject (javax.inject.Inject)2 I18n (org.glassfish.api.I18n)2 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)2 LoggingOutputStream (com.sun.common.util.logging.LoggingOutputStream)1 EarlyLogHandler (com.sun.enterprise.module.bootstrap.EarlyLogHandler)1 TransactionOperationsManager (com.sun.enterprise.transaction.spi.TransactionOperationsManager)1 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 EarlyLogger (com.sun.enterprise.util.EarlyLogger)1 AgentFormatterDelegate (com.sun.enterprise.v3.logging.AgentFormatterDelegate)1