当前位置: 首页>>代码示例>>Java>>正文


Java ResourceConfig.getClasses方法代码示例

本文整理汇总了Java中com.sun.jersey.api.core.ResourceConfig.getClasses方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceConfig.getClasses方法的具体用法?Java ResourceConfig.getClasses怎么用?Java ResourceConfig.getClasses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.jersey.api.core.ResourceConfig的用法示例。


在下文中一共展示了ResourceConfig.getClasses方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureServlets

import com.sun.jersey.api.core.ResourceConfig; //导入方法依赖的package包/类
@Override
protected void configureServlets() {
    ResourceConfig rc = new PackagesResourceConfig(
            "dk.dma.ais.abnormal.event.rest",
            "dk.dma.ais.abnormal.stat.rest",
            "dk.dma.commons.web.rest.defaults",
            "org.codehaus.jackson.jaxrs"
    );

    for ( Class<?> resource : rc.getClasses() ) {
        String packageName = resource.getPackage().getName();
        if (packageName.equals("dk.dma.commons.web.rest.defaults") || packageName.equals("org.codehaus.jackson.jaxrs")) {
            bind(resource).in(Scopes.SINGLETON);
        } else {
            bind(resource);
        }
    }

    serve("/rest/*").with( GuiceContainer.class );
}
 
开发者ID:dma-ais,项目名称:AisAbnormal,代码行数:21,代码来源:RestModule.java

示例2: configureServlets

import com.sun.jersey.api.core.ResourceConfig; //导入方法依赖的package包/类
@Override
    protected void configureServlets() {
        bind(MetricsServlet.class).asEagerSingleton();

        Map<String, String> parameters = new HashMap<>();
        parameters.put(JSONConfiguration.FEATURE_POJO_MAPPING, "true");
//        parameters.put("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
//        parameters.put("com.sun.jersey.config.property.packages", packageName);
        parameters.put("jersey.config.beanValidation.enableOutputValidationErrorEntity.server", "true");
        parameters.put("com.sun.jersey.api.json.POJOMappingFeature", "true");

        ResourceConfig rc = new PackagesResourceConfig(packageName);
        for (Class<?> resource : rc.getClasses()) {
            bind(resource).asEagerSingleton();
        }

        serve("/metrics").with(MetricsServlet.class);
        serve("/rest/*").with(GuiceContainer.class, parameters);
    }
 
开发者ID:enigma11,项目名称:jetty-guice,代码行数:20,代码来源:MainModule.java

示例3: bindJaxrsResources

import com.sun.jersey.api.core.ResourceConfig; //导入方法依赖的package包/类
/**
 * bind JAX-RS annotated classes to be served through Guice. based on a recursive class scanning that starts from the package
 * returned by {@link #getRootPackage()}. override this if you wish to avoid the scanning and bind your classes explicitly
 */
protected void bindJaxrsResources()
{
	String rootPackage = getRootPackage();
	if (rootPackage == null)
		throw new NullPointerException(
				"to scan for JAX-RS annotated classes, either override getRootPackage() or bindJaxrsResources()");

	ResourceConfig rc = new PackagesResourceConfig(rootPackage);
	for (Class<?> resource : rc.getClasses())
		bind(resource);
}
 
开发者ID:zach-m,项目名称:gae-jersey-guice-jsf,代码行数:16,代码来源:GuiceRestModule.java

示例4: configure

import com.sun.jersey.api.core.ResourceConfig; //导入方法依赖的package包/类
@Override
protected void configure() {
    install(new ServletModule() {
        @Override
        protected void configureServlets() {
            serve("/*").with(GuiceContainer.class);
        }
    });
    final ResourceConfig rc = new PackagesResourceConfig(packageName);
    for (final Class<?> resource : rc.getClasses()) {
        bind(resource);
    }
}
 
开发者ID:a86c6f7964,项目名称:ruist,代码行数:14,代码来源:JerseyModule.java

示例5: runWithBodyGen

