Search in sources :

Example 6 with NetworkConfig

use of org.glassfish.grizzly.config.dom.NetworkConfig in project Payara by payara.

the class CreateProtocol 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;
    }
    final ActionReport report = context.getActionReport();
    // check for duplicates
    NetworkConfig networkConfig = config.getNetworkConfig();
    Protocols protocols = networkConfig.getProtocols();
    for (Protocol protocol : protocols.getProtocol()) {
        if (protocolName != null && protocolName.equalsIgnoreCase(protocol.getName())) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL_DUPLICATE), protocolName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    // Add to the <network-config>
    try {
        create(protocols, protocolName, securityEnabled);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    } catch (Exception e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL), protocolName));
        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) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 7 with NetworkConfig

use of org.glassfish.grizzly.config.dom.NetworkConfig in project Payara by payara.

the class WebSslConfigHandler method delete.

@Override
public void delete(DeleteSsl command, ActionReport report) {
    NetworkConfig netConfig = command.config.getNetworkConfig();
    NetworkListener networkListener = netConfig.getNetworkListener(command.listenerId);
    if (networkListener == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_SSL_HTTP_LISTENER_NOT_FOUND), command.listenerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    Protocol protocol = networkListener.findHttpProtocol();
    if (protocol.getSsl() == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_SSL_ELEMENT_DOES_NOT_EXIST), command.listenerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            public Object run(Protocol param) {
                param.setSsl(null);
                return null;
            }
        }, networkListener.findHttpProtocol());
    } catch (TransactionFailure e) {
        command.reportError(report, e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 8 with NetworkConfig

use of org.glassfish.grizzly.config.dom.NetworkConfig in project Payara by payara.

the class WebSslConfigHandler method create.

@Override
public void create(final CreateSsl command, ActionReport report) {
    NetworkConfig netConfig = command.config.getNetworkConfig();
    // ensure we have the specified listener
    NetworkListener listener = netConfig.getNetworkListener(command.listenerId);
    Protocol httpProtocol;
    try {
        if (listener == null) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_SSL_HTTP_NOT_FOUND), command.listenerId));
            httpProtocol = command.findOrCreateProtocol(command.listenerId);
        } else {
            httpProtocol = listener.findHttpProtocol();
            Ssl ssl = httpProtocol.getSsl();
            if (ssl != null) {
                report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_SSL_HTTP_ALREADY_EXISTS), command.listenerId));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            public Object run(Protocol param) throws TransactionFailure {
                Ssl newSsl = param.createChild(Ssl.class);
                command.populateSslElement(newSsl);
                param.setSsl(newSsl);
                return newSsl;
            }
        }, httpProtocol);
    } catch (TransactionFailure e) {
        command.reportError(report, e);
    }
    command.reportSuccess(report);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Protocol(org.glassfish.grizzly.config.dom.Protocol) CreateSsl(com.sun.enterprise.admin.commands.CreateSsl) DeleteSsl(com.sun.enterprise.admin.commands.DeleteSsl) Ssl(org.glassfish.grizzly.config.dom.Ssl) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 9 with NetworkConfig

use of org.glassfish.grizzly.config.dom.NetworkConfig in project Payara by payara.

the class EmbeddedTest method setup.

@BeforeClass
public static void setup() {
    Server.Builder builder = new Server.Builder("build");
    server = builder.build();
    NetworkConfig nc = server.getHabitat().getService(NetworkConfig.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
    List<NetworkListener> listeners = nc.getNetworkListeners().getNetworkListener();
    System.out.println("Network listener size before creation " + listeners.size());
    for (NetworkListener nl : listeners) {
        System.out.println("Network listener " + nl.getPort());
    }
    try {
        http = server.createPort(8080);
        ContainerBuilder b = server.createConfig(ContainerBuilder.Type.web);
        server.addContainer(b);
        EmbeddedWebContainer embedded = (EmbeddedWebContainer) b.create(server);
        embedded.bind(http, "http");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    listeners = nc.getNetworkListeners().getNetworkListener();
    System.out.println("Network listener size after creation " + listeners.size());
    Assert.assertTrue(listeners.size() == 1);
    for (NetworkListener nl : listeners) {
        System.out.println("Network listener " + nl.getPort());
    }
    Collection<NetworkListener> cnl = server.getHabitat().getAllServices(NetworkListener.class);
    System.out.println("Network listener size after creation " + cnl.size());
    for (NetworkListener nl : cnl) {
        System.out.println("Network listener " + nl.getPort());
    }
    server.addContainer(ContainerBuilder.Type.all);
}
Also used : ContainerBuilder(org.glassfish.internal.embedded.ContainerBuilder) Server(org.glassfish.internal.embedded.Server) EmbeddedWebContainer(org.glassfish.api.embedded.web.EmbeddedWebContainer) ContainerBuilder(org.glassfish.internal.embedded.ContainerBuilder) Builder(org.glassfish.internal.embedded.ScatteredArchive.Builder) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) IOException(java.io.IOException) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) BeforeClass(org.junit.BeforeClass)

Example 10 with NetworkConfig

use of org.glassfish.grizzly.config.dom.NetworkConfig in project Payara by payara.

the class GrizzlyConfigSchemaMigrator method postConstruct.

public void postConstruct() {
    for (Config config : configs.getConfig()) {
        currentConfig = config;
        try {
            final NetworkConfig networkConfig = currentConfig.getNetworkConfig();
            if (networkConfig == null) {
                createFromScratch();
            }
            normalizeThreadPools();
            if (currentConfig.getHttpService() != null) {
                promoteHttpServiceProperties(currentConfig.getHttpService());
                promoteVirtualServerProperties(currentConfig.getHttpService());
            } else {
                // this only happens during some unit tests
                logger.log(Level.WARNING, ConfigApiLoggerInfo.nullHttpService, new String[] { currentConfig.getName() });
            }
            promoteSystemProperties();
            addAsadminProtocol(currentConfig.getNetworkConfig());
        } catch (TransactionFailure tf) {
            logger.log(Level.SEVERE, ConfigApiLoggerInfo.failUpgradeDomain, tf);
            throw new RuntimeException(tf);
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig)

Aggregations

NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)33 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)21 Config (com.sun.enterprise.config.serverbeans.Config)18 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)16 Protocol (org.glassfish.grizzly.config.dom.Protocol)14 ActionReport (org.glassfish.api.ActionReport)10 CommandTarget (org.glassfish.config.support.CommandTarget)10 Target (org.glassfish.internal.api.Target)10 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)6 Protocols (org.glassfish.grizzly.config.dom.Protocols)6 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)5 HttpService (com.sun.enterprise.config.serverbeans.HttpService)4 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)4 PropertyVetoException (java.beans.PropertyVetoException)3 Http (org.glassfish.grizzly.config.dom.Http)3 Ssl (org.glassfish.grizzly.config.dom.Ssl)3 Transport (org.glassfish.grizzly.config.dom.Transport)3 JavaConfig (com.sun.enterprise.config.serverbeans.JavaConfig)2 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2 Result (com.sun.enterprise.util.Result)2