use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class WebContainerImpl method bind.
private void bind(Port port, WebListener webListener, String vsId) {
String protocol = Port.HTTP_PROTOCOL;
final int portNumber = port.getPortNumber();
final String defaultVS = vsId;
final WebListener listener = webListener;
if (webListener == null) {
listenerName = getListenerName();
webListener = new HttpListener();
webListener.setId(listenerName);
webListener.setPort(portNumber);
} else {
listenerName = webListener.getId();
protocol = webListener.getProtocol();
}
listeners.add(webListener);
if (protocol.equals(Port.HTTP_PROTOCOL)) {
securityEnabled = "false";
} else if (protocol.equals(Port.HTTPS_PROTOCOL)) {
securityEnabled = "true";
}
try {
ConfigSupport.apply(new SingleConfigCode<Protocols>() {
public Object run(Protocols param) throws TransactionFailure {
final Protocol protocol = param.createChild(Protocol.class);
protocol.setName(listenerName);
protocol.setSecurityEnabled(securityEnabled);
param.getProtocol().add(protocol);
final Http http = protocol.createChild(Http.class);
http.setDefaultVirtualServer(defaultVS);
http.setFileCache(http.createChild(FileCache.class));
protocol.setHttp(http);
return protocol;
}
}, networkConfig.getProtocols());
ConfigSupport.apply(new ConfigCode() {
public Object run(ConfigBeanProxy... params) throws TransactionFailure {
NetworkListeners nls = (NetworkListeners) params[0];
Transports transports = (Transports) params[1];
final NetworkListener listener = nls.createChild(NetworkListener.class);
listener.setName(listenerName);
listener.setPort(Integer.toString(portNumber));
listener.setProtocol(listenerName);
listener.setThreadPool("http-thread-pool");
if (listener.findThreadPool() == null) {
final ThreadPool pool = nls.createChild(ThreadPool.class);
pool.setName(listenerName);
listener.setThreadPool(listenerName);
}
listener.setTransport("tcp");
if (listener.findTransport() == null) {
final Transport transport = transports.createChild(Transport.class);
transport.setName(listenerName);
listener.setTransport(listenerName);
}
nls.getNetworkListener().add(listener);
return listener;
}
}, networkConfig.getNetworkListeners(), networkConfig.getTransports());
if (webListener.getProtocol().equals("https")) {
NetworkListener networkListener = networkConfig.getNetworkListener(listenerName);
Protocol httpProtocol = networkListener.findHttpProtocol();
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
public Object run(Protocol param) throws TransactionFailure {
Ssl newSsl = param.createChild(Ssl.class);
populateSslElement(newSsl, listener);
System.out.println("SSL " + newSsl.getKeyStore() + " " + newSsl.getKeyStorePassword() + " " + newSsl.getTrustStore() + " " + newSsl.getTrustStorePassword());
param.setSsl(newSsl);
return newSsl;
}
}, httpProtocol);
}
com.sun.enterprise.config.serverbeans.VirtualServer vs = httpService.getVirtualServerByName(config.getVirtualServerId());
ConfigSupport.apply(new SingleConfigCode<com.sun.enterprise.config.serverbeans.VirtualServer>() {
public Object run(com.sun.enterprise.config.serverbeans.VirtualServer avs) throws PropertyVetoException {
avs.addNetworkListener(listenerName);
return avs;
}
}, vs);
} catch (Exception e) {
if (listeners.contains(webListener)) {
listeners.remove(webListener);
}
e.printStackTrace();
}
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class ParentTest method parents.
@Test
public void parents() {
NetworkListeners service = getHabitat().getService(NetworkListeners.class);
assertNotNull(service);
NetworkListener listener = service.getNetworkListener().get(0);
assertNotNull(listener);
ConfigBeanProxy parent = service.getParent();
assertNotNull(parent);
NetworkListeners myService = listener.getParent(NetworkListeners.class);
assertNotNull(myService);
assertNotNull(myService.getNetworkListener().get(0).getName());
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class TargetBasedResolver method getTarget.
private <T extends ConfigBeanProxy> T getTarget(Class<? extends ConfigBeanProxy> targetType, Class<T> type) throws ClassNotFoundException {
// when using the target based parameter, we look first for a configuration of that name,
// then we look for a cluster of that name and finally we look for a subelement of the right type
final String name = getName();
ConfigBeanProxy config = habitat.getService(targetType, target);
if (config != null) {
try {
return type.cast(config);
} catch (ClassCastException e) {
// ok we need to do more work to find which object is really requested.
}
Dom parentDom = Dom.unwrap(config);
String elementName = GenericCrudCommand.elementName(parentDom.document, targetType, type);
if (elementName == null) {
return null;
}
ConfigModel.Property property = parentDom.model.getElement(elementName);
if (property.isCollection()) {
Collection<Dom> collection;
synchronized (parentDom) {
collection = parentDom.nodeElements(elementName);
}
if (collection == null) {
return null;
}
for (Dom child : collection) {
if (name.equals(child.attribute("ref"))) {
return type.cast(child.<ConfigBeanProxy>createProxy());
}
}
}
}
return null;
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class BasicModularityTest method serializeConfigBean.
@Test
public void serializeConfigBean() {
Config config = habitat.<Config>getService(Config.class, ServerEnvironmentImpl.DEFAULT_INSTANCE_NAME);
ConfigBeanProxy prox = (ConfigBeanProxy) config.getExtensionByType(ConfigExtensionZero.class);
String content = configModularityUtils.serializeConfigBean(prox);
assertEquals("Cannot serialize config beans properly", "<config-extension-zero dummy=\"dummy-value\"></config-extension-zero>", content);
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class DirectCreationTest method doTest.
public void doTest() throws TransactionFailure {
AdminService service = habitat.getService(AdminService.class);
ConfigBean serviceBean = (ConfigBean) ConfigBean.unwrap(service);
Class<?>[] subTypes = null;
try {
subTypes = ConfigSupport.getSubElementsTypes(serviceBean);
} catch (ClassNotFoundException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
throw new RuntimeException(e);
}
ConfigSupport support = getBaseServiceLocator().getService(ConfigSupport.class);
assertNotNull("ConfigSupport not found", support);
for (Class<?> subType : subTypes) {
// TODO: JL force compilation error to mark this probably edit point for grizzly config
if (subType.getName().endsWith("DasConfig")) {
Map<String, String> configChanges = new HashMap<String, String>();
configChanges.put("dynamic-reload-enabled", "true");
configChanges.put("autodeploy-dir", "funky-dir");
support.createAndSet(serviceBean, (Class<? extends ConfigBeanProxy>) subType, configChanges);
break;
}
}
support.createAndSet(serviceBean, DasConfig.class, (List) null);
List<AttributeChanges> profilerChanges = new ArrayList<AttributeChanges>();
String[] values = { "-Xmx512m", "-RFtrq", "-Xmw24" };
ConfigSupport.MultipleAttributeChanges multipleChanges = new ConfigSupport.MultipleAttributeChanges("jvm-options", values);
String[] values1 = { "profile" };
ConfigSupport.MultipleAttributeChanges multipleChanges1 = new ConfigSupport.MultipleAttributeChanges("name", values1);
profilerChanges.add(multipleChanges);
profilerChanges.add(multipleChanges1);
support.createAndSet((ConfigBean) ConfigBean.unwrap(habitat.<JavaConfig>getService(JavaConfig.class)), Profiler.class, profilerChanges);
}
Aggregations