Search in sources :

Example 1 with HttpRedirect

use of org.glassfish.grizzly.config.dom.HttpRedirect 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 2 with HttpRedirect

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

the class HttpRedirectFilter method configure.

// ----------------------------------------- Methods from ConfigAwareElement
/**
 * Configuration for &lt;http-redirect&gt;.
 *
 * @param configuration filter configuration
 */
@Override
public void configure(ServiceLocator habitat, NetworkListener networkListener, ConfigBeanProxy configuration) {
    if (configuration instanceof HttpRedirect) {
        final HttpRedirect httpRedirectConfig = (HttpRedirect) configuration;
        int port = Integer.parseInt(httpRedirectConfig.getPort());
        redirectPort = port != -1 ? port : null;
        secure = Boolean.parseBoolean(httpRedirectConfig.getSecure());
    } else {
    // Retained for backwards compatibility with legacy redirect declarations.
    }
}
Also used : HttpRedirect(org.glassfish.grizzly.config.dom.HttpRedirect)

Aggregations

HttpRedirect (org.glassfish.grizzly.config.dom.HttpRedirect)2 Config (com.sun.enterprise.config.serverbeans.Config)1 ActionReport (org.glassfish.api.ActionReport)1 CommandTarget (org.glassfish.config.support.CommandTarget)1 Protocol (org.glassfish.grizzly.config.dom.Protocol)1 Protocols (org.glassfish.grizzly.config.dom.Protocols)1 Target (org.glassfish.internal.api.Target)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1