use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class ListHttpListeners 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();
List<NetworkListener> list = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
int size = 0;
for (NetworkListener networkListener : list) {
size = Math.max(size, networkListener.getName().length());
}
final String format = "%-" + (size + 2) + "s %-6s";
if (verbose) {
report.getTopMessagePart().addChild().setMessage(String.format(format, "NAME", "PORT"));
}
for (NetworkListener listener : list) {
if (listener.findHttpProtocol().getHttp() != null) {
report.getTopMessagePart().addChild().setMessage(String.format(format, listener.getName(), verbose ? listener.getPort() : ""));
}
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class CreateHttpListener method verifyUniquePort.
private boolean verifyUniquePort(ActionReport report, NetworkConfig networkConfig) {
// check port uniqueness, only for same address
for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
if (listener.getPort().trim().equals(listenerPort) && listener.getAddress().trim().equals(listenerAddress)) {
String def = "Port is already taken by another listener, choose another port.";
String msg = MessageFormat.format(rb.getString(LogFacade.PORT_IN_USE), listenerPort, listenerAddress);
report.setMessage(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return false;
}
}
return true;
}
use of org.glassfish.grizzly.config.dom.NetworkListener 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.NetworkListener 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.NetworkListener in project Payara by payara.
the class ORBConnectorStartup method initializeLazyListener.
/**
* Start Grizzly based ORB lazy listener, which is going to initialize
* ORB container on first request.
*/
private void initializeLazyListener() {
final IiopService iiopService = config.getExtensionByType(IiopService.class);
if (iiopService != null) {
List<IiopListener> iiopListenerList = iiopService.getIiopListener();
for (IiopListener oneListener : iiopListenerList) {
if (Boolean.valueOf(oneListener.getEnabled()) && Boolean.valueOf(oneListener.getLazyInit())) {
NetworkListener dummy = new DummyNetworkListener();
dummy.setPort(oneListener.getPort());
dummy.setAddress(oneListener.getAddress());
dummy.setProtocol("light-weight-listener");
dummy.setTransport("tcp");
dummy.setName("iiop-service");
grizzlyService.createNetworkProxy(dummy);
}
}
}
}
Aggregations