use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class DeleteTransport 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();
Transports transports = networkConfig.getTransports();
try {
for (Transport transport : transports.getTransport()) {
if (transportName.equalsIgnoreCase(transport.getName())) {
transportToBeRemoved = transport;
}
}
if (transportToBeRemoved == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_TRANSPORT_NOT_EXISTS), transportName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// check if the transport to be deleted is being used by
// any network listener
List<NetworkListener> nwlsnrList = transportToBeRemoved.findNetworkListeners();
for (NetworkListener nwlsnr : nwlsnrList) {
if (transportToBeRemoved.getName().equals(nwlsnr.getTransport())) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_TRANSPORT_BEINGUSED), transportName, nwlsnr.getName()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
ConfigSupport.apply(new SingleConfigCode<Transports>() {
public Object run(Transports param) {
param.getTransport().remove(transportToBeRemoved);
return transportToBeRemoved;
}
}, transports);
} catch (TransactionFailure e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_TRANSPORT_FAIL), transportName) + " " + 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 GetHttpListener method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
// Check that a configuration can be found
if (targetUtil.getConfig(target) == null) {
report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_CONFIG), target));
return;
}
Config config = targetUtil.getConfig(target);
// Check that a matching listener can be found
List<NetworkListener> listeners = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
Optional<NetworkListener> optionalListener = listeners.stream().filter(listener -> listener.getName().equals(listenerName)).findFirst();
if (!optionalListener.isPresent()) {
report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_NETWORK_LISTENER), listenerName, target));
return;
}
NetworkListener listener = optionalListener.get();
// Write message body
report.appendMessage(String.format("Name: %s\n", listener.getName()));
report.appendMessage(String.format("Enabled: %s\n", listener.getEnabled()));
report.appendMessage(String.format("Port: %s\n", listener.getPort()));
report.appendMessage(String.format("Address: %s\n", listener.getAddress()));
report.appendMessage(String.format("Protocol: %s\n", listener.getProtocol()));
if (verbose) {
report.appendMessage(String.format("Transport: %s\n", listener.getTransport()));
report.appendMessage(String.format("Type: %s\n", listener.getType()));
report.appendMessage(String.format("Thread Pool: %s\n", listener.getThreadPool()));
report.appendMessage(String.format("JK Enabled: %s\n", listener.getJkEnabled()));
report.appendMessage(String.format("JK Configuration File: %s\n", listener.getJkConfigurationFile()));
}
// Write the variables as properties
Properties properties = new Properties();
properties.put("name", listener.getName());
properties.put("enabled", listener.getEnabled());
properties.put("port", listener.getPort());
properties.put("address", listener.getAddress());
properties.put("protocol", listener.getProtocol());
properties.put("transport", listener.getTransport());
properties.put("type", listener.getType());
properties.put("threadPool", listener.getThreadPool());
properties.put("jkEnabled", listener.getJkEnabled());
properties.put("jkConfigurationFile", listener.getJkConfigurationFile());
report.setExtraProperties(properties);
}
use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class ListNetworkListeners method execute.
/**
* Executes the command with the command parameters passed as Properties where the keys are the parameter 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();
List<NetworkListener> list = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
for (NetworkListener networkListener : list) {
report.getTopMessagePart().addChild().setMessage(networkListener.getName());
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class CreateHttpListener method verifyUniqueName.
private boolean verifyUniqueName(ActionReport report, NetworkConfig networkConfig) {
// ensure we don't already have one of this name
for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
if (listener.getName().equals(listenerId)) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_LISTENER_DUPLICATE), listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return false;
}
}
return true;
}
use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class CreateNetworkListener 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();
NetworkConfig networkConfig = config.getNetworkConfig();
NetworkListeners nls = networkConfig.getNetworkListeners();
// ensure we don't have one of this name already
for (NetworkListener networkListener : nls.getNetworkListener()) {
if (networkListener.getName().equals(listenerName)) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL_DUPLICATE), listenerName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
if (!verifyUniquePort(networkConfig)) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.PORT_IN_USE), port, address));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Protocol prot = networkConfig.findProtocol(protocol);
if (prot == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND), protocol));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (prot.getHttp() == null && prot.getPortUnification() == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL_BAD_PROTOCOL), protocol));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new ConfigCode() {
public Object run(ConfigBeanProxy... params) throws TransactionFailure, PropertyVetoException {
NetworkListeners listeners = (NetworkListeners) params[0];
NetworkListener newNetworkListener = listeners.createChild(NetworkListener.class);
newNetworkListener.setProtocol(protocol);
newNetworkListener.setTransport(transport);
newNetworkListener.setEnabled(enabled.toString());
newNetworkListener.setJkEnabled(jkEnabled.toString());
newNetworkListener.setPort(port);
newNetworkListener.setThreadPool(threadPool);
newNetworkListener.setName(listenerName);
newNetworkListener.setAddress(address);
listeners.getNetworkListener().add(newNetworkListener);
((VirtualServer) params[1]).addNetworkListener(listenerName);
return newNetworkListener;
}
}, nls, findVirtualServer(prot));
} catch (TransactionFailure e) {
e.printStackTrace();
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL), listenerName) + (e.getMessage() == null ? "No reason given" : e.getMessage()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Aggregations