Search in sources :

Example 41 with Type

use of org.glassfish.hk2.classmodel.reflect.Type in project Payara by payara.

the class InplantedTest method Test.

@Test
public void Test() {
    ServiceLocator habitat = server.getHabitat();
    System.out.println("Process type is " + habitat.<ProcessEnvironment>getService(ProcessEnvironment.class).getProcessType());
    for (Sniffer s : habitat.<Sniffer>getAllServices(Sniffer.class)) {
        System.out.println("Got sniffer " + s.getModuleType());
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Sniffer(org.glassfish.api.container.Sniffer) Test(org.junit.Test)

Example 42 with Type

use of org.glassfish.hk2.classmodel.reflect.Type in project Payara by payara.

the class MultipleSPETest method test.

@Test
public void test() throws Exception {
    // 1. Bootstrap GlassFish DAS in embedded mode.
    GlassFishProperties glassFishProperties = new GlassFishProperties();
    glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
    glassFishProperties.setConfigFileReadOnly(false);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
    PrintStream sysout = System.out;
    glassfish.start();
    System.setOut(sysout);
    // 2. Deploy the PaaS-bookstore application. Deployment should fail
    File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to get the
    "/target/basic-spe-test.war");
    // archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    try {
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNull(appName);
    } catch (Exception e) {
        System.out.println("$$$$$$$$$$$$$$$$Exception$$$$$$");
    } finally {
        // 3. Register one of the plugins as the default S.P.E
        ServiceLocator habitat = Globals.getDefaultHabitat();
        org.glassfish.api.admin.CommandRunner commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
        ActionReport report = habitat.getService(ActionReport.class);
        org.glassfish.api.admin.CommandRunner.CommandInvocation invocation = commandRunner.getCommandInvocation("register-service-provisioning-engine", report);
        ParameterMap parameterMap = new ParameterMap();
        parameterMap.add("type", "Database");
        parameterMap.add("defaultservice", "true");
        parameterMap.add("DEFAULT", "org.glassfish.paas.mydbplugin.MyDBPlugin");
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        System.out.println("Registered a default SPE :" + !report.hasFailures());
        // 4. Deploy the application. Deployment should succeed.
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        // 5. Access the app to make sure PaaS-basic-shared-service-test app is correctly
        // provisioned.
        String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
        String instanceIP = getLBIPAddress(glassfish);
        get("http://" + instanceIP + ":" + HTTP_PORT + "/basic-spe-test/list", "Here is a list of animals in the zoo.");
        // Retrieve the  port number used by the connection pool
        invocation = commandRunner.getCommandInvocation("get", report);
        parameterMap = new ParameterMap();
        parameterMap.add("DEFAULT", "server.resources.jdbc-connection-pool.jdbc/__multiple_spe_paas_sample.property.PortNumber");
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            try {
                boolean undeployClean = false;
                CommandResult commandResult = glassfish.getCommandRunner().run("list-services");
                if (commandResult.getOutput().contains("Nothing to list.")) {
                    undeployClean = true;
                }
                Assert.assertTrue(undeployClean);
            } catch (Exception e) {
                System.err.println("Couldn't varify whether undeploy succeeded");
            }
        }
        commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
        invocation = commandRunner.getCommandInvocation("unregister-service-provisioning-engine", report);
        parameterMap = new ParameterMap();
        parameterMap.add("DEFAULT", "org.glassfish.paas.mydbplugin.MyDBPlugin");
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        System.out.println("Unregistered the default SPE :" + !report.hasFailures());
    }
}
Also used : PrintStream(java.io.PrintStream) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) PaaSDeploymentException(org.glassfish.paas.orchestrator.PaaSDeploymentException) IOException(java.io.IOException) Exception(java.lang.Exception) CommandResult(org.glassfish.embeddable.CommandResult) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) GlassFish(org.glassfish.embeddable.GlassFish) JarFile(java.util.jar.JarFile) File(java.io.File) CommandRunner(org.glassfish.embeddable.CommandRunner) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) Test(org.junit.Test)

Example 43 with Type

use of org.glassfish.hk2.classmodel.reflect.Type in project Payara by payara.

the class CDISecondChanceResolver method justInTimeResolution.

/* (non-Javadoc)
     * @see org.glassfish.hk2.api.JustInTimeInjectionResolver#justInTimeResolution(org.glassfish.hk2.api.Injectee)
     */
