use of org.glassfish.grizzly.config.dom.Protocol in project Payara by payara.
the class CreateProtocolFinder method execute.
@Override
public void execute(AdminCommandContext context) {
Target targetUtil = services.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
report = context.getActionReport();
final Protocols protocols = config.getNetworkConfig().getProtocols();
final Protocol protocol = protocols.findProtocol(protocolName);
final Protocol target = protocols.findProtocol(targetName);
try {
validate(protocol, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, protocolName);
validate(target, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, targetName);
final Class<?> finderClass = Thread.currentThread().getContextClassLoader().loadClass(classname);
if (!org.glassfish.grizzly.portunif.ProtocolFinder.class.isAssignableFrom(finderClass)) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_FAIL_NOTFINDER), name, classname));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
PortUnification unif = (PortUnification) ConfigSupport.apply(new SingleConfigCode<Protocol>() {
@Override
public Object run(Protocol param) throws PropertyVetoException, TransactionFailure {
PortUnification pu = param.getPortUnification();
if (pu == null) {
pu = param.createChild(PortUnification.class);
param.setPortUnification(pu);
}
return pu;
}
}, protocol);
ConfigSupport.apply(new SingleConfigCode<PortUnification>() {
@Override
public Object run(PortUnification param) throws PropertyVetoException, TransactionFailure {
final List<ProtocolFinder> list = param.getProtocolFinder();
for (ProtocolFinder finder : list) {
if (name.equals(finder.getName())) {
throw new TransactionFailure(String.format("A protocol finder named %s already exists.", name));
}
}
final ProtocolFinder finder = param.createChild(ProtocolFinder.class);
finder.setName(name);
finder.setProtocol(targetName);
finder.setClassname(classname);
list.add(finder);
return null;
}
}, unif);
} catch (ValidationFailureException e) {
return;
} catch (Exception e) {
e.printStackTrace();
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_FAIL), name, e.getMessage() == null ? "No reason given" : e.getMessage()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
}
use of org.glassfish.grizzly.config.dom.Protocol 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);
if (portRange != null) {
newNetworkListener.setPortRange(portRange);
}
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);
}
use of org.glassfish.grizzly.config.dom.Protocol 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.Protocol in project Payara by payara.
the class ListProtocolFilters method execute.
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();
Protocol protocol = config.getNetworkConfig().getProtocols().findProtocol(protocolName);
if (protocol != null && protocol.getProtocolChainInstanceHandler() != null) {
final ProtocolChain chain = protocol.getProtocolChainInstanceHandler().getProtocolChain();
if (chain != null) {
for (ProtocolFilter filter : chain.getProtocolFilter()) {
report.getTopMessagePart().addChild().setMessage(filter.getName());
}
}
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.grizzly.config.dom.Protocol in project Payara by payara.
the class ListProtocolFinders method execute.
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();
Protocol protocol = config.getNetworkConfig().getProtocols().findProtocol(protocolName);
if (protocol != null) {
final PortUnification pu = protocol.getPortUnification();
if (pu != null) {
for (ProtocolFinder finder : pu.getProtocolFinder()) {
report.getTopMessagePart().addChild().setMessage(finder.getName());
}
}
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Aggregations