use of org.glassfish.grizzly.config.dom.NetworkConfig 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);
}
use of org.glassfish.grizzly.config.dom.NetworkConfig in project Payara by payara.
the class WebSslConfigHandler method delete.
@Override
public void delete(DeleteSsl command, ActionReport report) {
NetworkConfig netConfig = command.config.getNetworkConfig();
NetworkListener networkListener = netConfig.getNetworkListener(command.listenerId);
if (networkListener == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_SSL_HTTP_LISTENER_NOT_FOUND), command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Protocol protocol = networkListener.findHttpProtocol();
if (protocol.getSsl() == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_SSL_ELEMENT_DOES_NOT_EXIST), command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
public Object run(Protocol param) {
param.setSsl(null);
return null;
}
}, networkListener.findHttpProtocol());
} catch (TransactionFailure e) {
command.reportError(report, e);
}
}
use of org.glassfish.grizzly.config.dom.NetworkConfig in project Payara by payara.
the class WebSslConfigHandler method create.
@Override
public void create(final CreateSsl command, ActionReport report) {
NetworkConfig netConfig = command.config.getNetworkConfig();
// ensure we have the specified listener
NetworkListener listener = netConfig.getNetworkListener(command.listenerId);
Protocol httpProtocol;
try {
if (listener == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_SSL_HTTP_NOT_FOUND), command.listenerId));
httpProtocol = command.findOrCreateProtocol(command.listenerId);
} else {
httpProtocol = listener.findHttpProtocol();
Ssl ssl = httpProtocol.getSsl();
if (ssl != null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_SSL_HTTP_ALREADY_EXISTS), command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
public Object run(Protocol param) throws TransactionFailure {
Ssl newSsl = param.createChild(Ssl.class);
command.populateSslElement(newSsl);
param.setSsl(newSsl);
return newSsl;
}
}, httpProtocol);
} catch (TransactionFailure e) {
command.reportError(report, e);
}
command.reportSuccess(report);
}
use of org.glassfish.grizzly.config.dom.NetworkConfig in project Payara by payara.
the class EmbeddedTest method setup.
@BeforeClass
public static void setup() {
Server.Builder builder = new Server.Builder("build");
server = builder.build();
NetworkConfig nc = server.getHabitat().getService(NetworkConfig.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
List<NetworkListener> listeners = nc.getNetworkListeners().getNetworkListener();
System.out.println("Network listener size before creation " + listeners.size());
for (NetworkListener nl : listeners) {
System.out.println("Network listener " + nl.getPort());
}
try {
http = server.createPort(8080);
ContainerBuilder b = server.createConfig(ContainerBuilder.Type.web);
server.addContainer(b);
EmbeddedWebContainer embedded = (EmbeddedWebContainer) b.create(server);
embedded.bind(http, "http");
} catch (IOException e) {
throw new RuntimeException(e);
}
listeners = nc.getNetworkListeners().getNetworkListener();
System.out.println("Network listener size after creation " + listeners.size());
Assert.assertTrue(listeners.size() == 1);
for (NetworkListener nl : listeners) {
System.out.println("Network listener " + nl.getPort());
}
Collection<NetworkListener> cnl = server.getHabitat().getAllServices(NetworkListener.class);
System.out.println("Network listener size after creation " + cnl.size());
for (NetworkListener nl : cnl) {
System.out.println("Network listener " + nl.getPort());
}
server.addContainer(ContainerBuilder.Type.all);
}
use of org.glassfish.grizzly.config.dom.NetworkConfig in project Payara by payara.
the class GrizzlyConfigSchemaMigrator method postConstruct.
public void postConstruct() {
for (Config config : configs.getConfig()) {
currentConfig = config;
try {
final NetworkConfig networkConfig = currentConfig.getNetworkConfig();
if (networkConfig == null) {
createFromScratch();
}
normalizeThreadPools();
if (currentConfig.getHttpService() != null) {
promoteHttpServiceProperties(currentConfig.getHttpService());
promoteVirtualServerProperties(currentConfig.getHttpService());
} else {
// this only happens during some unit tests
logger.log(Level.WARNING, ConfigApiLoggerInfo.nullHttpService, new String[] { currentConfig.getName() });
}
promoteSystemProperties();
addAsadminProtocol(currentConfig.getNetworkConfig());
} catch (TransactionFailure tf) {
logger.log(Level.SEVERE, ConfigApiLoggerInfo.failUpgradeDomain, tf);
throw new RuntimeException(tf);
}
}
}
Aggregations