Search in sources :

Example 91 with org.jvnet.hk2.config

use of org.jvnet.hk2.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 92 with org.jvnet.hk2.config

use of org.jvnet.hk2.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 93 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class CreateHttpListener 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) {
    final ActionReport report = context.getActionReport();
    if (!validateInputs(report)) {
        return;
    }
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    networkConfig = config.getNetworkConfig();
    HttpService httpService = config.getHttpService();
    if (!(verifyUniqueName(report, networkConfig) && verifyUniquePort(report, networkConfig) && verifyDefaultVirtualServer(report))) {
        return;
    }
    VirtualServer vs = httpService.getVirtualServerByName(defaultVirtualServer);
    boolean listener = false;
    boolean protocol = false;
    boolean transport = false;
    try {
        transport = createOrGetTransport(null);
        protocol = createProtocol(context);
        createHttp(context);
        final ThreadPool threadPool = getThreadPool(networkConfig);
        listener = createNetworkListener(networkConfig, transport, threadPool);
        updateVirtualServer(vs);
    } catch (TransactionFailure e) {
        try {
            if (listener) {
                deleteListener(context);
            }
            if (protocol) {
                deleteProtocol(context);
            }
            if (transport) {
                deleteTransport(context);
            }
        } catch (Exception e1) {
            if (logger.isLoggable(Level.INFO)) {
                logger.log(Level.INFO, e.getMessage(), e);
            }
            throw new RuntimeException(e.getMessage());
        }
        if (logger.isLoggable(Level.INFO)) {
            logger.log(Level.INFO, e.getMessage(), e);
        }
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_LISTENER_FAIL), listenerId, e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
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) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) ActionReport(org.glassfish.api.ActionReport) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) PropertyVetoException(java.beans.PropertyVetoException)

Example 94 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class CreateHttpRedirect method execute.

// ----------------------------------------------- Methods from AdminCommand
@Override
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();
    // check for duplicates
    Protocols protocols = config.getNetworkConfig().getProtocols();
    Protocol protocol = null;
    for (Protocol p : protocols.getProtocol()) {
        if (protocolName.equals(p.getName())) {
            protocol = p;
        }
    }
    if (protocol == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (protocol.getHttpRedirect() != null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_REDIRECT_FAIL_DUPLICATE), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            public Object run(Protocol param) throws TransactionFailure {
                HttpRedirect httpRedirect = param.createChild(HttpRedirect.class);
                httpRedirect.setPort(port);
                httpRedirect.setSecure(secure);
                param.setHttpRedirect(httpRedirect);
                return httpRedirect;
            }
        }, protocol);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_REDIRECT_FAIL), protocolName) + (e.getMessage() == null ? "No reason given." : e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Protocols(org.glassfish.grizzly.config.dom.Protocols) HttpRedirect(org.glassfish.grizzly.config.dom.HttpRedirect) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 95 with org.jvnet.hk2.config

use of org.jvnet.hk2.config in project Payara by payara.

the class CreateProtocolFilter 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);
        final Class<?> filterClass = Thread.currentThread().getContextClassLoader().loadClass(classname);
        if (!org.glassfish.grizzly.filterchain.Filter.class.isAssignableFrom(filterClass)) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_FAIL_NOTFILTER), name, classname));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        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();
                for (ProtocolFilter filter : list) {
                    if (name.equals(filter.getName())) {
                        throw new TransactionFailure(String.format("A protocol filter named %s already exists.", name));
                    }
                }
                final ProtocolFilter filter = param.createChild(ProtocolFilter.class);
                filter.setName(name);
                filter.setClassname(classname);
                list.add(filter);
                return null;
            }
        }, chain);
    } catch (ValidationFailureException e) {
        return;
    } catch (Exception e) {
        e.printStackTrace();
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_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) ProtocolFilter(org.glassfish.grizzly.config.dom.ProtocolFilter) ProtocolChainInstanceHandler(org.glassfish.grizzly.config.dom.ProtocolChainInstanceHandler) ProtocolChain(org.glassfish.grizzly.config.dom.ProtocolChain) List(java.util.List) Protocol(org.glassfish.grizzly.config.dom.Protocol) ProtocolFilter(org.glassfish.grizzly.config.dom.ProtocolFilter)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)81 Config (com.sun.enterprise.config.serverbeans.Config)69 ActionReport (org.glassfish.api.ActionReport)60 PropertyVetoException (java.beans.PropertyVetoException)59 Property (org.jvnet.hk2.config.types.Property)50 CommandTarget (org.glassfish.config.support.CommandTarget)24 Target (org.glassfish.internal.api.Target)23 Properties (java.util.Properties)21 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)17 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)17 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)15 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 Server (com.sun.enterprise.config.serverbeans.Server)14 List (java.util.List)14 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)14 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 IOException (java.io.IOException)10 Map (java.util.Map)10 Cluster (com.sun.enterprise.config.serverbeans.Cluster)9