use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class ConfigTest method testAddClassOfInjector.
/**
* Ensures that even the non-standard format of metadata from the hk2-config subsystem can
* be read from the service in addClasses. addClasses will now read both forms, if the
* documented form fails, it'll try the hk2-config form
*/
@Test
public void testAddClassOfInjector() {
ServiceLocator locator = ServiceLocatorFactory.getInstance().create(null);
List<ActiveDescriptor<?>> added = ServiceLocatorUtilities.addClasses(locator, EjbContainerAvailabilityInjector.class);
ActiveDescriptor<?> descriptor = added.get(0);
Assert.assertEquals("org.jvnet.hk2.config.test.EjbContainerAvailability", ServiceLocatorUtilities.getOneMetadataField(descriptor, "target"));
}
use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class AttributeMethodVisitor method visitAnnotation.
/**
* Visits an annotation of this method.
*
* @param desc the class descriptor of the annotation class.
* @param visible <tt>true</tt> if the annotation is visible at runtime.
*
* @return a visitor to visit the annotation values, or <tt>null</tt> if this visitor is not interested in visiting
* this annotation.
*/
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
duckTyped |= "Lorg/jvnet/hk2/config/DuckTyped;".equals(desc);
AnnotationVisitor visitor = null;
if ("Lorg/jvnet/hk2/config/Attribute;".equals(desc) || "Lorg/jvnet/hk2/config/Element;".equals(desc)) {
try {
final Class<?> configurable = Thread.currentThread().getContextClassLoader().loadClass(def.getDef());
final Attribute annotation = configurable.getMethod(name).getAnnotation(Attribute.class);
def.addAttribute(name, annotation);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
} else if ("Lorg/glassfish/api/admin/config/PropertiesDesc;".equals(desc)) {
try {
final Class<?> configurable = Thread.currentThread().getContextClassLoader().loadClass(def.getDef());
final PropertiesDesc annotation = configurable.getMethod(name).getAnnotation(PropertiesDesc.class);
final PropertyDesc[] propertyDescs = annotation.props();
for (PropertyDesc prop : propertyDescs) {
def.addProperty(prop);
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
return visitor;
}
use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class AbstractRestResourceProvider method getResourceConfig.
@Override
public ResourceConfig getResourceConfig(Set<Class<?>> classes, final ServerContext sc, final ServiceLocator habitat, final Set<? extends Binder> additionalBinders) throws EndpointRegistrationException {
final Reloader r = new Reloader();
ResourceConfig rc = new ResourceConfig(classes);
rc.property(ServerProperties.MEDIA_TYPE_MAPPINGS, getMimeMappings());
rc.register(CsrfProtectionFilter.class);
// TODO - JERSEY2
// RestConfig restConf = ResourceUtil.getRestConfig(habitat);
// if (restConf != null) {
// if (restConf.getLogOutput().equalsIgnoreCase("true")) { //enable output logging
// rc.getContainerResponseFilters().add(LoggingFilter.class);
// }
// if (restConf.getLogInput().equalsIgnoreCase("true")) { //enable input logging
// rc.getContainerRequestFilters().add(LoggingFilter.class);
// }
// if (restConf.getWadlGeneration().equalsIgnoreCase("false")) { //disable WADL
// rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
// }
// }
// else {
// rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
// }
//
rc.register(r);
rc.register(ReloadResource.class);
rc.register(new MultiPartFeature());
// rc.register(getJsonFeature());
rc.register(new AbstractBinder() {
@Override
protected void configure() {
AbstractActiveDescriptor<Reloader> descriptor = BuilderHelper.createConstantDescriptor(r);
descriptor.addContractType(Reloader.class);
bind(descriptor);
AbstractActiveDescriptor<ServerContext> scDescriptor = BuilderHelper.createConstantDescriptor(sc);
scDescriptor.addContractType(ServerContext.class);
bind(scDescriptor);
LocatorBridge locatorBridge = new LocatorBridge(habitat);
AbstractActiveDescriptor<LocatorBridge> hDescriptor = BuilderHelper.createConstantDescriptor(locatorBridge);
bind(hDescriptor);
RestSessionManager rsm = habitat.getService(RestSessionManager.class);
AbstractActiveDescriptor<RestSessionManager> rmDescriptor = BuilderHelper.createConstantDescriptor(rsm);
bind(rmDescriptor);
}
});
for (Binder b : additionalBinders) {
rc.register(b);
}
rc.property(MessageProperties.LEGACY_WORKERS_ORDERING, true);
return rc;
}
Aggregations