use of org.glassfish.grizzly.config.dom.Protocols 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.Protocols in project Payara by payara.
the class CreateHttp 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();
// 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.getHttp() != null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_DUPLICATE), protocolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// Add to the <network-config>
try {
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
public Object run(Protocol param) throws TransactionFailure {
Http http = param.createChild(Http.class);
final FileCache cache = http.createChild(FileCache.class);
cache.setEnabled("false");
http.setFileCache(cache);
http.setDefaultVirtualServer(defaultVirtualServer);
http.setDnsLookupEnabled(dnsLookupEnabled == null ? null : dnsLookupEnabled.toString());
http.setMaxConnections(maxConnections);
http.setRequestTimeoutSeconds(requestTimeoutSeconds);
http.setTimeoutSeconds(timeoutSeconds);
http.setXpoweredBy(xPoweredBy == null ? null : xPoweredBy.toString());
http.setServerHeader(serverHeader == null ? null : serverHeader.toString());
http.setXframeOptions(xFrameOptions == null ? null : xFrameOptions.toString());
http.setServerName(serverName);
// HTTP2 options
http.setHttp2Enabled(http2Enabled);
if (http2MaxConcurrentStreams != null) {
http.setHttp2MaxConcurrentStreams(http2MaxConcurrentStreams);
}
if (http2InitialWindowSizeInBytes != null) {
http.setHttp2InitialWindowSizeInBytes(http2InitialWindowSizeInBytes);
}
if (http2MaxFramePayloadSizeInBytes != null) {
http.setHttp2MaxFramePayloadSizeInBytes(http2MaxFramePayloadSizeInBytes);
}
if (http2MaxHeaderListSizeInBytes != null) {
http.setHttp2MaxHeaderListSizeInBytes(http2MaxHeaderListSizeInBytes);
}
if (http2StreamsHighWaterMark != null) {
http.setHttp2StreamsHighWaterMark(http2StreamsHighWaterMark.toString());
}
if (http2CleanPercentage != null) {
http.setHttp2CleanPercentage(http2CleanPercentage.toString());
}
if (http2CleanFrequencyCheck != null) {
http.setHttp2CleanFrequencyCheck(http2CleanFrequencyCheck);
}
if (http2DisableCipherCheck != null) {
http.setHttp2DisableCipherCheck(http2DisableCipherCheck);
}
if (http2PushEnabled != null) {
http.setHttp2PushEnabled(http2PushEnabled);
}
param.setHttp(http);
return http;
}
}, 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);
}
use of org.glassfish.grizzly.config.dom.Protocols 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.Protocols 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.Protocols in project Payara by payara.
the class CreateProtocol 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();
// check for duplicates
NetworkConfig networkConfig = config.getNetworkConfig();
Protocols protocols = networkConfig.getProtocols();
for (Protocol protocol : protocols.getProtocol()) {
if (protocolName != null && protocolName.equalsIgnoreCase(protocol.getName())) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL_DUPLICATE), protocolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
// Add to the <network-config>
try {
create(protocols, protocolName, securityEnabled);
} catch (TransactionFailure e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL), protocolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
} catch (Exception e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL), protocolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Aggregations