import com.sun.jersey.api.core.ResourceConfig; //导入方法依赖的package包/类
private void runWithBodyGen(final JaxrsVersion jaxrsVersion, final boolean useJsr303Annotations,String resource) throws Exception {
	final Set<String> generatedSources = new HashSet<String>();
	
	final Configuration configuration = new Configuration();
	configuration.setJaxrsVersion(jaxrsVersion);
	configuration.setUseJsr303Annotations(useJsr303Annotations);
	File root = codegenOutputFolder.getRoot();
	root=new File("/Users/kor/git/aml/raml-to-jaxrs/core/src/test/javagen");
	configuration.setOutputDirectory(root);
	configuration.setGenerateImpl(true);
	configuration.setBasePackageName(TEST_BASE_PACKAGE);
	String dirPath = getClass().getResource("/org/raml").getPath();
	
	configuration.setSourceDirectory(new File(dirPath));
	String name = resource;
	Set<String> run = new Generator()
			.run(new InputStreamReader(getClass().getResourceAsStream(name)), configuration);
	for (String s : run) {
		generatedSources.add(s.replace('\\', '/'));
	}

	// test compile the classes
	final JavaCompiler compiler = new JavaCompilerFactory().createCompiler("eclipse");

	final JavaCompilerSettings settings = compiler.createDefaultSettings();
	settings.setSourceVersion("1.5");
	settings.setTargetVersion("1.5");
	settings.setDebug(true);

	final String[] sources = generatedSources.toArray(EMPTY_STRING_ARRAY);

	final FileResourceReader sourceReader = new FileResourceReader(root);
	final FileResourceStore classWriter = new FileResourceStore(compilationOutputFolder.getRoot());
	final CompilationResult result = compiler.compile(sources, sourceReader, classWriter,
			Thread.currentThread().getContextClassLoader(), settings);

	assertThat(ToStringBuilder.reflectionToString(result.getErrors(), ToStringStyle.SHORT_PREFIX_STYLE),
			result.getErrors(), is(emptyArray()));

	assertThat(ToStringBuilder.reflectionToString(result.getWarnings(), ToStringStyle.SHORT_PREFIX_STYLE),
			result.getWarnings(), is(emptyArray()));

	// test load the classes with Jersey
	final URLClassLoader resourceClassLoader = new URLClassLoader(
			new URL[] { compilationOutputFolder.getRoot().toURI().toURL() });

	final ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader();
	try {
		Thread.currentThread().setContextClassLoader(resourceClassLoader);
		final ResourceConfig config = new PackagesResourceConfig(TEST_BASE_PACKAGE);

		Set<Class<?>> classes = config.getClasses();

		Iterator<Class<?>> it = classes.iterator();
		Class<?> something = it.next();
		Method[] methods = something.getDeclaredMethods();
		
		// assertEquals(InputStream.class.getName(),
		// methodWithInputStreamParam.getParameterTypes()[0].getName());
	} finally {
		Thread.currentThread().setContextClassLoader(initialClassLoader);
	}
}
 
开发者ID:OnPositive,项目名称:aml,代码行数:64,代码来源:RAML1Test.java

示例6: run

import com.sun.jersey.api.core.ResourceConfig; //导入方法依赖的package包/类
private void run(final JaxrsVersion jaxrsVersion, final boolean useJsr303Annotations) throws Exception
  {
      final Set<String> generatedSources = new HashSet<String>();

      final Configuration configuration = new Configuration();
      configuration.setJaxrsVersion(jaxrsVersion);
      configuration.setUseJsr303Annotations(useJsr303Annotations);
      configuration.setOutputDirectory(codegenOutputFolder.getRoot());

      configuration.setBasePackageName(TEST_BASE_PACKAGE);
      String dirPath = getClass().getResource("/org/raml").getPath();

      configuration.setSourceDirectory( new File(dirPath) );
      generatedSources.addAll(new Generator().run(
          new InputStreamReader(getClass().getResourceAsStream("/org/raml/mediatype/application_octet-stream.yaml")),
          configuration));

      // test compile the classes
      final JavaCompiler compiler = new JavaCompilerFactory().createCompiler("eclipse");

      final JavaCompilerSettings settings = compiler.createDefaultSettings();
      settings.setSourceVersion("1.5");
      settings.setTargetVersion("1.5");
      settings.setDebug(true);

      String[] sources = generatedSources.toArray(EMPTY_STRING_ARRAY);
      generatedSources.clear();
      for (String s : sources) {
	generatedSources.add(s.replace('\\', '/'));
}
      sources = generatedSources.toArray(EMPTY_STRING_ARRAY);
      final FileResourceReader sourceReader = new FileResourceReader(codegenOutputFolder.getRoot());
      final FileResourceStore classWriter = new FileResourceStore(compilationOutputFolder.getRoot());
      final CompilationResult result = compiler.compile(sources, sourceReader, classWriter,
          Thread.currentThread().getContextClassLoader(), settings);

      assertThat(ToStringBuilder.reflectionToString(result.getErrors(), ToStringStyle.SHORT_PREFIX_STYLE),
          result.getErrors(), is(emptyArray()));

      assertThat(
          ToStringBuilder.reflectionToString(result.getWarnings(), ToStringStyle.SHORT_PREFIX_STYLE),
          result.getWarnings(), is(emptyArray()));

      // test load the classes with Jersey
      final URLClassLoader resourceClassLoader = new URLClassLoader(
          new URL[]{compilationOutputFolder.getRoot().toURI().toURL()});

      final ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader();
      try
      {
          Thread.currentThread().setContextClassLoader(resourceClassLoader);
          final ResourceConfig config = new PackagesResourceConfig(TEST_BASE_PACKAGE);
          
          Set<Class<?>> classes = config.getClasses();
          
          Iterator<Class<?>> it = classes.iterator();
          Class<?> something = it.next();
          Method[] methods = something.getDeclaredMethods();
          
          Method methodWithInputStreamParam = methods[0];
          
          assertEquals(InputStream.class.getName(), methodWithInputStreamParam.getParameterTypes()[0].getName());
      }
      finally
      {
          Thread.currentThread().setContextClassLoader(initialClassLoader);
      }
  }
 
开发者ID:OnPositive,项目名称:aml,代码行数:69,代码来源:MediaTypeGeneratorTestCase.java


注:本文中的com.sun.jersey.api.core.ResourceConfig.getClasses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。