use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class AdminConsoleAdapter method initRest.
void initRest() {
InputStream is = null;
try {
NetworkListener nl = domain.getServerNamed("server").getConfig().getNetworkConfig().getNetworkListener("admin-listener");
SecureAdmin secureAdmin = habitat.getService(SecureAdmin.class);
URL url = new URL((SecureAdmin.Util.isEnabled(secureAdmin) ? "https" : "http"), nl.getAddress(), Integer.parseInt(nl.getPort()), "/management/domain");
URLConnection conn = url.openConnection();
is = conn.getInputStream();
isRestStarted = true;
} catch (Exception ex) {
logger.log(Level.FINE, null, ex);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ex1) {
logger.log(Level.FINE, null, ex1);
}
}
}
}
use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class AdminEndpointDecider method setValues.
private void setValues() {
// can't change
asadminContextRoot = AdminAdapter.PREFIX_URI;
// asadminHosts = Collections.emptyList(); //asadmin is handled completely by the adapter, no VS needed
NetworkListener nl = cfg.getAdminListener();
ThreadPool tp = nl.findThreadPool();
if (tp != null) {
try {
maxThreadPoolSize = Integer.parseInt(tp.getMaxThreadPoolSize());
} catch (NumberFormatException ne) {
}
}
String dvs = nl.findHttpProtocol().getHttp().getDefaultVirtualServer();
guiHosts = Collections.unmodifiableList(Arrays.asList(dvs));
// same for now
asadminHosts = guiHosts;
try {
address = InetAddress.getByName(nl.getAddress());
} catch (UnknownHostException e) {
throw new IllegalStateException(e);
}
if (ServerTags.ADMIN_LISTENER_ID.equals(nl.getName())) {
// at the root context for separate admin-listener
guiContextRoot = "";
try {
port = Integer.parseInt(nl.getPort());
} catch (NumberFormatException ne) {
port = ADMIN_PORT;
}
} else {
try {
port = Integer.parseInt(nl.getPort());
} catch (NumberFormatException ne) {
// this is the last resort
port = 8080;
}
// get the context root from admin-service
AdminService as = cfg.getAdminService();
if (as == null)
guiContextRoot = ServerEnvironmentImpl.DEFAULT_ADMIN_CONSOLE_CONTEXT_ROOT;
else
setGuiContextRootFromAdminService(as);
}
}
use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class ServerHelper method getAdminListener.
public static NetworkListener getAdminListener(Config config) {
NetworkConfig nwc = config.getNetworkConfig();
if (nwc == null)
throw new IllegalStateException("Can't operate without <http-service>");
List<NetworkListener> lss = nwc.getNetworkListeners().getNetworkListener();
if (lss == null || lss.isEmpty())
throw new IllegalStateException("Can't operate without at least one <network-listener>");
for (NetworkListener ls : lss) {
if (ServerTags.ADMIN_LISTENER_ID.equals(ls.getName())) {
return ls;
}
}
// if we can't find the admin-listener, then use the first one
return lss.get(0);
}
use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class ServerHelper method translateAddressAndPort.
/**
* @param adminListener
* @param server
* @param config
* @return ret[0] == address, ret[1] == port
*/
private static String[] translateAddressAndPort(NetworkListener adminListener, Server server, Config config) {
NetworkListener adminListenerRaw = null;
String[] ret = new String[2];
String portString = null;
String addressString = null;
try {
Dom serverDom = Dom.unwrap(server);
Domain domain = serverDom.getHabitat().getService(Domain.class);
adminListenerRaw = GlassFishConfigBean.getRawView(adminListener);
portString = adminListenerRaw.getPort();
addressString = adminListenerRaw.getAddress();
PropertyResolver resolver = new PropertyResolver(domain, server.getName());
if (isToken(portString))
ret[1] = resolver.getPropertyValue(portString);
else
ret[1] = portString;
if (isToken(addressString))
ret[0] = resolver.getPropertyValue(addressString);
else
ret[0] = addressString;
} catch (ClassCastException e) {
// jc: workaround for issue 12354
// TODO severe error
ret[0] = translatePortOld(addressString, server, config);
ret[1] = translatePortOld(portString, server, config);
}
return ret;
}
use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class TransactionListenerTest method transactionEvents.
@Test
public void transactionEvents() throws Exception, TransactionFailure {
httpService = getHabitat().getService(HttpService.class);
NetworkConfig networkConfig = getHabitat().getService(NetworkConfig.class);
final NetworkListener netListener = networkConfig.getNetworkListeners().getNetworkListener().get(0);
final Http http = netListener.findHttpProtocol().getHttp();
final TransactionListener listener = new TransactionListener() {
public void transactionCommited(List<PropertyChangeEvent> changes) {
events = changes;
}
public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
}
};
Transactions transactions = getHabitat().getService(Transactions.class);
try {
transactions.addTransactionsListener(listener);
assertTrue(httpService != null);
logger.fine("Max connections = " + http.getMaxConnections());
ConfigSupport.apply(new SingleConfigCode<Http>() {
public Object run(Http param) {
param.setMaxConnections("500");
return null;
}
}, http);
assertTrue("500".equals(http.getMaxConnections()));
transactions.waitForDrain();
assertTrue(events != null);
logger.fine("Number of events " + events.size());
assertTrue(events.size() == 1);
PropertyChangeEvent event = events.iterator().next();
assertTrue("max-connections".equals(event.getPropertyName()));
assertTrue("500".equals(event.getNewValue().toString()));
assertTrue("250".equals(event.getOldValue().toString()));
} catch (Exception t) {
t.printStackTrace();
throw t;
} finally {
transactions.removeTransactionsListener(listener);
}
// put back the right values in the domain to avoid test collisions
ConfigSupport.apply(new SingleConfigCode<Http>() {
public Object run(Http param) {
param.setMaxConnections("250");
return null;
}
}, http);
}
Aggregations