use of org.glassfish.grizzly.config.dom.Protocol in project Payara by payara.
the class DeleteHttpRedirect 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;
}
Protocol protocolToBeRemoved = null;
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 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.setHttpRedirect(null);
return null;
}
}, protocolToBeRemoved);
} catch (TransactionFailure e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_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 DeleteNetworkListener 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();
NetworkListeners networkListeners = config.getNetworkConfig().getNetworkListeners();
try {
if (findListener(networkListeners, report)) {
final Protocol httpProtocol = listenerToBeRemoved.findHttpProtocol();
final VirtualServer virtualServer = config.getHttpService().getVirtualServerByName(httpProtocol.getHttp().getDefaultVirtualServer());
ConfigSupport.apply(new ConfigCode() {
public Object run(ConfigBeanProxy... params) throws PropertyVetoException {
final NetworkListeners listeners = (NetworkListeners) params[0];
final VirtualServer server = (VirtualServer) params[1];
listeners.getNetworkListener().remove(listenerToBeRemoved);
server.removeNetworkListener(listenerToBeRemoved.getName());
return listenerToBeRemoved;
}
}, networkListeners, virtualServer);
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_NETWORK_LISTENER_FAIL), networkListenerName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
use of org.glassfish.grizzly.config.dom.Protocol in project Payara by payara.
the class DeleteProtocolFilter 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();
try {
final Protocols protocols = config.getNetworkConfig().getProtocols();
final Protocol protocol = protocols.findProtocol(protocolName);
validate(protocol, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, protocolName);
ProtocolChainInstanceHandler handler = getHandler(protocol);
ProtocolChain chain = getChain(handler);
ConfigSupport.apply(new SingleConfigCode<ProtocolChain>() {
@Override
public Object run(ProtocolChain param) throws PropertyVetoException, TransactionFailure {
final List<ProtocolFilter> list = param.getProtocolFilter();
List<ProtocolFilter> newList = new ArrayList<ProtocolFilter>();
for (final ProtocolFilter filter : list) {
if (!name.equals(filter.getName())) {
newList.add(filter);
}
}
if (list.size() == newList.size()) {
throw new RuntimeException(String.format("No filter named %s found for protocol %s", name, protocolName));
}
param.setProtocolFilter(newList);
return null;
}
}, chain);
cleanChain(chain);
cleanHandler(handler);
} catch (ValidationFailureException e) {
return;
} catch (Exception e) {
e.printStackTrace();
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_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 DeleteProtocolFilter method getChain.
private ProtocolChain getChain(ProtocolChainInstanceHandler handler) throws TransactionFailure {
ProtocolChain chain = handler.getProtocolChain();
if ((chain == null) && (report != null)) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.NOT_FOUND), "protocol-chain", handler.getParent(Protocol.class).getName()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
return chain;
}
use of org.glassfish.grizzly.config.dom.Protocol 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);
}
Aggregations