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);
}
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);
}
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);
}
}
}
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;
}
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()]));
}
Aggregations