本文整理汇总了Java中javax.ws.rs.core.Application.getClasses方法的典型用法代码示例。如果您正苦于以下问题:Java Application.getClasses方法的具体用法?Java Application.getClasses怎么用?Java Application.getClasses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.Application
的用法示例。
在下文中一共展示了Application.getClasses方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SwaggerHandler
import javax.ws.rs.core.Application; //导入方法依赖的package包/类
public SwaggerHandler(
final Class<? extends Application> applicationClass) {
final ApplicationPath annotation = applicationClass.getAnnotation(ApplicationPath.class);
if (annotation != null) {
baseUri = URI.create(annotation.value()).normalize();
} else {
baseUri = URI.create("/");
}
Application application;
try {
application = applicationClass.newInstance();
} catch (InstantiationException
| IllegalAccessException e) {
throw new ExceptionInInitializerError(e);
}
swagger = new ClonableSwagger();
final Reader swaggerReader = new Reader(swagger);
final Set<Class<?>> resourceClasses = application.getClasses();
if (resourceClasses.isEmpty()) {
final String packageName = applicationClass.getPackage().getName();
final Reflections reflections = new Reflections(packageName);
reflections.getTypesAnnotatedWith(Api.class).forEach(swaggerReader::read);
reflections.getTypesAnnotatedWith(SwaggerDefinition.class).forEach(swaggerReader::read);
} else {
swaggerReader.read(applicationClass);
resourceClasses.forEach(swaggerReader::read);
}
}
示例2: index
import javax.ws.rs.core.Application; //导入方法依赖的package包/类
@GET
@Produces(MediaType.APPLICATION_JSON)
public ResourceIndex index(@Context Application application,
@Context HttpServletRequest request) throws Exception {
// String basePath = request.getRequestURL().toString();
// String basePath = getBasePath(request);
JsonObject rootNode = new JsonObject();
JsonArray classesNode = new JsonArray();
rootNode.addProperty(JS_TITLE_FIELD, Settings.getString(SettingCodes.API_TITLE, Bundle.SETTINGS, DefaultSettings.API_TITLE));
rootNode.addProperty(JS_INSTANCE_FIELD, WebUtil.getInstanceName());
rootNode.addProperty(JS_VERSION_FIELD, Settings.getString(SettingCodes.API_VERSION, Bundle.SETTINGS, DefaultSettings.API_VERSION));
rootNode.addProperty(JS_JVM_FIELD, System.getProperty("java.version"));
rootNode.addProperty(JS_REALM_FIELD, Settings.getString(SettingCodes.API_REALM, Bundle.SETTINGS, DefaultSettings.API_REALM));
AnnouncementVO announcement = WebUtil.getServiceLocator().getToolsService().getAnnouncement();
if (announcement != null) {
rootNode.addProperty(JS_ANNOUNCEMENT_FIELD, announcement.getMessage());
}
rootNode.add(JS_CLASSES_FIELD, classesNode);
ArrayList<Class> classes = new ArrayList<Class>(application.getClasses());
Collections.sort(classes, RESOURCE_CLASS_COMPARATOR);
Iterator<Class> classesIt = classes.iterator();
while (classesIt.hasNext()) {
Class resourceClass = classesIt.next();
if (isAnnotatedResourceClass(resourceClass)) {
classesNode.add(getResourceIndexNode(resourceClass, request)); // basePath));
}
}
// return Response.ok().entity(rootNode).build();
return new ResourceIndex(rootNode);
}