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());
}
}
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());
}
}
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;
}
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();
}
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();
}
Aggregations