Search in sources :

Example 36 with Protocol

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

the class FindHttpProtocolResource method get.

@GET
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
public ActionReportResult get() {
    Dom dom = getEntity();
    NetworkListener nl = dom.createProxy(NetworkListener.class);
    Protocol p = nl.findHttpProtocol();
    RestActionReporter ar = new RestActionReporter();
    ar.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    ar.getTopMessagePart().getProps().put("protocol", p.getName());
    return new ActionReportResult("find-http-protocol", ar, new OptionsResult());
}
Also used : Dom(org.jvnet.hk2.config.Dom) ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) OptionsResult(org.glassfish.admin.rest.results.OptionsResult) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 37 with Protocol

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

the class CreateSsl method findOrCreateProtocol.

public Protocol findOrCreateProtocol(final String name, final boolean create) throws TransactionFailure {
    NetworkConfig networkConfig = config.getNetworkConfig();
    Protocol protocol = networkConfig.findProtocol(name);
    if (protocol == null && create) {
        protocol = (Protocol) ConfigSupport.apply(new SingleConfigCode<Protocols>() {

            @Override
            public Object run(Protocols param) throws TransactionFailure {
                Protocol newProtocol = param.createChild(Protocol.class);
                newProtocol.setName(name);
                newProtocol.setSecurityEnabled("true");
                param.getProtocol().add(newProtocol);
                return newProtocol;
            }
        }, habitat.<Protocols>getService(Protocols.class));
    }
    return protocol;
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Protocols(org.glassfish.grizzly.config.dom.Protocols) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 38 with Protocol

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

the class ProtocolSslConfigHandler method create.

// ------------------------------------------- Methods from SslConfigHandler
@Override
public void create(final CreateSsl command, final ActionReport report) {
    try {
        final Protocol protocol = command.findOrCreateProtocol(command.listenerId, false);
        if (protocol == null) {
            report.setMessage(LOCAL_STRINGS.getLocalString("create.ssl.protocol.notfound.fail", "Unable to find protocol {0}.", command.listenerId));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        } else {
            ConfigSupport.apply(new SingleConfigCode<Protocol>() {

                @Override
                public Object run(Protocol param) throws TransactionFailure {
                    Ssl newSsl = param.createChild(Ssl.class);
                    param.setSecurityEnabled("true");
                    command.populateSslElement(newSsl);
                    param.setSsl(newSsl);
                    return newSsl;
                }
            }, protocol);
        }
    } catch (TransactionFailure transactionFailure) {
        command.reportError(report, transactionFailure);
        return;
    }
    command.reportSuccess(report);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Protocol(org.glassfish.grizzly.config.dom.Protocol) Ssl(org.glassfish.grizzly.config.dom.Ssl)

Example 39 with Protocol

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

the class RuntimeRootImpl method getRESTBaseURL.

public String getRESTBaseURL() throws MalformedURLException {
    final Protocol protocol = networkConfig().getProtocols().findProtocol(ADMIN_LISTENER_NAME);
    final String scheme = Boolean.parseBoolean(protocol.getSecurityEnabled()) ? "https" : "http";
    final String host = "localhost";
    URL url = new URL(scheme, host, getRESTPort(), "/" + get_asadmin());
    return url.toString() + "/";
}
Also used : Protocol(org.glassfish.grizzly.config.dom.Protocol) URL(java.net.URL) JMXServiceURL(javax.management.remote.JMXServiceURL)

Example 40 with Protocol

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

the class AdminRESTConfigUpgrade method postConstruct.

@Override
public void postConstruct() {
    for (Config config : configs.getConfig()) {
        // we only want to handle configs that have an admin listener
        try {
            if (config.getAdminListener() == null) {
                LogRecord lr = new LogRecord(Level.FINE, String.format("Skipping config %s. No admin listener.", config.getName()));
                lr.setLoggerName(getClass().getName());
                EarlyLogHandler.earlyMessages.add(lr);
                continue;
            }
        } catch (IllegalStateException ise) {
            /*
                 * I've only seen the exception rather than
                 * getAdminListener returning null. This should
                 * typically happen for any config besides
                 * <server-config>, but we'll proceed if any
                 * config has an admin listener.
                 */
            LogRecord lr = new LogRecord(Level.FINE, String.format("Skipping config %s. getAdminListener threw: %s", config.getName(), ise.getLocalizedMessage()));
            lr.setLoggerName(getClass().getName());
            EarlyLogHandler.earlyMessages.add(lr);
            continue;
        }
        Protocols ps = config.getNetworkConfig().getProtocols();
        if (ps != null) {
            for (Protocol p : ps.getProtocol()) {
                Http h = p.getHttp();
                if (h != null && "__asadmin".equals(h.getDefaultVirtualServer())) {
                    try {
                        ConfigSupport.apply(new HttpConfigCode(), h);
                    } catch (TransactionFailure tf) {
                        LogRecord lr = new LogRecord(Level.SEVERE, "Could not upgrade http element for admin console: " + tf);
                        lr.setLoggerName(getClass().getName());
                        EarlyLogHandler.earlyMessages.add(lr);
                    }
                }
            }
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Protocols(org.glassfish.grizzly.config.dom.Protocols) LogRecord(java.util.logging.LogRecord) Config(com.sun.enterprise.config.serverbeans.Config) Http(org.glassfish.grizzly.config.dom.Http) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Aggregations

Protocol (org.glassfish.grizzly.config.dom.Protocol)42 Config (com.sun.enterprise.config.serverbeans.Config)22 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)18 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)16 CommandTarget (org.glassfish.config.support.CommandTarget)15 Target (org.glassfish.internal.api.Target)15 Protocols (org.glassfish.grizzly.config.dom.Protocols)14 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)12 ActionReport (org.glassfish.api.ActionReport)11 Http (org.glassfish.grizzly.config.dom.Http)9 PropertyVetoException (java.beans.PropertyVetoException)7 Ssl (org.glassfish.grizzly.config.dom.Ssl)7 List (java.util.List)6 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)5 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)5 ArrayList (java.util.ArrayList)4 PortUnification (org.glassfish.grizzly.config.dom.PortUnification)4 ProtocolChain (org.glassfish.grizzly.config.dom.ProtocolChain)4 ProtocolFinder (org.glassfish.grizzly.config.dom.ProtocolFinder)4 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)4