本文整理匯總了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 );
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}