use of org.glassfish.grizzly.config.dom.Protocols 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.Protocols in project Payara by payara.
the class DeleteProtocolFinder 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);
PortUnification pu = getPortUnification(protocol);
ConfigSupport.apply(new ConfigCode() {
@Override
public Object run(ConfigBeanProxy... params) {
final Protocol prot = (Protocol) params[0];
final PortUnification portUnification = (PortUnification) params[1];
final List<ProtocolFinder> oldList = portUnification.getProtocolFinder();
List<ProtocolFinder> newList = new ArrayList<ProtocolFinder>();
for (final ProtocolFinder finder : oldList) {
if (!name.equals(finder.getName())) {
newList.add(finder);
}
}
if (oldList.size() == newList.size()) {
throw new RuntimeException(String.format("No finder named %s found for protocol %s", name, protocolName));
}
if (newList.isEmpty()) {
prot.setPortUnification(null);
} else {
portUnification.setProtocolFinder(newList);
}
return null;
}
}, protocol, pu);
cleanPortUnification(pu);
} 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.Protocols in project Payara by payara.
the class InstanceReaderImpl method getListeners.
/**
* Enlists both http and https listeners of this server instance
* It will be form "http:<hostname>:<port> https:<hostname>:<port>"
*
* @return String Listener(s) info.
*/
@Override
public String getListeners() throws LbReaderException {
StringBuffer listenerStr = new StringBuffer();
Config config = _domain.getConfigNamed(_server.getConfigRef());
NetworkConfig networkConfig = config.getNetworkConfig();
Protocols protocols = networkConfig.getProtocols();
NetworkListeners nls = networkConfig.getNetworkListeners();
Iterator<NetworkListener> listenerIter = nls.getNetworkListener().iterator();
int i = 0;
PropertyResolver resolver = new PropertyResolver(_domain, _server.getName());
while (listenerIter.hasNext()) {
NetworkListener listener = listenerIter.next();
NetworkListener rawListener = GlassFishConfigBean.getRawView(listener);
if (rawListener.getName().equals(ADMIN_LISTENER)) {
continue;
}
String prot = rawListener.getProtocol();
Protocol protocol = protocols.findProtocol(prot);
if (i > 0) {
// space between listener names
listenerStr.append(' ');
}
i++;
if (Boolean.valueOf(protocol.getHttp().getJkEnabled())) {
listenerStr.append(AJP_PROTO);
} else {
if (Boolean.valueOf(protocol.getSecurityEnabled()).booleanValue()) {
listenerStr.append(HTTPS_PROTO);
} else {
listenerStr.append(HTTP_PROTO);
}
}
String hostName = getResolvedHostName(rawListener.getAddress());
listenerStr.append(hostName);
listenerStr.append(':');
// resolve the port name
String port = rawListener.getPort();
// If it is system variable, resolve it
if ((port != null) && (port.length() > 1) && (port.charAt(0) == '$') && (port.charAt(1) == '{') && (port.charAt(port.length() - 1) == '}')) {
String portVar = port.substring(2, port.length() - 1);
port = resolver.getPropertyValue(portVar);
if (port == null) {
throw new LbReaderException(LbLogUtil.getStringManager().getString("UnableToResolveSystemProperty", portVar, _server.getName()));
}
}
listenerStr.append(port);
}
return listenerStr.toString();
}
use of org.glassfish.grizzly.config.dom.Protocols in project Payara by payara.
the class CreateSsl method findOrCreateProtocol.
public Protocol findOrCreateProtocol(final String name, final boolean create) throws TransactionFailure {
NetworkConfig networkConfig = config.getNetworkConfig();
Protocol protocol = networkConfig.findProtocol(name);
if (protocol == null && create) {
protocol = (Protocol) ConfigSupport.apply(new SingleConfigCode<Protocols>() {
@Override
public Object run(Protocols param) throws TransactionFailure {
Protocol newProtocol = param.createChild(Protocol.class);
newProtocol.setName(name);
newProtocol.setSecurityEnabled("true");
param.getProtocol().add(newProtocol);
return newProtocol;
}
}, habitat.<Protocols>getService(Protocols.class));
}
return protocol;
}
use of org.glassfish.grizzly.config.dom.Protocols in project Payara by payara.
the class AdminRESTConfigUpgrade method postConstruct.
@Override
public void postConstruct() {
for (Config config : configs.getConfig()) {
// we only want to handle configs that have an admin listener
try {
if (config.getAdminListener() == null) {
LogRecord lr = new LogRecord(Level.FINE, String.format("Skipping config %s. No admin listener.", config.getName()));
lr.setLoggerName(getClass().getName());
EarlyLogHandler.earlyMessages.add(lr);
continue;
}
} catch (IllegalStateException ise) {
/*
* I've only seen the exception rather than
* getAdminListener returning null. This should
* typically happen for any config besides
* <server-config>, but we'll proceed if any
* config has an admin listener.
*/
LogRecord lr = new LogRecord(Level.FINE, String.format("Skipping config %s. getAdminListener threw: %s", config.getName(), ise.getLocalizedMessage()));
lr.setLoggerName(getClass().getName());
EarlyLogHandler.earlyMessages.add(lr);
continue;
}
Protocols ps = config.getNetworkConfig().getProtocols();
if (ps != null) {
for (Protocol p : ps.getProtocol()) {
Http h = p.getHttp();
if (h != null && "__asadmin".equals(h.getDefaultVirtualServer())) {
try {
ConfigSupport.apply(new HttpConfigCode(), h);
} catch (TransactionFailure tf) {
LogRecord lr = new LogRecord(Level.SEVERE, "Could not upgrade http element for admin console: " + tf);
lr.setLoggerName(getClass().getName());
EarlyLogHandler.earlyMessages.add(lr);
}
}
}
}
}
}
Aggregations