本文整理汇总了Java中com.sun.jersey.api.core.ResourceConfig类的典型用法代码示例。如果您正苦于以下问题:Java ResourceConfig类的具体用法?Java ResourceConfig怎么用?Java ResourceConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResourceConfig类属于com.sun.jersey.api.core包,在下文中一共展示了ResourceConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureWebAppServlets
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
protected void configureWebAppServlets() {
// Add in the web services filters/serves if app has them.
// Using Jersey/guice integration module. If user has web services
// they must have also bound a default one in their webapp code.
if (this.wsName != null) {
// There seems to be an issue with the guice/jersey integration
// where we have to list the stuff we don't want it to serve
// through the guicecontainer. In this case its everything except
// the the web services api prefix. We can't just change the filter
// from /* below - that doesn't work.
String regex = "(?!/" + this.wsName + ")";
serveRegex(regex).with(DefaultWrapperServlet.class);
Map<String, String> params = new HashMap<String, String>();
params.put(ResourceConfig.FEATURE_IMPLICIT_VIEWABLES, "true");
params.put(ServletContainer.FEATURE_FILTER_FORWARD_ON_404, "true");
params.put(FeaturesAndProperties.FEATURE_XMLROOTELEMENT_PROCESSING, "true");
params.put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, GZIPContentEncodingFilter.class.getName());
params.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, GZIPContentEncodingFilter.class.getName());
filter("/*").through(getWebAppFilterClass(), params);
}
}
示例2: CCOWContextListener
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
public CCOWContextListener(final ContextState commonContext, final Module... behaviourModules) {
super();
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
logger.info("Starting up servlet ...");
this.modules = ImmutableList.<Module> builder().add(behaviourModules).add(new EndpointModule(commonContext))
.add(new JerseyServletModule() {
@Override
protected void configureServlets() {
final Map<String, String> params = ImmutableMap.<String, String> builder()
.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS,
GZIPContentEncodingFilter.class.getName())
.build();
bind(CORSFilter.class).in(Singleton.class);
bind(UrlRewriteFilter.class).in(Singleton.class);
serve("/*").with(GuiceContainer.class, params);
filter("/*").through(CORSFilter.class);
filter("/*").through(UrlRewriteFilter.class);
requestStaticInjection(WebSocketsConfigurator.class);
}
}).build();
}
示例3: initiate
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
@Override
protected void initiate(ResourceConfig rc, WebApplication wa) {
try {
//Register the OfflineRestFilter
String filters = (String) rc.getProperties().get(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS);
rc.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
filters + ",org.artifactory.rest.filter.OfflineRestFilter");
//Register the lICENSERestFilter
filters = (String) rc.getProperties().get(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS);
rc.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
filters + ",org.artifactory.rest.filter.LicenseRestFilter");
//Register spring as component provider
ArtifactoryContext artifactoryContext = (ArtifactoryContext) getServletContext().getAttribute(
ArtifactoryContext.APPLICATION_CONTEXT_KEY);
SpringComponentProviderFactory springComponentProviderFactory =
new SpringComponentProviderFactory(rc, (ConfigurableApplicationContext) artifactoryContext);
wa.initiate(rc, springComponentProviderFactory);
} catch (RuntimeException e) {
log.error("Exception in initialization of the Rest servlet");
throw e;
}
}
示例4: testClassesFromProvidesMethodsWithModuleInjectsAndNoInjectsConstructorAreRegistered
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
@Test
public void testClassesFromProvidesMethodsWithModuleInjectsAndNoInjectsConstructorAreRegistered() {
ResourceConfig config = new DefaultResourceConfig();
ObjectGraph objectGraph = ObjectGraph.create(SomeInjectableProvidesModule.class,
new SomeOtherInjectableProvidesModule());
IoCComponentProviderFactory factory = new DaggerComponentProviderFactory(config, objectGraph,
new Object[]{SomeInjectableProvidesModule.class, new SomeOtherInjectableProvidesModule()});
assertTrue(config.getClasses().contains(SomeProvidesInjectableResource.class));
assertTrue(config.getClasses().contains(SomeOtherProvidesInjectableResource.class));
assertTrue(config.getClasses().contains(SomeProvidesInjectableProvider.class));
SomeProvidesInjectableResource someResource = (SomeProvidesInjectableResource) factory.
getComponentProvider(SomeProvidesInjectableResource.class).getInstance();
SomeOtherProvidesInjectableResource someOtherResource = (SomeOtherProvidesInjectableResource) factory
.getComponentProvider(SomeOtherProvidesInjectableResource.class).getInstance();
SomeProvidesInjectableProvider someProvider = (SomeProvidesInjectableProvider) factory
.getComponentProvider(SomeProvidesInjectableProvider.class).getInstance();
assertNotNull(someResource);
assertNotNull(someOtherResource);
assertNotNull(someProvider);
}
示例5: configure
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
@Override
protected AppDescriptor configure() {
this.requestConfiguration = RequestConfiguration.builder().withApiKeyQueryParamName("passkey")
.withSignatureHttpHeader("duck-duck-signature-header")
.withTimestampHttpHeader("duck-duck-timestamp-header")
.withVersionHttpHeader("duck-duck-version-header")
.build();
final Authenticator<String> authenticator = new Authenticator<String>() {
@Override
public String authenticate(Credentials credentials) {
if (GOOD_API_KEY.equals(credentials.getApiKey())) {
return GOOD_API_KEY;
}
if (INTERNAL_ERROR.equals(credentials.getApiKey())) {
throw new IllegalStateException("An internal error occurred");
}
return null;
}
};
ResourceConfig config = new ScanningResourceConfig();
config.getSingletons().add(new HmacAuthProvider<String>(new DefaultRequestHandler<String>(authenticator, requestConfiguration)));
config.getSingletons().add(new AuthResource());
return new LowLevelAppDescriptor.Builder(config).build();
}
示例6: register
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
/**
* Registers any Guice-bound providers or root resources.
*
* @param config the resource configuration
* @param injector the Guice injector
*/
private void register(ResourceConfig config, Injector injector) {
while (injector != null) {
for (Key<?> key : injector.getBindings().keySet()) {
Type type = key.getTypeLiteral().getType();
if (type instanceof Class) {
Class<?> c = (Class) type;
if (ResourceConfig.isProviderClass(c)) {
LOGGER.log(Level.INFO, "Registering {0} as a provider class", c.getName());
config.getClasses().add(c);
} else if (ResourceConfig.isRootResourceClass(c)) {
LOGGER.log(Level.INFO, "Registering {0} as a root resource class", c.getName());
config.getClasses().add(c);
}
}
}
injector = injector.getParent();
}
}
示例7: configureServlets
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
@Override
public void configureServlets() {
setup();
serve("/", "/__stop").with(Dispatcher.class);
for (String path : this.getServePathSpecs()) {
serve(path).with(Dispatcher.class);
}
String regex = "(?!/ws)";
serveRegex(regex).with(SliderDefaultWrapperServlet.class);
Map<String, String> params = new HashMap<String, String>();
params.put(ResourceConfig.FEATURE_IMPLICIT_VIEWABLES, "true");
params.put(ServletContainer.FEATURE_FILTER_FORWARD_ON_404, "true");
params.put(ResourceConfig.FEATURE_XMLROOTELEMENT_PROCESSING, "true");
params.put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, GZIPContentEncodingFilter.class.getName());
params.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, GZIPContentEncodingFilter.class.getName());
//params.put("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
//params.put("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
//params.put("com.sun.jersey.config.feature.Trace", "true");
params.put("com.sun.jersey.config.property.WadlGeneratorConfig",
AMWadlGeneratorConfig.CLASSNAME);
filter("/*").through(GuiceContainer.class, params);
}
示例8: RestApplication
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
/**
* Constructor.
* @param manager
*/
public RestApplication( Manager manager ) {
super();
this.applicationResource = new ApplicationResource( manager );
this.managementResource = new ManagementResource( manager );
this.debugResource = new DebugResource( manager );
this.targetResource = new TargetResource( manager );
this.preferencesResource = new PreferencesResource( manager );
this.schedulerResource = new SchedulerResource( manager );
this.authenticationResource = new AuthenticationResource( manager );
this.historyResource = new HistoryResource( manager );
getFeatures().put( "com.sun.jersey.api.json.POJOMappingFeature", Boolean.TRUE );
getFeatures().put( ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE );
}
示例9: main
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
Map<String, String> mapArgs = parseArgs(args);
System.out.println("Starting Ambari API server using the following properties: " + mapArgs);
System.setProperty("ambariapi.dbfile", mapArgs.get("db"));
ResourceConfig config = new PackagesResourceConfig("org.apache.ambari.server.api.services");
System.out.println("Starting server: http://localhost:" + mapArgs.get("port") + '/');
HttpServer server = HttpServerFactory.create("http://localhost:" + mapArgs.get("port") + '/', config);
server.start();
System.out.println("SERVER RUNNING: http://localhost:" + mapArgs.get("port") + '/');
System.out.println("Hit return to stop...");
System.in.read();
System.out.println("Stopping server");
server.stop(0);
System.out.println("Server stopped");
}
示例10: configureServlets
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
@Override
protected void configureServlets() {
// filters
// Objectify filter
filter("/*").through(ObjectifyFilter.class);
// servlets
serve("/home").with(HomeServlet.class);
// Jersey restful servlet
HashMap<String, String> params = new HashMap<String, String>();
params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "uk.co.inetria.appstart.frontend.rest");
params.put(JSONConfiguration.FEATURE_POJO_MAPPING, "true");
// speed up jersey startup under appengine
params.put(ResourceConfig.FEATURE_DISABLE_WADL, "true");
serve("/api/*").with(GuiceContainer.class, params);
}
示例11: configure
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
@Override
protected void configure() {
bind(RefAppResource.class);
// Install servlet module setting a the Jersey/Guice integration.
install(new ServletModule() {
@Override
protected void configureServlets() {
filter("/*").through(GuiceContainer.class,
ImmutableMap.of(JSONConfiguration.FEATURE_POJO_MAPPING, "true",
ResourceConfig.FEATURE_TRACE, "true",
ResourceConfig.FEATURE_TRACE_PER_REQUEST, "true",
ServletContainer.FEATURE_FILTER_FORWARD_ON_404, "true"));
}
});
}
示例12: testInvokeResourceWithCategory
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
@Test
public void testInvokeResourceWithCategory() throws Exception {
final Map<String, String> initParams = new HashMap<>();
initParams.put(NewRelicResourceFilterFactory.TRANSACTION_CATEGORY_PROP, "someCategory");
initParams.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES,
NewRelicResourceFilterFactory.class.getCanonicalName());
server = getServer(getInjector(initParams).getInstance(GuiceFilter.class));
server.start();
Response response = httpClient.prepareGet("http://localhost:" + PORT + "/foo").execute().get();
assertEquals(200, response.getStatusCode());
assertEquals(newArrayList("someCategory:/foo GET"), wrapper.getNames());
assertTrue(wrapper.getThrowables().isEmpty());
}
示例13: testInvokeResourceWithoutCategory
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
@Test
public void testInvokeResourceWithoutCategory() throws Exception {
final Map<String, String> initParams = new HashMap<>();
initParams.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES,
NewRelicResourceFilterFactory.class.getCanonicalName());
server = getServer(getInjector(initParams).getInstance(GuiceFilter.class));
server.start();
Response response = httpClient.prepareGet("http://localhost:" + PORT + "/foo").execute().get();
assertEquals(200, response.getStatusCode());
assertEquals(newArrayList("/foo GET"), wrapper.getNames());
assertTrue(wrapper.getThrowables().isEmpty());
}
示例14: testInvokeThrowsResource
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
@Test
public void testInvokeThrowsResource() throws Exception {
final Map<String, String> initParams = new HashMap<>();
initParams.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES,
NewRelicResourceFilterFactory.class.getCanonicalName());
server = getServer(getInjector(initParams).getInstance(GuiceFilter.class));
server.start();
Response response = httpClient.prepareGet("http://localhost:" + PORT + "/foo/throw").execute().get();
assertEquals(500, response.getStatusCode());
assertEquals(newArrayList("/foo/throw GET"), wrapper.getNames());
assertEquals(1, wrapper.getThrowables().size());
assertEquals("zomg", wrapper.getThrowables().get(0).getMessage());
}
示例15: testInvokeThrowsMappedResource
import com.sun.jersey.api.core.ResourceConfig; //导入依赖的package包/类
@Test
public void testInvokeThrowsMappedResource() throws Exception {
final Map<String, String> initParams = new HashMap<>();
initParams.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES,
NewRelicResourceFilterFactory.class.getCanonicalName());
server = getServer(getInjector(initParams).getInstance(GuiceFilter.class));
server.start();
Response response = httpClient.prepareGet("http://localhost:" + PORT + "/foo/throwMapped").execute().get();
assertEquals(javax.ws.rs.core.Response.Status.NOT_ACCEPTABLE.getStatusCode(), response.getStatusCode());
assertEquals(newArrayList("/foo/throwMapped GET"), wrapper.getNames());
assertEquals(1, wrapper.getThrowables().size());
assertEquals("asdf", wrapper.getThrowables().get(0).getMessage());
}