use of javax.ws.rs.core.Application in project wildfly by wildfly.
the class JaxrsScanningProcessor method scan.
protected void scan(final DeploymentUnit du, final ClassLoader classLoader, final ResteasyDeploymentData resteasyDeploymentData) throws DeploymentUnitProcessingException, ModuleLoadException {
final CompositeIndex index = du.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
if (!resteasyDeploymentData.shouldScan()) {
return;
}
if (!resteasyDeploymentData.isDispatcherCreated()) {
final Set<ClassInfo> applicationClasses = index.getAllKnownSubclasses(APPLICATION);
try {
for (ClassInfo c : applicationClasses) {
if (Modifier.isAbstract(c.flags()))
continue;
@SuppressWarnings("unchecked") Class<? extends Application> scanned = (Class<? extends Application>) classLoader.loadClass(c.name().toString());
resteasyDeploymentData.getScannedApplicationClasses().add(scanned);
}
} catch (ClassNotFoundException e) {
throw JaxrsLogger.JAXRS_LOGGER.cannotLoadApplicationClass(e);
}
}
List<AnnotationInstance> resources = null;
List<AnnotationInstance> providers = null;
if (resteasyDeploymentData.isScanResources()) {
resources = index.getAnnotations(JaxrsAnnotations.PATH.getDotName());
}
if (resteasyDeploymentData.isScanProviders()) {
providers = index.getAnnotations(JaxrsAnnotations.PROVIDER.getDotName());
}
if ((resources == null || resources.isEmpty()) && (providers == null || providers.isEmpty()))
return;
final Set<ClassInfo> pathInterfaces = new HashSet<ClassInfo>();
if (resources != null) {
for (AnnotationInstance e : resources) {
final ClassInfo info;
if (e.target() instanceof ClassInfo) {
info = (ClassInfo) e.target();
} else if (e.target() instanceof MethodInfo) {
// ignore
continue;
} else {
JAXRS_LOGGER.classOrMethodAnnotationNotFound("@Path", e.target());
continue;
}
if (info.name().toString().startsWith(ORG_APACHE_CXF)) {
// see WFLY-9752
continue;
}
if (info.annotations().containsKey(DECORATOR)) {
// we can't pick up on programatically added decorators, but that is such an edge case it should not really matter
continue;
}
if (!Modifier.isInterface(info.flags())) {
resteasyDeploymentData.getScannedResourceClasses().add(info.name().toString());
} else {
pathInterfaces.add(info);
}
}
}
if (providers != null) {
for (AnnotationInstance e : providers) {
if (e.target() instanceof ClassInfo) {
ClassInfo info = (ClassInfo) e.target();
if (info.name().toString().startsWith(ORG_APACHE_CXF)) {
// see WFLY-9752
continue;
}
if (info.annotations().containsKey(DECORATOR)) {
// we can't pick up on programatically added decorators, but that is such an edge case it should not really matter
continue;
}
if (!Modifier.isInterface(info.flags())) {
resteasyDeploymentData.getScannedProviderClasses().add(info.name().toString());
}
} else {
JAXRS_LOGGER.classAnnotationNotFound("@Provider", e.target());
}
}
}
// look for all implementations of interfaces annotated @Path
for (final ClassInfo iface : pathInterfaces) {
final Set<ClassInfo> implementors = index.getAllKnownImplementors(iface.name());
for (final ClassInfo implementor : implementors) {
if (implementor.name().toString().startsWith(ORG_APACHE_CXF)) {
// see WFLY-9752
continue;
}
if (implementor.annotations().containsKey(DECORATOR)) {
// we can't pick up on programatically added decorators, but that is such an edge case it should not really matter
continue;
}
resteasyDeploymentData.getScannedResourceClasses().add(implementor.name().toString());
}
}
}
use of javax.ws.rs.core.Application in project swagger-core by swagger-api.
the class Reader method resolveApplicationPath.
protected String resolveApplicationPath() {
if (application != null) {
Class<?> applicationToScan = this.application.getClass();
ApplicationPath applicationPath;
// search up in the hierarchy until we find one with the annotation, this is needed because for example Weld proxies will not have the annotation and the right class will be the superClass
while ((applicationPath = applicationToScan.getAnnotation(ApplicationPath.class)) == null && !applicationToScan.getSuperclass().equals(Application.class)) {
applicationToScan = applicationToScan.getSuperclass();
}
if (applicationPath != null) {
if (StringUtils.isNotBlank(applicationPath.value())) {
return applicationPath.value();
}
}
// look for inner application, e.g. ResourceConfig
try {
Application innerApp = application;
Method m = application.getClass().getMethod("getApplication");
while (m != null) {
Application retrievedApp = (Application) m.invoke(innerApp);
if (retrievedApp == null) {
break;
}
if (retrievedApp.getClass().equals(innerApp.getClass())) {
break;
}
innerApp = retrievedApp;
applicationPath = innerApp.getClass().getAnnotation(ApplicationPath.class);
if (applicationPath != null) {
if (StringUtils.isNotBlank(applicationPath.value())) {
return applicationPath.value();
}
}
m = innerApp.getClass().getMethod("getApplication");
}
} catch (NoSuchMethodException e) {
// no inner application found
} catch (Exception e) {
// no inner application found
}
}
return "";
}
use of javax.ws.rs.core.Application in project swagger-core by swagger-api.
the class JaxrsApplicationAndAnnotationScannerTest method setUp.
@BeforeMethod
public void setUp() {
scanner = new JaxrsApplicationAndAnnotationScanner();
scanner.setApplication(new Application() {
@Override
public Set<Class<?>> getClasses() {
return Collections.singleton(ResourceInApplication.class);
}
});
}
Aggregations