@SuppressWarnings({ "unchecked" })
@Override
public boolean justInTimeResolution(Injectee failedInjectionPoint) {
    Type requiredType = failedInjectionPoint.getRequiredType();
    Set<Annotation> setQualifiers = failedInjectionPoint.getRequiredQualifiers();
    Annotation[] qualifiers = setQualifiers.toArray(new Annotation[setQualifiers.size()]);
    BeanManager manager = getCurrentBeanManager();
    if (manager == null)
        return false;
    Set<Bean<?>> beans = manager.getBeans(requiredType, qualifiers);
    if (beans == null || beans.isEmpty()) {
        return false;
    }
    DynamicConfiguration config = ServiceLocatorUtilities.createDynamicConfiguration(locator);
    for (Bean<?> bean : beans) {
        // Add a bean to the service locator
        CDIHK2Descriptor<Object> descriptor = new CDIHK2Descriptor<Object>(manager, (Bean<Object>) bean, requiredType);
        config.addActiveDescriptor(descriptor);
    }
    config.commit();
    return true;
}
Also used : Type(java.lang.reflect.Type) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) BeanManager(javax.enterprise.inject.spi.BeanManager) Annotation(java.lang.annotation.Annotation) Bean(javax.enterprise.inject.spi.Bean)

Example 44 with Type

use of org.glassfish.hk2.classmodel.reflect.Type in project Payara by payara.

the class EjbOptionalIntfGenerator method generateInterfaceMethod.

private static void generateInterfaceMethod(ClassVisitor cv, java.lang.reflect.Method m) throws Exception {
    String methodName = m.getName();
    Type returnType = Type.getReturnType(m);
    Type[] argTypes = Type.getArgumentTypes(m);
    Method asmMethod = new Method(methodName, returnType, argTypes);
    GeneratorAdapter cg = new GeneratorAdapter(ACC_PUBLIC + ACC_ABSTRACT, asmMethod, null, getExceptionTypes(m), cv);
    cg.endMethod();
}
Also used : GeneratorAdapter(org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter) Method(org.glassfish.hk2.external.org.objectweb.asm.commons.Method)

Example 45 with Type

use of org.glassfish.hk2.classmodel.reflect.Type in project Payara by payara.

the class EjbOptionalIntfGenerator method generateSetDelegateMethod.

private static void generateSetDelegateMethod(ClassVisitor cv, Class delegateClass, String subClassName) throws Exception {
    Class optProxyClass = OptionalLocalInterfaceProvider.class;
    java.lang.reflect.Method proxyMethod = optProxyClass.getMethod("setOptionalLocalIntfProxy", java.lang.reflect.Proxy.class);
    String methodName = proxyMethod.getName();
    Type returnType = Type.getReturnType(proxyMethod);
    Type[] argTypes = Type.getArgumentTypes(proxyMethod);
    Type[] eTypes = getExceptionTypes(proxyMethod);
    Method asmMethod = new Method(methodName, returnType, argTypes);
    GeneratorAdapter mg2 = new GeneratorAdapter(ACC_PUBLIC, asmMethod, null, eTypes, cv);
    mg2.visitVarInsn(ALOAD, 0);
    mg2.visitVarInsn(ALOAD, 1);
    mg2.visitTypeInsn(CHECKCAST, delegateClass.getName().replace('.', '/'));
    String delIntClassDesc = Type.getType(delegateClass).getDescriptor();
    mg2.visitFieldInsn(PUTFIELD, subClassName.replace('.', '/'), DELEGATE_FIELD_NAME, delIntClassDesc);
    mg2.returnValue();
    mg2.endMethod();
}
Also used : GeneratorAdapter(org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter) Method(org.glassfish.hk2.external.org.objectweb.asm.commons.Method) OptionalLocalInterfaceProvider(com.sun.ejb.spi.container.OptionalLocalInterfaceProvider)

Aggregations

ServiceLocator (org.glassfish.hk2.api.ServiceLocator)18 ActionReport (org.glassfish.api.ActionReport)13 MultiException (org.glassfish.hk2.api.MultiException)13 ParameterMap (org.glassfish.api.admin.ParameterMap)12 List (java.util.List)10 Map (java.util.Map)10 GeneratorAdapter (org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter)7 Method (org.glassfish.hk2.external.org.objectweb.asm.commons.Method)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Sniffer (org.glassfish.api.container.Sniffer)6 CommandRunner (org.glassfish.embeddable.CommandRunner)6 File (java.io.File)5 Types (org.glassfish.hk2.classmodel.reflect.Types)5 PropertyVetoException (java.beans.PropertyVetoException)4 Method (java.lang.reflect.Method)4 Type (java.lang.reflect.Type)4 JsonString (javax.json.JsonString)4 PrivilegedActionException (java.security.PrivilegedActionException)3