本文整理匯總了Java中com.google.inject.servlet.RequestScoped類的典型用法代碼示例。如果您正苦於以下問題:Java RequestScoped類的具體用法?Java RequestScoped怎麽用?Java RequestScoped使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RequestScoped類屬於com.google.inject.servlet包,在下文中一共展示了RequestScoped類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: beforeEach
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
@Override
public void beforeEach(final ExtensionContext context) throws Exception {
final GuicyTest testInstance = (GuicyTest)context.getTestInstance().get();
final Module module = testInstance.module();
final RequestScope requestScope = new RequestScope();
final AbstractModule basicTestModule = new AbstractModule() {
@Override
protected void configure() {
this.bindScope(RequestScoped.class, requestScope);
this.bind(RequestScope.class).toInstance(requestScope);
this.bind(HttpServletRequest.class).to(FakeHttpServletRequest.class);
this.bind(HttpServletResponse.class).to(FakeHttpServletResponse.class);
}
};
final Injector injector = Guice.createInjector(Modules.override(basicTestModule).with(module));
context.getStore(NAMESPACE).put(Injector.class, injector);
final ScopeRequestFilter scopeFilter = injector.getInstance(ScopeRequestFilter.class);
injector.getInstance(Requestor.class).addFilter(scopeFilter);
}
示例2: getCookieMap
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
@Provides
@CookieMap
@RequestScoped
Multimap<String,Cookie> getCookieMap(
Provider<HttpServletRequest> httpServletRequestProvider) {
Cookie[] cookies = httpServletRequestProvider.get().getCookies();
ImmutableMultimap.Builder<String, Cookie> temp =
new ImmutableMultimap.Builder<String, Cookie>();
if (cookies != null) {
for (Cookie cookie : cookies) {
temp.put(cookie.getName(), cookie);
}
}
return temp.build();
}
示例3: module
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
static Module module() {
return new AbstractModule() {
@Override
public void configure() {
install(new GerritRequestModule());
bind(RequestScopePropagator.class).to(Propagator.class);
bindScope(RequestScoped.class, InProcessProtocol.REQUEST);
}
@Provides
@RemotePeer
SocketAddress getSocketAddress() {
// TODO(dborowitz): Could potentially fake this with thread ID or
// something.
throw new OutOfScopeException("No remote peer in acceptance tests");
}
};
}
示例4: module
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
public static Module module() {
return new CacheModule() {
@Override
protected void configure() {
persist(WebSessionManager.CACHE_NAME, String.class, Val.class)
.maximumWeight(1024) // reasonable default for many sites
.expireAfterWrite(
CacheBasedWebSession.MAX_AGE_MINUTES,
MINUTES) // expire sessions if they are inactive
;
install(new FactoryModuleBuilder().build(WebSessionManagerFactory.class));
DynamicItem.itemOf(binder(), WebSession.class);
DynamicItem.bind(binder(), WebSession.class)
.to(H2CacheBasedWebSession.class)
.in(RequestScoped.class);
}
};
}
示例5: provideAppengineUser
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
@Provides @RequestScoped
User provideAppengineUser(UserService userService) {
User user = userService.getCurrentUser();
if (user == null) {
throw new ProvisionException("Not logged in");
}
return user;
}
示例6: provideWaveUrlBase
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
@Provides @RequestScoped @Named("wave url base")
String provideWaveUrlBase(HttpServletRequest req) throws MalformedURLException {
URL requestUrl = new URL(req.getRequestURL().toString());
String portString = requestUrl.getPort() == -1 ? "" : ":" + requestUrl.getPort();
String waveUrlBase = requestUrl.getProtocol() + "://" + requestUrl.getHost() + portString + "/";
log.info("requestUrl=" + requestUrl + ", waveUrlBase=" + waveUrlBase);
return waveUrlBase;
}
示例7: get
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
@Provides
@RequestScoped
TestId get(@CookieMap Multimap<String,Cookie> cookieMap) {
Collection<Cookie> temp = cookieMap.get(TestId.COOKIE_NAME);
if (temp.size() > 1) {
throw new IllegalStateException(String.format(
"There's more than one Cookie named '%s'.", TestId.COOKIE_NAME));
} else if (temp.size() == 0) {
return null;
}
return new TestId(temp.iterator().next());
}
示例8: configure
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
@Override
protected void configure() {
bind(RequestScopePropagator.class).to(GuiceRequestScopePropagator.class);
bind(HttpRequestContext.class);
installAuthModule();
if (options.enableMasterFeatures()) {
install(new UrlModule(options, authConfig));
install(new UiRpcModule());
}
install(new GerritRequestModule());
install(new GitOverHttpServlet.Module(options.enableMasterFeatures()));
if (gitwebCgiConfig.getGitwebCgi() != null) {
install(new GitwebModule());
}
install(new AsyncReceiveCommits.Module());
bind(SocketAddress.class)
.annotatedWith(RemotePeer.class)
.toProvider(HttpRemotePeerProvider.class)
.in(RequestScoped.class);
bind(ProxyProperties.class).toProvider(ProxyPropertiesProvider.class);
listener().toInstance(registerInParentInjectors());
install(UniversalWebLoginFilter.module());
}
示例9: configure
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
@Override
protected void configure() {
bind(RequestCleanup.class).in(RequestScoped.class);
bind(RequestScopedReviewDbProvider.class);
bind(IdentifiedUser.RequestFactory.class).in(SINGLETON);
bind(PerRequestProjectControlCache.class).in(RequestScoped.class);
}
示例10: configure
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
@Override
protected void configure()
{
bind(Gson.class).toInstance(new GsonBuilder().setPrettyPrinting().create());
bind(LabelJsonProvider.class).to(LabelJsonFromFileProvider.class).in(Scopes.SINGLETON);
bind(GlobalConfigurationJsonStore.class).in(Scopes.SINGLETON);
bind(IdentityConfJsonStore.class).in(Scopes.SINGLETON);
bind(UserPermissionsJsonStore.class).in(Scopes.SINGLETON);
bind(ExperimentalConfJsonStore.class).in(Scopes.SINGLETON);
bind(RequestBodyReader.class).in(RequestScoped.class);
}
示例11: configure
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
@Override
protected void configure() {
Provider<Injector> injector = getProvider(Injector.class);
bind(ServiceLocator.class).toProvider(new ServiceLocatorProvider(injector, locator))
.in(Singleton.class);
Provider<ServiceLocator> provider = getProvider(ServiceLocator.class);
bind(Application.class)
.toProvider(new JerseyProvider<>(provider, Application.class));
bind(Providers.class)
.toProvider(new JerseyProvider<>(provider, Providers.class));
bind(UriInfo.class)
.toProvider(new JerseyProvider<>(provider, UriInfo.class))
.in(RequestScoped.class);
bind(HttpHeaders.class)
.toProvider(new JerseyProvider<>(provider, HttpHeaders.class))
.in(RequestScoped.class);
bind(SecurityContext.class)
.toProvider(new JerseyProvider<>(provider, SecurityContext.class))
.in(RequestScoped.class);
bind(Request.class)
.toProvider(new JerseyProvider<>(provider, Request.class))
.in(RequestScoped.class);
}
示例12: configure
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
@Override
protected void configure() {
bindScope(RequestScoped.class, ServletScopes.REQUEST);
for (Binding binding : bindings) {
binding.bind();
}
}
示例13: provideAppengineUser
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
@Provides
@RequestScoped
User provideAppengineUser(UserService userService) {
User user = userService.getCurrentUser();
if (user == null) {
throw new ProvisionException("Not logged in");
}
return user;
}
示例14: configure
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
@Override
protected void configure() {
configureHandlers();
bindScope(RequestScoped.class, requestScope);
bind(RequestScope.class).toInstance(requestScope);
bind(new Key<List<RequestMatcher>>() {}).toInstance(matchers.build());
bind(Servlet.class).to(RequestHandlerServlet.class).in(Singleton.class);
bind(GatewayRequestHandler.Factory.class).toProvider(
FactoryProvider.newFactory(
GatewayRequestHandler.Factory.class, GatewayRequestHandler.class));
bind(GatewayConfiguration.class).in(Singleton.class);
}
示例15: serve
import com.google.inject.servlet.RequestScoped; //導入依賴的package包/類
protected void serve(HttpMethod method, String pattern, Class<? extends RequestHandler> withHttpHandler) {
logger.debug("Registering {} on {} to {}", new Object[]{method, pattern, withHttpHandler});
RequestMatcher matcher = new RequestMatcher(method, pattern);
matchers.add(matcher);
MapBinder.newMapBinder(binder(), RequestMatcher.class, RequestHandler.class)
.addBinding(matcher).to(withHttpHandler).in(RequestScoped.class);
}