本文整理汇总了Java中javax.ws.rs.ApplicationPath类的典型用法代码示例。如果您正苦于以下问题:Java ApplicationPath类的具体用法?Java ApplicationPath怎么用?Java ApplicationPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApplicationPath类属于javax.ws.rs包,在下文中一共展示了ApplicationPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyConfigurationFromAnnotation
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
private void applyConfigurationFromAnnotation(Map<Class<? extends Annotation>, String> annotatedClassMap, Configuration configuration, SwaggerUIConfiguration swaggerUIConfiguration) {
configuration.setActive(swaggerUIConfiguration.active());
configuration.setConfigurationFilename(swaggerUIConfiguration.configurationFilename());
if (isNotEmpty(swaggerUIConfiguration.systemPropertyForExternalConfigurationFilename())) {
configuration.setSystemPropertyForExternalConfigurationFilename(swaggerUIConfiguration.systemPropertyForExternalConfigurationFilename());
}
configuration.setHost(swaggerUIConfiguration.host());
ApplicationPath applicationPath = getAnnotationFrom(annotatedClassMap, ApplicationPath.class);
if (applicationPath != null) {
try {
configuration.setRestApplicationClass(classLoader.loadClass(annotatedClassMap.get(ApplicationPath.class)));
configuration.setRestApplicationPath(applicationPath.value());
configuration.setRestApplicationPackageAsRoot(swaggerUIConfiguration.restApplicationPackageAsRoot());
if (configuration.isRestApplicationPackageAsRoot()) {
configuration.setRestApplicationPackage(configuration.getRestApplicationClass().getPackage().getName());
} else {
configuration.setRestApplicationPackage(swaggerUIConfiguration.restApplicationPackage());
}
} catch (ClassNotFoundException e) {
configuration.setRestApplicationClass(null);
}
}
configuration.setApiDocPath(swaggerUIConfiguration.apiDocPath());
configuration.setApiDocIndex(swaggerUIConfiguration.apiDocIndex());
}
示例2: onStartup
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
@Override
public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException {
servletContext.setAttribute(OZARK_CONTROLLERS_FOUND, false);
if (classes != null && !classes.isEmpty()) {
LOG.log(Level.INFO, "Ozark version {0} started", getClass().getPackage().getImplementationVersion());
for (Class<?> clazz : classes) {
final ApplicationPath ap = getAnnotation(clazz, ApplicationPath.class);
if (ap != null) {
if (servletContext.getAttribute(APP_PATH_CONTEXT_KEY) != null) {
// must be a singleton
throw new IllegalStateException("More than one JAX-RS ApplicationPath detected!");
}
servletContext.setAttribute(APP_PATH_CONTEXT_KEY, ap.value());
}
if (hasAnnotationOnClassOrMethod(clazz, Path.class)
&& hasAnnotationOnClassOrMethod(clazz, Controller.class)) {
servletContext.setAttribute(OZARK_CONTROLLERS_FOUND, true);
}
if (servletContext.getAttribute(APP_PATH_CONTEXT_KEY) != null
&& (Boolean) servletContext.getAttribute(OZARK_CONTROLLERS_FOUND) == true) {
break; // no need to loop further
}
}
}
}
示例3: JaxRsJavaTypeMetadata
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
public JaxRsJavaTypeMetadata(Class<?> javaType) {
isTrue(javaType.isInterface(), "Your type must be a Java interface.");
isTrue(javaType.getInterfaces().length <= 1, "Only single inheritance is supported.");
this.javaType = javaType;
this.parent = javaType.getInterfaces().length == 1 ? new JaxRsJavaTypeMetadata(javaType.getInterfaces()[0]) : null;
this.applicationPath = javaType.getAnnotation(ApplicationPath.class);
this.path = javaType.getAnnotation(Path.class);
isFalse(applicationPath != null && path != null,
"Invalid use of the @Path and @ApplicationPath annotations at the top of the interface. Use only one.");
this.consumes = javaType.getAnnotation(Consumes.class);
this.produces = javaType.getAnnotation(Produces.class);
}
示例4: getURLMappingFromApplication
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
private String getURLMappingFromApplication(Class<?> appClass) {
ApplicationPath apath = appClass.getAnnotation(ApplicationPath.class);
if (apath != null) {
String urlMapping = apath.value();
if (urlMapping == null || urlMapping.isEmpty() || urlMapping.equals("/")) {
return "";
}
if (urlMapping != null && !urlMapping.startsWith("/")) {
urlMapping = "/" + urlMapping;
}
return urlMapping;
}
else {
logger.finest("Didn't find @ApplicationPath in Application classs " + appClass.getName());
}
return null;
}
示例5: visitType
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
@Override
public Optional<String> visitType(TypeElement element, Void aVoid) {
String servletName = element.getAnnotation(ExposedApplication.class).servletName();
ApplicationPath applicationPath = element.getAnnotation(ApplicationPath.class);
String applicationName = String.valueOf(element.getQualifiedName());
if (!(applicationPath != null ^ !servletName.isEmpty())) {
messager.printMessage(ERROR, INCONSISTENT_APPLICATION_MAPPING.format(applicationName), element);
return absent();
}
if (applicationPath != null) {
return Optional.of(applicationName);
}
return Optional.of(servletName);
}
示例6: createJerseyHandler
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
private ServletContextHandler createJerseyHandler(final HandlerCollection handlerCollection) {
// http://nikgrozev.com/2014/10/16/rest-with-embedded-jetty-and-jersey-in-a-single-jar-step-by-step/
final Set<Class<?>> managedClasses = collectAnnotated(JAX_RS_MANAGED_CLASSES);
final ServletContextHandler context = initContext("/rest", managedClasses);
handlerCollection.addHandler(context);
final ResourceConfig config = initConfig(managedClasses);
annotationScanner.scanFor(ApplicationPath.class).forEach(appClass -> {
final String path = appClass.getAnnotation(ApplicationPath.class).value();
final String pathSpec = (path.startsWith("/") ? "" : "/") + path + "/*";
LOG.debug("Mapping rest application {} to {}", appClass.getName(), pathSpec);
context.addServlet(new ServletHolder(new JerseyServlet(config)), pathSpec);
});
return context;
}
示例7: getPathSpec
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
private String getPathSpec(Class<? extends Application> appClass) {
ApplicationPath applicationPath = appClass.getAnnotation(ApplicationPath.class);
StringBuilder pathSpec = new StringBuilder(applicationPath.value());
if(pathSpec.length()==0 || pathSpec.charAt(pathSpec.length()-1)!='/') {
pathSpec.append('/');
}
pathSpec.append('*');
return pathSpec.toString();
}
示例8: register
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
/**
* Register the routes.
*
* @param applicationClass
* application class to get the root
* @param router
* router to apply the changes to
* @param pathsProvider
* provides a list of Path classes
* @param jaxRsHandler
* route handler
*/
public void register(final Class<? extends Application> applicationClass,
final Router router,
final PathsProvider pathsProvider,
final Handler<RoutingContext> jaxRsHandler) {
final String rootPath = Optional.ofNullable(applicationClass.getAnnotation(ApplicationPath.class)).map(ApplicationPath::value).orElse("");
final SortedSet<JaxRsPath> paths = new TreeSet<>();
pathsProvider.getPathAnnotatedClasses().forEach(clazz -> {
final String classPath = Optional.ofNullable(clazz.getAnnotation(Path.class)).map(Path::value).orElse("");
stream(clazz.getMethods()).filter(m -> m.getAnnotation(GET.class) != null
|| m.getAnnotation(POST.class) != null
|| m.getAnnotation(PUT.class) != null
|| m.getAnnotation(DELETE.class) != null).forEach(m -> {
final String path = Optional.ofNullable(m.getAnnotation(Path.class)).map(Path::value).orElse("");
final String[] consumes = Optional.ofNullable(m.getAnnotation(Consumes.class)).map(Consumes::value).orElse(new String[0]);
final String[] produces = Optional.ofNullable(m.getAnnotation(Produces.class)).map(Produces::value).orElse(new String[0]);
paths.add(new JaxRsPath(UriBuilder.fromPath(rootPath).path(classPath).path(path).toTemplate(), consumes, produces, getHttpMethod(m)));
});
});
paths.forEach(p -> {
p.apply(router, jaxRsHandler, failureHandler);
LOG.debug("route={}", p);
});
}
示例9: SwaggerHandler
import javax.ws.rs.ApplicationPath; //导入依赖的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);
}
}
示例10: resolveApplicationPath
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
private void resolveApplicationPath() {
if (StringUtils.hasLength(this.resteasy.getApplicationPath())) {
this.path = parseApplicationPath(this.resteasy.getApplicationPath());
} else {
this.path = findApplicationPath(
AnnotationUtils.findAnnotation(this.config.getClass(), ApplicationPath.class));
}
}
示例11: readConfigurationFrom
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
@Override
protected Configuration readConfigurationFrom(Configuration configuration, ServletContext servletContext) {
@SuppressWarnings("unchecked") Map<Class<? extends Annotation>, String> annotatedClassMap = new ByteCodeAnnotationScanner(servletContext, SwaggerUIConfiguration.class, ApplicationPath.class).get();
if (annotatedClassMap.size() > 0) {
classLoader = getClassLoader();
return readConfiguration(annotatedClassMap, configuration);
}
return configuration;
}
示例12: allApplicationPaths
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
private String[] allApplicationPaths() {
ArrayList<String> applicationPaths = new ArrayList<>();
Optional.ofNullable(parent)
.map(p -> p.allApplicationPaths())
.ifPresent(array -> Collections.addAll(applicationPaths, array));
Optional.ofNullable(applicationPath).map(ApplicationPath::value)
.ifPresent(p -> applicationPaths.add(p));
return applicationPaths.toArray(new String[0]);
}
示例13: resolveApplicationPath
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
private void resolveApplicationPath() {
if (StringUtils.hasLength(this.jersey.getApplicationPath())) {
this.path = parseApplicationPath(this.jersey.getApplicationPath());
}
else {
this.path = findApplicationPath(AnnotationUtils
.findAnnotation(this.config.getClass(), ApplicationPath.class));
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:JerseyAutoConfiguration.java
示例14: findApplicationPath
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
private static String findApplicationPath(ApplicationPath annotation) {
// Jersey doesn't like to be the default servlet, so map to /* as a fallback
if (annotation == null) {
return "/*";
}
return parseApplicationPath(annotation.value());
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:JerseyAutoConfiguration.java
示例15: getApplicationPath
import javax.ws.rs.ApplicationPath; //导入依赖的package包/类
private static String getApplicationPath(Application applicationConfig) {
if (applicationConfig == null) {
return null;
}
ApplicationPath ap = applicationConfig.getClass().getAnnotation(ApplicationPath.class);
if (ap == null) {
return null;
}
String applicationPath = ap.value();
if (isBlank(applicationPath)) {
return null;
}
while (applicationPath.startsWith("/")) {
applicationPath = applicationPath.substring(1);
}
// support Servlet configs
if (applicationPath.endsWith("/*")) {
applicationPath = applicationPath.substring(0, applicationPath.length() - 2);
}
while (applicationPath.endsWith("/")) {
applicationPath = applicationPath.substring(0, applicationPath.length() - 1);
}
if (isBlank(applicationPath)) {
return null;
}
return applicationPath;
}