當前位置: 首頁>>代碼示例>>Java>>正文


Java ApplicationPath類代碼示例

本文整理匯總了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());
}
 
開發者ID:ptitbob,項目名稱:swagger-ui-integration,代碼行數:26,代碼來源:AnnotationConfigurationReader.java

示例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
            }
        }
    }
}
 
開發者ID:mvc-spec,項目名稱:ozark,代碼行數:26,代碼來源:OzarkContainerInitializer.java

示例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);
}
 
開發者ID:ljtfreitas,項目名稱:java-restify,代碼行數:17,代碼來源:JaxRsJavaTypeMetadata.java

示例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;
}
 
開發者ID:WASdev,項目名稱:tool.swagger.docgen,代碼行數:18,代碼來源:SwaggerAnnotationsScanner.java

示例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);
}
 
開發者ID:vidal-community,項目名稱:jax-rs-linker,代碼行數:17,代碼來源:ApplicationNameVisitor.java

示例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;
}
 
開發者ID:dajudge,項目名稱:testee.fi,代碼行數:15,代碼來源:RestServerImpl.java

示例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();
}
 
開發者ID:chonton,項目名稱:apm-client,代碼行數:10,代碼來源:HelloMain.java

示例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);
    });

}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:41,代碼來源:JaxRsRouter.java

示例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);
    }

}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:33,代碼來源:SwaggerHandler.java

示例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));
	}
}
 
開發者ID:holon-platform,項目名稱:holon-jaxrs,代碼行數:9,代碼來源:ResteasyAutoConfiguration.java

示例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;
}
 
開發者ID:ptitbob,項目名稱:swagger-ui-integration,代碼行數:10,代碼來源:AnnotationConfigurationReader.java

示例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]);
}
 
開發者ID:ljtfreitas,項目名稱:java-restify,代碼行數:13,代碼來源:JaxRsJavaTypeMetadata.java

示例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;
}
 
開發者ID:bbilger,項目名稱:jrestless,代碼行數:28,代碼來源:ApplicationPathFilter.java


注:本文中的javax.ws.rs.ApplicationPath類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。