Search in sources :

Example 6 with NetworkListener

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

the class DeleteHttp 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 networkConfig = config.getNetworkConfig();
    Protocols protocols = networkConfig.getProtocols();
    try {
        for (Protocol protocol : protocols.getProtocol()) {
            if (protocolName.equalsIgnoreCase(protocol.getName())) {
                protocolToBeRemoved = protocol;
            }
        }
        if (protocolToBeRemoved == null) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_NOTEXISTS), protocolName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        // check if the protocol whose http-redirect to be deleted is being used by
        // any network listener, then do not delete it.
        List<NetworkListener> nwlsnrList = protocolToBeRemoved.findNetworkListeners();
        for (NetworkListener nwlsnr : nwlsnrList) {
            if (protocolToBeRemoved.getName().equals(nwlsnr.getProtocol())) {
                report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_PROTOCOL_BEING_USED), protocolName, nwlsnr.getName()));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            public Object run(Protocol param) {
                param.setHttp(null);
                return null;
            }
        }, protocolToBeRemoved);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_REDIRECT_FAIL), protocolName) + e.getLocalizedMessage());
        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) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 7 with NetworkListener

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

the class DeleteProtocol 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 networkConfig = config.getNetworkConfig();
    Protocols protocols = networkConfig.getProtocols();
    try {
        protocol = protocols.findProtocol(protocolName);
        if (protocol == null) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_PROTOCOL_NOT_EXISTS), protocolName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        // check if the protocol to be deleted is being used by
        // any network listener
        List<NetworkListener> nwlsnrList = protocol.findNetworkListeners();
        for (NetworkListener nwlsnr : nwlsnrList) {
            if (protocol.getName().equals(nwlsnr.getProtocol())) {
                report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_PROTOCOL_BEING_USED), protocolName, nwlsnr.getName()));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        ConfigSupport.apply(new SingleConfigCode<Protocols>() {

            public Object run(Protocols param) {
                param.getProtocol().remove(protocol);
                return protocol;
            }
        }, protocols);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_PROTOCOL_FAIL), protocolName) + e.getLocalizedMessage());
        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) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 8 with NetworkListener

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

the class VirtualServer method addProbes.

/**
 * Sets all the monitoring probes used in the virtual server
 * @param globalAccessLoggingEnabled
 * @see org.glassfish.grizzly.http.HttpProbe
 */
void addProbes(boolean globalAccessLoggingEnabled) {
    for (final NetworkListener listener : getGrizzlyNetworkListeners()) {
        try {
            final GrizzlyProxy proxy = (GrizzlyProxy) grizzlyService.lookupNetworkProxy(listener);
            if (proxy != null) {
                GenericGrizzlyListener grizzlyListener = (GenericGrizzlyListener) proxy.getUnderlyingListener();
                List<HttpCodecFilter> codecFilters = grizzlyListener.getFilters(HttpCodecFilter.class);
                if (codecFilters == null || codecFilters.isEmpty()) {
                    // if it's AJP listener - it's ok if we didn't find HttpCodecFilter
                    if (grizzlyListener.isAjpEnabled()) {
                        continue;
                    }
                    _logger.log(Level.SEVERE, LogFacade.CODE_FILTERS_NULL, new Object[] { listener.getName(), codecFilters });
                } else {
                    for (HttpCodecFilter codecFilter : codecFilters) {
                        if (codecFilter.getMonitoringConfig().getProbes().length == 0) {
                            HttpProbeImpl httpProbe = new HttpProbeImpl(listener, isAccessLoggingEnabled(globalAccessLoggingEnabled));
                            codecFilter.getMonitoringConfig().addProbes(httpProbe);
                        }
                    }
                }
                grizzlyListener.getTransport().getConnectionMonitoringConfig().addProbes(new ConnectionProbe.Adapter() {

                    RequestProbeProvider requestProbeProvider = webContainer.getRequestProbeProvider();

                    @Override
                    public void onReadEvent(Connection connection, Buffer data, int size) {
                        if (requestProbeProvider != null) {
                            requestProbeProvider.dataReceivedEvent(size, _id);
                        }
                    }

                    @Override
                    public void onWriteEvent(Connection connection, Buffer data, long size) {
                        if (requestProbeProvider != null) {
                            requestProbeProvider.dataSentEvent(size, _id);
                        }
                    }
                });
            } else {
                // check the listener is enabled before spitting out the SEVERE log
                if (Boolean.parseBoolean(listener.getEnabled())) {
                    _logger.log(Level.SEVERE, LogFacade.PROXY_NULL, new Object[] { listener.getName() });
                }
            }
        } catch (Exception ex) {
            _logger.log(Level.SEVERE, LogFacade.ADD_HTTP_PROBES_ERROR, ex);
        }
    }
}
Also used : Buffer(org.glassfish.grizzly.Buffer) GrizzlyProxy(com.sun.enterprise.v3.services.impl.GrizzlyProxy) GenericGrizzlyListener(org.glassfish.grizzly.config.GenericGrizzlyListener) Connection(org.glassfish.grizzly.Connection) HttpCodecFilter(org.glassfish.grizzly.http.HttpCodecFilter) ConfigException(org.glassfish.embeddable.web.ConfigException) IOException(java.io.IOException) GlassFishException(org.glassfish.embeddable.GlassFishException) ConnectionProbe(org.glassfish.grizzly.ConnectionProbe) RequestProbeProvider(org.glassfish.web.admin.monitor.RequestProbeProvider) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 9 with NetworkListener

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

