Search in sources :

Example 21 with Context

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;
    }
}
Also used : ActionReport(org.glassfish.api.ActionReport) Filter(org.glassfish.hk2.api.Filter) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) TargetType(org.glassfish.config.support.TargetType) ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) Descriptor(org.glassfish.hk2.api.Descriptor) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

Example 22 with Context

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);
        }
    }
}
Also used : GenericsContext(ru.vyarus.java.generics.resolver.context.GenericsContext) Type(java.lang.reflect.Type) GuiceComponentFactory(ru.vyarus.dropwizard.guice.module.jersey.support.GuiceComponentFactory) ParameterizedTypeImpl(org.glassfish.hk2.utilities.reflection.ParameterizedTypeImpl)

Example 23 with Context

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);
    }
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 24 with Context

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();
}
Also used : ParsingContext(org.glassfish.hk2.classmodel.reflect.ParsingContext) IOException(java.io.IOException) Parser(org.glassfish.hk2.classmodel.reflect.Parser)

Example 25 with Context

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>");
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ServletContext(javax.servlet.ServletContext) PrintWriter(java.io.PrintWriter)

Aggregations

ActionReport (org.glassfish.api.ActionReport)12 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)12 IOException (java.io.IOException)11 Properties (java.util.Properties)8 ArrayList (java.util.ArrayList)7 MultiException (org.glassfish.hk2.api.MultiException)7 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)7 Config (com.sun.enterprise.config.serverbeans.Config)6 PropertyVetoException (java.beans.PropertyVetoException)6 VersioningSyntaxException (org.glassfish.deployment.versioning.VersioningSyntaxException)6 Types (org.glassfish.hk2.classmodel.reflect.Types)6 RetryableException (org.jvnet.hk2.config.RetryableException)6 Logger (java.util.logging.Logger)5 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)5 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)4 ServletContext (javax.servlet.ServletContext)4 TargetType (org.glassfish.config.support.TargetType)4 Notifier (fish.payara.nucleus.notification.configuration.Notifier)3 NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)3 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)3