use of org.jvnet.hk2.config 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.jvnet.hk2.config in project Payara by payara.
the class GetProtocol 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<Protocol> protocols = config.getNetworkConfig().getProtocols().getProtocol();
Optional<Protocol> optionalProtocol = protocols.stream().filter(protocol -> protocol.getName().equals(protocolName)).findFirst();
if (!optionalProtocol.isPresent()) {
report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_PROTOCOL), protocolName, target));
return;
}
Protocol protocol = optionalProtocol.get();
// Write message body
report.appendMessage(String.format("Name: %s\n", protocol.getName()));
// Write HTTP config options
report.appendMessage("\nHTTP:\n");
report.appendMessage(String.format("Server Name: %s\n", protocol.getHttp().getServerName()));
report.appendMessage(String.format("Max Connections: %s seconds\n", protocol.getHttp().getMaxConnections()));
report.appendMessage(String.format("Default Virtual Server: %s\n", protocol.getHttp().getDefaultVirtualServer()));
report.appendMessage(String.format("Server Header: %s\n", protocol.getHttp().getServerHeader()));
report.appendMessage(String.format("X-Powered-By: %s\n", protocol.getHttp().getXpoweredBy()));
if (verbose) {
report.appendMessage(String.format("Request Timeout: %s seconds\n", protocol.getHttp().getRequestTimeoutSeconds()));
report.appendMessage(String.format("Timeout: %s seconds\n", protocol.getHttp().getTimeoutSeconds()));
report.appendMessage(String.format("DNS Lookup Enabled: %s\n", protocol.getHttp().getDnsLookupEnabled()));
report.appendMessage(String.format("X Frame Options: %s\n", protocol.getHttp().getXframeOptions()));
}
// Write HTTP/2 config options
report.appendMessage("\nHTTP/2:\n");
report.appendMessage(String.format("Enabled: %s\n", protocol.getHttp().isHttp2Enabled()));
if (protocol.getHttp().isHttp2Enabled()) {
report.appendMessage(String.format("Push Enabled: %s\n", protocol.getHttp().isHttp2PushEnabled()));
report.appendMessage(String.format("Cipher Check: %s\n", !protocol.getHttp().isHttp2DisableCipherCheck()));
if (verbose) {
report.appendMessage(String.format("Max Concurrent Streams: %s\n", protocol.getHttp().getHttp2MaxConcurrentStreams()));
report.appendMessage(String.format("Initial Window Size: %s bytes\n", protocol.getHttp().getHttp2InitialWindowSizeInBytes()));
report.appendMessage(String.format("Max Frame Payload Size: %s bytes\n", protocol.getHttp().getHttp2MaxFramePayloadSizeInBytes()));
report.appendMessage(String.format("Max Header List Size: %s bytes\n", protocol.getHttp().getHttp2MaxHeaderListSizeInBytes()));
report.appendMessage(String.format("Streams High Water Mark: %s\n", protocol.getHttp().getHttp2StreamsHighWaterMark()));
report.appendMessage(String.format("Clean Percentage: %s\n", protocol.getHttp().getHttp2CleanPercentage()));
report.appendMessage(String.format("Clean Frequency Check: %s\n", protocol.getHttp().getHttp2CleanFrequencyCheck()));
}
}
// Write the variables as properties
Properties properties = new Properties();
properties.put("name", protocol.getName());
properties.put("serverName", protocol.getHttp().getServerName() == null ? "null" : protocol.getHttp().getServerName());
properties.put("maxConnections", protocol.getHttp().getMaxConnections());
properties.put("defaultVirtualServer", protocol.getHttp().getDefaultVirtualServer());
properties.put("serverHeader", protocol.getHttp().getServerHeader());
properties.put("xPoweredBy", protocol.getHttp().getXpoweredBy());
properties.put("requestTimeoutSeconds", protocol.getHttp().getRequestTimeoutSeconds());
properties.put("timeoutSeconds", protocol.getHttp().getTimeoutSeconds());
properties.put("dnsLookupEnabled", protocol.getHttp().getDnsLookupEnabled());
properties.put("xFrameOptions", protocol.getHttp().getXframeOptions());
properties.put("http2Enabled", protocol.getHttp().isHttp2Enabled());
properties.put("http2MaxConcurrentStreams", protocol.getHttp().getHttp2MaxConcurrentStreams());
properties.put("http2InitialWindowSizeInBytes", protocol.getHttp().getHttp2InitialWindowSizeInBytes());
properties.put("http2MaxFramePayloadSizeInBytes", protocol.getHttp().getHttp2MaxFramePayloadSizeInBytes());
properties.put("http2MaxHeaderListSizeInBytes", protocol.getHttp().getHttp2MaxHeaderListSizeInBytes());
properties.put("http2StreamsHighWaterMark", protocol.getHttp().getHttp2StreamsHighWaterMark());
properties.put("http2CleanPercentage", protocol.getHttp().getHttp2CleanPercentage());
properties.put("http2CleanFrequencyCheck", protocol.getHttp().getHttp2CleanFrequencyCheck());
properties.put("http2DisableCipherCheck", protocol.getHttp().isHttp2DisableCipherCheck());
properties.put("http2PushEnabled", protocol.getHttp().isHttp2PushEnabled());
report.setExtraProperties(properties);
}
use of org.jvnet.hk2.config in project Payara by payara.
the class CreateHttpListener 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) {
final ActionReport report = context.getActionReport();
if (!validateInputs(report)) {
return;
}
Target targetUtil = services.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
networkConfig = config.getNetworkConfig();
HttpService httpService = config.getHttpService();
if (!(verifyUniqueName(report, networkConfig) && verifyUniquePort(report, networkConfig) && verifyDefaultVirtualServer(report))) {
return;
}
VirtualServer vs = httpService.getVirtualServerByName(defaultVirtualServer);
boolean listener = false;
boolean protocol = false;
boolean transport = false;
try {
transport = createOrGetTransport(null);
protocol = createProtocol(context);
createHttp(context);
final ThreadPool threadPool = getThreadPool(networkConfig);
listener = createNetworkListener(networkConfig, transport, threadPool);
updateVirtualServer(vs);
} catch (TransactionFailure e) {
try {
if (listener) {
deleteListener(context);
}
if (protocol) {
deleteProtocol(context);
}
if (transport) {
deleteTransport(context);
}
} catch (Exception e1) {
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, e.getMessage(), e);
}
throw new RuntimeException(e.getMessage());
}
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, e.getMessage(), e);
}
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_LISTENER_FAIL), listenerId, e.getMessage()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.jvnet.hk2.config 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);
}
use of org.jvnet.hk2.config in project Payara by payara.
the class CreateProtocolFilter 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);
final Class<?> filterClass = Thread.currentThread().getContextClassLoader().loadClass(classname);
if (!org.glassfish.grizzly.filterchain.Filter.class.isAssignableFrom(filterClass)) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_FAIL_NOTFILTER), name, classname));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
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();
for (ProtocolFilter filter : list) {
if (name.equals(filter.getName())) {
throw new TransactionFailure(String.format("A protocol filter named %s already exists.", name));
}
}
final ProtocolFilter filter = param.createChild(ProtocolFilter.class);
filter.setName(name);
filter.setClassname(classname);
list.add(filter);
return null;
}
}, chain);
} 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;
}
}
Aggregations