the class VirtualServer method getHttpProbeImpl.

private List<HttpProbeImpl> getHttpProbeImpl() {
    List<HttpProbeImpl> httpProbes = new ArrayList<>();
    for (final NetworkListener listener : getGrizzlyNetworkListeners()) {
        final GrizzlyProxy proxy = (GrizzlyProxy) grizzlyService.lookupNetworkProxy(listener);
        if (proxy != null) {
            GenericGrizzlyListener grizzlyListener = (GenericGrizzlyListener) proxy.getUnderlyingListener();
            List<HttpCodecFilter> codecFilters = grizzlyListener.getFilters(HttpCodecFilter.class);
            if (codecFilters != null && !codecFilters.isEmpty()) {
                for (HttpCodecFilter codecFilter : codecFilters) {
                    HttpProbe[] probes = codecFilter.getMonitoringConfig().getProbes();
                    if (probes != null) {
                        for (HttpProbe probe : probes) {
                            if (probe instanceof HttpProbeImpl) {
                                httpProbes.add((HttpProbeImpl) probe);
                            }
                        }
                    }
                }
            }
        }
    }
    return httpProbes;
}
Also used : GrizzlyProxy(com.sun.enterprise.v3.services.impl.GrizzlyProxy) GenericGrizzlyListener(org.glassfish.grizzly.config.GenericGrizzlyListener) HttpCodecFilter(org.glassfish.grizzly.http.HttpCodecFilter) HttpProbe(org.glassfish.grizzly.http.HttpProbe) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 10 with NetworkListener

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

the class WebContainer method configureHostPortNumbers.

/**
 * Configures the given virtual server with the port numbers of its
 * associated http listeners.
 *
 * @param vs        The virtual server to configure
 * @param listeners The http listeners with which the given virtual
 *                  server is associated
 */
protected void configureHostPortNumbers(VirtualServer vs, HashSet<NetworkListener> listeners) {
    boolean addJkListenerName = jkConnector != null && !vs.getName().equalsIgnoreCase(org.glassfish.api.web.Constants.ADMIN_VS);
    List<String> listenerNames = new ArrayList<String>();
    for (NetworkListener listener : listeners) {
        if (Boolean.valueOf(listener.getEnabled())) {
            listenerNames.add(listener.getName());
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, LogFacade.VIRTUAL_SERVER_SET_LISTENER_NAME);
            }
        } else {
            if (vs.getName().equalsIgnoreCase(org.glassfish.api.web.Constants.ADMIN_VS)) {
                String msg = rb.getString(LogFacade.MUST_NOT_DISABLE);
                msg = MessageFormat.format(msg, listener.getName(), vs.getName());
                throw new IllegalArgumentException(msg);
            }
        }
    }
    if (addJkListenerName && (!listenerNames.contains(jkConnector.getName()))) {
        listenerNames.add(jkConnector.getName());
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, LogFacade.VIRTUAL_SERVER_SET_JK_LISTENER_NAME, new Object[] { vs.getID(), jkConnector.getName() });
        }
    }
    vs.setNetworkListenerNames(listenerNames.toArray(new String[listenerNames.size()]));
}
Also used : ArrayList(java.util.ArrayList) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)74 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)21 Protocol (org.glassfish.grizzly.config.dom.Protocol)18 Config (com.sun.enterprise.config.serverbeans.Config)17 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)14 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)12 Test (org.junit.Test)11 ActionReport (org.glassfish.api.ActionReport)10 CommandTarget (org.glassfish.config.support.CommandTarget)9 Target (org.glassfish.internal.api.Target)9 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)8 HttpService (com.sun.enterprise.config.serverbeans.HttpService)7 ArrayList (java.util.ArrayList)7 Protocols (org.glassfish.grizzly.config.dom.Protocols)7 ObservableBean (org.jvnet.hk2.config.ObservableBean)7 Transactions (org.jvnet.hk2.config.Transactions)7 IOException (java.io.IOException)6 Http (org.glassfish.grizzly.config.dom.Http)6 PropertyVetoException (java.beans.PropertyVetoException)5 ThreadPool (org.glassfish.grizzly.config.dom.ThreadPool)5