本文整理汇总了Java中org.apache.tapestry5.services.Request类的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于org.apache.tapestry5.services包,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildTimingFilter
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
public RequestFilter buildTimingFilter(final Logger log) {
return new RequestFilter() {
public boolean service(Request request, Response response, RequestHandler handler) throws IOException {
long startTime = System.currentTimeMillis();
try {
return handler.service(request, response);
} finally {
long elapsed = System.currentTimeMillis() - startTime;
log.info(String.format("Request time: %d ms, %s", elapsed, request.getPath()));
}
}
};
}
示例2: handleRetrieveAlerts
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
protected void handleRetrieveAlerts(final Request request, final Response response) throws IOException {
// See TAP5-1941
if (!request.isXHR()) {
response.sendError(400, "Expecting XMLHttpRequest");
}
JSONObject result = new JSONObject();
AlertStorage storage = applicationStateManager.getIfExists(AlertStorage.class);
if (storage != null) {
for (Alert alert : storage.getAlerts()) {
result.append("alerts", alert.toJSON());
}
storage.dismissNonPersistent();
}
try (PrintWriter printWriter = response.getPrintWriter("application/json")) {
printWriter.write(result.toString(productionMode));
}
}
示例3: handleDismissAlerts
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
protected void handleDismissAlerts(final Request request, final Response response) throws IOException {
AlertStorage storage = applicationStateManager.getIfExists(AlertStorage.class);
if (storage != null) {
String id = request.getParameter("id");
if (id != null) {
storage.dismiss(Long.parseLong(id));
} else {
storage.dismissAll();
}
}
if (request.isXHR()) {
try (PrintWriter printWriter = response.getPrintWriter("application/json")) {
printWriter.write("{}");
}
}
}
示例4: buildTimingFilter
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
/**
* This is a service definition, the service will be named "TimingFilter".
* The interface, RequestFilter, is used within the RequestHandler service
* pipeline, which is built from the RequestHandler service configuration.
* Tapestry IoC is responsible for passing in an appropriate Logger
* instance. Requests for static resources are handled at a higher level, so
* this filter will only be invoked for Tapestry related requests.
* <p/>
* <p/>
* Service builder methods are useful when the implementation is inline as
* an inner class (as here) or require some other kind of special
* initialization. In most cases, use the static bind() method instead.
* <p/>
* <p/>
* If this method was named "build", then the service id would be taken from
* the service interface and would be "RequestFilter". Since Tapestry
* already defines a service named "RequestFilter" we use an explicit
* service id that we can reference inside the contribution method.
*/
public RequestFilter buildTimingFilter(final Logger log) {
return new RequestFilter() {
public boolean service(Request request, Response response, RequestHandler handler) throws IOException {
long startTime = System.currentTimeMillis();
try {
// The responsibility of a filter is to invoke the
// corresponding method
// in the handler. When you chain multiple filters together,
// each filter
// received a handler that is a bridge to the next filter.
return handler.service(request, response);
} finally {
long elapsed = System.currentTimeMillis() - startTime;
log.info(String.format("Request time: %d ms", elapsed));
}
}
};
}
示例5: buildTimingFilter
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
/**
* This is a service definition, the service will be named "TimingFilter". The interface,
* RequestFilter, is used within the RequestHandler service pipeline, which is built from the
* RequestHandler service configuration. Tapestry IoC is responsible for passing in an
* appropriate Logger instance. Requests for static resources are handled at a higher level, so
* this filter will only be invoked for Tapestry related requests.
* <p/>
* <p/>
* Service builder methods are useful when the implementation is inline as an inner class
* (as here) or require some other kind of special initialization. In most cases,
* use the static bind() method instead.
* <p/>
* <p/>
* If this method was named "build", then the service id would be taken from the
* service interface and would be "RequestFilter". Since Tapestry already defines
* a service named "RequestFilter" we use an explicit service id that we can reference
* inside the contribution method.
*/
public RequestFilter buildTimingFilter(final Logger log)
{
return new RequestFilter()
{
public boolean service(Request request, Response response, RequestHandler handler)
throws IOException
{
long startTime = System.currentTimeMillis();
try
{
// The responsibility of a filter is to invoke the corresponding method
// in the handler. When you chain multiple filters together, each filter
// received a handler that is a bridge to the next filter.
return handler.service(request, response);
} finally
{
long elapsed = System.currentTimeMillis() - startTime;
log.info(String.format("Request time: %d ms", elapsed));
}
}
};
}
示例6: decorateRequestGlobals
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
public static RequestGlobals decorateRequestGlobals(final RequestGlobals originalRequestGlobals)
{
HttpServletRequest httpServletRequest = createNiceMock(HttpServletRequest.class);
RequestGlobals requestGlobals = createNiceMock(RequestGlobals.class);
requestGlobals.storeRequestResponse(anyObject(Request.class), anyObject(Response.class));
expectLastCall().andDelegateTo(originalRequestGlobals);
requestGlobals.storeActivePageName(anyObject(String.class));
expectLastCall().andDelegateTo(originalRequestGlobals);
expect(requestGlobals.getRequest()).andDelegateTo(originalRequestGlobals);
expect(requestGlobals.getResponse()).andDelegateTo(originalRequestGlobals);
expect(requestGlobals.getHTTPServletRequest()).andReturn(httpServletRequest);
replay(requestGlobals, httpServletRequest);
return requestGlobals;
}
示例7: SubdomainPageLinkTransformer
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
/**
* Single constructor of this class.
*
* @param tagController a {@link TagController}.
* @param hostname the hostname used by the server running Eloquentia.
*/
public SubdomainPageLinkTransformer(
final Request request,
final TagController tagController,
final PageActivationContextService pageActivationContextService,
@Inject @Symbol(SymbolConstants.HOSTNAME) final String hostname) {
assert request != null;
assert tagController != null;
assert hostname != null;
this.request = request;
this.tagController = tagController;
this.pageActivationContextService = pageActivationContextService;
this.hostname = hostname.trim();
this.enabled = this.hostname.length() > 0;
}
示例8: SubdomainTagLinkTransformer
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
/**
* Single constructor of this class.
*
* @param tagController a {@link TagController}.
* @param hostname the hostname used by the server running Eloquentia.
*/
public SubdomainTagLinkTransformer(
final Request request,
final TagController tagController,
@Inject @Symbol(SymbolConstants.HOSTNAME) final String hostname) {
assert request != null;
assert tagController != null;
assert hostname != null;
this.request = request;
this.tagController = tagController;
this.hostname = hostname.trim();
this.enabled = this.hostname.length() > 0;
}
示例9: buildUtf8Filter
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
public RequestFilter buildUtf8Filter(@InjectService("RequestGlobals") final RequestGlobals requestGlobals,
final Logger log) {
return new RequestFilter() {
public boolean service(Request request, Response response, RequestHandler handler) throws IOException {
requestGlobals.getHTTPServletRequest().setCharacterEncoding("UTF-8");
return handler.service(request, response);
}
};
}
示例10: service
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
/**
* Filter interface for the HttpServletRequestHandler pipeline. A filter
* should delegate to the handler. It may perform operations before or after
* invoking the handler, and may modify the request and response passed in to
* the handler.
*
* @param request
* @param response
* @param handler
*
* @return true if the request has been handled, false otherwise
*/
@Override
public boolean service(final Request request, final Response response, final RequestHandler handler)
throws IOException {
{
if (path.equals(request.getPath())) {
String operation = request.getParameter("operation");
switch (operation) {
case "retrieve-alerts":
handleRetrieveAlerts(request, response);
break;
case "dismiss-alerts":
handleDismissAlerts(request, response);
break;
default:
response.sendError(400, "Invalid operation: " + operation);
break;
}
return true;
} else {
return handler.service(request, response);
}
}
}
示例11: buildTimingFilter
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
/**
* This is a service definition, the service will be named "TimingFilter". The interface,
* RequestFilter, is used within the RequestHandler service pipeline, which is built from the
* RequestHandler service configuration. Tapestry IoC is responsible for passing in an
* appropriate Logger instance. Requests for static resources are handled at a higher level, so
* this filter will only be invoked for Tapestry related requests.
*
* <p>
* Service builder methods are useful when the implementation is inline as an inner class
* (as here) or require some other kind of special initialization. In most cases,
* use the static bind() method instead.
*
* <p>
* If this method was named "build", then the service id would be taken from the
* service interface and would be "RequestFilter". Since Tapestry already defines
* a service named "RequestFilter" we use an explicit service id that we can reference
* inside the contribution method.
*/
public RequestFilter buildTimingFilter(final Logger log)
{
return new RequestFilter()
{
public boolean service(Request request, Response response, RequestHandler handler)
throws IOException
{
long startTime = System.currentTimeMillis();
try
{
// The responsibility of a filter is to invoke the corresponding method
// in the handler. When you chain multiple filters together, each filter
// received a handler that is a bridge to the next filter.
return handler.service(request, response);
}
finally
{
long elapsed = System.currentTimeMillis() - startTime;
log.info(String.format("Request time: %d ms", elapsed));
}
}
};
}
示例12: CsrfProtectionFilter
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
/**
* Creates a new filter and injects the required services and configuration parameters.
*
* @param csrfTokenManager .
* @param protectedPagesService .
* @param request .
* @param httpServletRequest .
*/
public CsrfProtectionFilter(
CsrfTokenManager csrfTokenManager,
ProtectedPagesService protectedPagesService,
Request request, HttpServletRequest httpServletRequest)
{
super();
this.csrfTokenManager = csrfTokenManager;
this.protectedPagesService = protectedPagesService;
this.request = request;
this.httpServletRequest = httpServletRequest;
}
示例13: decodeComponentEventRequest
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
@Override
public ComponentEventRequestParameters decodeComponentEventRequest(Request request)
{
ComponentEventRequestParameters requestParameters =
csrfComponentEventLinkTransformer.decodeComponentEventRequest(request);
return requestParameters != null ? requestParameters : delegate.decodeComponentEventRequest(request);
}
示例14: checkToken
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
/**
* This method performs the check of the token. It extracts the current client token from the request and the
* current server-side token by accessing the CsrfTokenProvider instance assigned in this session.
*
* @param request .
* @param httpServletRequest .
* @throws CsrfException when token not there or token does not match
*/
public void checkToken(Request request, HttpServletRequest httpServletRequest)
throws CsrfException
{
String requestParam = request.getParameter(parameterName);
CsrfToken serverToken = tokenRepository.loadToken();
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("SessionToken: " + serverToken + ", ClientToken: " + requestParam);
}
if (serverToken == null || !serverToken.getToken().equals(requestParam))
{
// check if session id changed - if yes Spring Security (or another security framework)
// requested a new session after login
HttpSession session = httpServletRequest.getSession(false);
if (session != null && session.isNew())
{
return;
}
LOGGER.warn("CSRF Attack detected. Server-Token: {} vs. Client-Token: {}",
serverToken, requestParam);
throw new CsrfException("CSRF Attack detected. Invalid client token: " + requestParam);
}
}
示例15: process
import org.apache.tapestry5.services.Request; //导入依赖的package包/类
public Request process(Request request) {
final String serverName = request.getServerName();
final String path = request.getPath();
// this rewriting should only happen when a request to
// tagName + '.' + hostname is done.
if (path.equals("/") && serverName.endsWith(hostname)) {
final String tagName = serverName.substring(0, serverName.indexOf('.'));
final Tag tag = tagController.findByName(tagName);
// the tag must exist and have it marked as subdomain for the rewriting to happen.
if (tag != null && tag.isSubdomain()) {
if (tag.isBlog()) {
request = new SimpleRequestWrapper(request, hostname, "/tag/" + tagName);
}
else {
request = new SimpleRequestWrapper(request, hostname, "/" + tagName);
}
}
}
return request;
}