use of org.glassfish.hk2.api.Context in project Payara by payara.
the class CreateResourceRef method chooseRefContainer.
private RefContainer chooseRefContainer(final AdminCommandContext context) {
final ActionReport report = context.getActionReport();
Class<?>[] allInterfaces = resourceOfInterest.getClass().getInterfaces();
for (Class<?> resourceInterface : allInterfaces) {
ResourceConfigCreator resourceConfigCreator = (ResourceConfigCreator) resourceInterface.getAnnotation(ResourceConfigCreator.class);
if (resourceConfigCreator != null) {
commandName = resourceConfigCreator.commandName();
}
}
if (commandName != null) {
List<ServiceHandle<?>> serviceHandles = locator.getAllServiceHandles(new Filter() {
@Override
public boolean matches(Descriptor arg0) {
String name = arg0.getName();
if (name != null && name.equals(commandName)) {
return true;
}
return false;
}
});
for (ServiceHandle<?> handle : serviceHandles) {
ActiveDescriptor<?> descriptor = handle.getActiveDescriptor();
if (descriptor.getName().equals(commandName)) {
if (!descriptor.isReified()) {
locator.reifyDescriptor(descriptor);
}
AdminCommand service = locator.<AdminCommand>getService(descriptor.getImplementationClass());
if (service != null) {
TargetType targetType = descriptor.getImplementationClass().getAnnotation(TargetType.class);
targets = targetType.value();
break;
}
}
}
if (!(isTargetValid = validateTarget(target, targets))) {
return null;
}
Config config = domain.getConfigs().getConfigByName(target);
if (config != null) {
return config;
}
Server server = configBeansUtilities.getServerNamed(target);
if (server != null) {
return server;
}
DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
if (dg != null) {
return dg;
}
Cluster cluster = domain.getClusterNamed(target);
return cluster;
} else {
report.setMessage(localStrings.getLocalString("create.resource.ref.failed", "Resource ref {0} creation failed", refName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return null;
}
}
use of org.glassfish.hk2.api.Context in project dropwizard-guicey by xvik.
the class JerseyBinding method bindSpecificComponent.
/**
* Binds jersey specific component (component implements jersey interface or extends class).
* Specific binding is required for types directly supported by jersey (e.g. ExceptionMapper).
* Such types must be bound to target interface directly, otherwise jersey would not be able to resolve them.
* <p> If type is {@link HK2Managed}, binds directly.
* Otherwise, use guice "bridge" factory to lazily bind type.</p>
*
* @param binder hk binder
* @param injector guice injector
* @param type type which implements specific jersey interface or extends class
* @param specificType specific jersey type (interface or abstract class)
*/
public static void bindSpecificComponent(final AbstractBinder binder, final Injector injector, final Class<?> type, final Class<?> specificType) {
// resolve generics of specific type
final GenericsContext context = GenericsResolver.resolve(type).type(specificType);
final List<Type> genericTypes = context.genericTypes();
final Type[] generics = genericTypes.toArray(new Type[0]);
final Type binding = generics.length > 0 ? new ParameterizedTypeImpl(specificType, generics) : specificType;
if (isHK2Managed(type)) {
binder.bind(type).to(binding).in(Singleton.class);
} else {
// hk cant find different things in different situations, so uniform registration is impossible
if (InjectionResolver.class.equals(specificType)) {
binder.bindFactory(new GuiceComponentFactory<>(injector, type)).to(type).in(Singleton.class);
binder.bind(type).to(binding).in(Singleton.class);
} else {
binder.bindFactory(new GuiceComponentFactory<>(injector, type)).to(type).to(binding).in(Singleton.class);
}
}
}
use of org.glassfish.hk2.api.Context in project athenz by yahoo.
the class InstanceProviderContainer method run.
public void run() {
try {
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(16);
Server server = new Server(threadPool);
ServletContextHandler handler = new ServletContextHandler();
handler.setContextPath("");
ResourceConfig config = new ResourceConfig(InstanceProviderResources.class).register(new Binder());
handler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
server.setHandler(handler);
// SSL Context Factory
SslContextFactory sslContextFactory = createSSLContextObject();
// SSL HTTP Configuration
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecureScheme("https");
httpConfig.setSecurePort(10043);
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
// SSL Connector
ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
sslConnector.setPort(10043);
server.addConnector(sslConnector);
server.start();
server.join();
} catch (Exception e) {
System.err.println("*** " + e);
}
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class JavaEEScanner method initTypes.
protected void initTypes(File file) throws IOException {
ParsingContext context = new ParsingContext.Builder().build();
Parser cp = new Parser(context);
cp.parse(file, null);
try {
cp.awaitTermination();
} catch (InterruptedException e) {
throw new IOException(e);
}
types = cp.getContext().getTypes();
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class Iso1Servlet method doGet.
/**
* Just prints out the value of the ServiceLocator getName
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
ServletContext context = getServletContext();
ServiceLocator locator = (ServiceLocator) context.getAttribute(HABITAT_ATTRIBUTE);
String reply1 = SERVLET_CONTEXT_LOCATOR + ((locator == null) ? "null" : locator.getName());
String jndiAppLocatorName = getJndiAppLocatorName();
String reply2 = JNDI_APP_LOCATOR + ((jndiAppLocatorName == null) ? "null" : jndiAppLocatorName);
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer.println("<html>");
writer.println("<head>");
writer.println("<title>Iso1 WebApp</title>");
writer.println("</head>");
writer.println("<body>");
writer.println(reply1);
writer.println(reply2);
writer.println("</body>");
writer.println("</html>");
}
Aggregations