Search in sources :

Example 81 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class DeleteHttpListener method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and
 * the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    ActionReport report = context.getActionReport();
    networkConfig = config.getNetworkConfig();
    if (!exists()) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_LISTENER_NOT_EXISTS), listenerId));
        report.setActionExitCode(ExitCode.FAILURE);
        return;
    }
    try {
        NetworkListener ls = networkConfig.getNetworkListener(listenerId);
        final String name = ls.getProtocol();
        VirtualServer vs = config.getHttpService().getVirtualServerByName(ls.findHttpProtocol().getHttp().getDefaultVirtualServer());
        ConfigSupport.apply(new DeleteNetworkListener(), networkConfig.getNetworkListeners());
        ConfigSupport.apply(new UpdateVirtualServer(), vs);
        cleanUp(name);
        report.setActionExitCode(ExitCode.SUCCESS);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_LISTENER_FAIL), listenerId));
        report.setActionExitCode(ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ActionReport(org.glassfish.api.ActionReport) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 82 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class DeleteNetworkListener method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and
 * the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    ActionReport report = context.getActionReport();
    NetworkListeners networkListeners = config.getNetworkConfig().getNetworkListeners();
    try {
        if (findListener(networkListeners, report)) {
            final Protocol httpProtocol = listenerToBeRemoved.findHttpProtocol();
            final VirtualServer virtualServer = config.getHttpService().getVirtualServerByName(httpProtocol.getHttp().getDefaultVirtualServer());
            ConfigSupport.apply(new ConfigCode() {

                public Object run(ConfigBeanProxy... params) throws PropertyVetoException {
                    final NetworkListeners listeners = (NetworkListeners) params[0];
                    final VirtualServer server = (VirtualServer) params[1];
                    listeners.getNetworkListener().remove(listenerToBeRemoved);
                    server.removeNetworkListener(listenerToBeRemoved.getName());
                    return listenerToBeRemoved;
                }
            }, networkListeners, virtualServer);
        }
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_NETWORK_LISTENER_FAIL), networkListenerName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCode(org.jvnet.hk2.config.ConfigCode) Config(com.sun.enterprise.config.serverbeans.Config) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 83 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class DeleteProtocolFilter method execute.

@Override
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    report = context.getActionReport();
    try {
        final Protocols protocols = config.getNetworkConfig().getProtocols();
        final Protocol protocol = protocols.findProtocol(protocolName);
        validate(protocol, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, protocolName);
        ProtocolChainInstanceHandler handler = getHandler(protocol);
        ProtocolChain chain = getChain(handler);
        ConfigSupport.apply(new SingleConfigCode<ProtocolChain>() {

            @Override
            public Object run(ProtocolChain param) throws PropertyVetoException, TransactionFailure {
                final List<ProtocolFilter> list = param.getProtocolFilter();
                List<ProtocolFilter> newList = new ArrayList<ProtocolFilter>();
                for (final ProtocolFilter filter : list) {
                    if (!name.equals(filter.getName())) {
                        newList.add(filter);
                    }
                }
                if (list.size() == newList.size()) {
                    throw new RuntimeException(String.format("No filter named %s found for protocol %s", name, protocolName));
                }
                param.setProtocolFilter(newList);
                return null;
            }
        }, chain);
        cleanChain(chain);
        cleanHandler(handler);
    } catch (ValidationFailureException e) {
        return;
    } catch (Exception e) {
        e.printStackTrace();
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_FAIL), name, e.getMessage() == null ? "No reason given" : e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Protocols(org.glassfish.grizzly.config.dom.Protocols) Config(com.sun.enterprise.config.serverbeans.Config) PropertyVetoException(java.beans.PropertyVetoException) PropertyVetoException(java.beans.PropertyVetoException) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ProtocolChainInstanceHandler(org.glassfish.grizzly.config.dom.ProtocolChainInstanceHandler) ProtocolChain(org.glassfish.grizzly.config.dom.ProtocolChain) ArrayList(java.util.ArrayList) List(java.util.List) Protocol(org.glassfish.grizzly.config.dom.Protocol) ProtocolFilter(org.glassfish.grizzly.config.dom.ProtocolFilter)

Example 84 with Config

use of com.sun.enterprise.config.serverbeans.Config 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 85 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class ListHttpListeners method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the parameter names and
 * the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    final ActionReport report = context.getActionReport();
    List<NetworkListener> list = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
    int size = 0;
    for (NetworkListener networkListener : list) {
        size = Math.max(size, networkListener.getName().length());
    }
    final String format = "%-" + (size + 2) + "s %-6s";
    if (verbose) {
        report.getTopMessagePart().addChild().setMessage(String.format(format, "NAME", "PORT"));
    }
    for (NetworkListener listener : list) {
        if (listener.findHttpProtocol().getHttp() != null) {
            report.getTopMessagePart().addChild().setMessage(String.format(format, listener.getName(), verbose ? listener.getPort() : ""));
        }
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)152 ActionReport (org.glassfish.api.ActionReport)73 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)50 PropertyVetoException (java.beans.PropertyVetoException)34 Target (org.glassfish.internal.api.Target)31 CommandTarget (org.glassfish.config.support.CommandTarget)30 Properties (java.util.Properties)28 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)23 Protocol (org.glassfish.grizzly.config.dom.Protocol)20 HashMap (java.util.HashMap)17 Server (com.sun.enterprise.config.serverbeans.Server)15 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)15 Logger (java.util.logging.Logger)14 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)13 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)10 Level (java.util.logging.Level)10 LogRecord (java.util.logging.LogRecord)10