Search in sources :

Example 1 with Request

use of org.apache.tapestry5.http.services.Request in project flowlogix by flowlogix.

the class TapestryRemoteServiceServlet method doGetSerializationPolicy.

@Override
protected SerializationPolicy doGetSerializationPolicy(HttpServletRequest request, String moduleBaseURL, String strongName) {
    final SymbolSource symbolSource = ExternalServiceUtil.getTapestryService(getServletContext(), SymbolSource.class);
    final String prefix = symbolSource.valueForSymbol(SymbolConstants.ASSET_PATH_PREFIX);
    final AssetPathProcessor pathProcessor = new AssetPathProcessor(prefix);
    return super.doGetSerializationPolicy(request, pathProcessor.removeAssetPathPart(moduleBaseURL), strongName);
}
Also used : SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) AssetPathProcessor(com.flowlogix.web.services.internal.AssetPathProcessor)

Example 2 with Request

use of org.apache.tapestry5.http.services.Request in project flowlogix by flowlogix.

the class GwtCachingFilter method service.

@Override
public boolean service(HttpServletRequest request, HttpServletResponse response, HttpServletRequestHandler chainHandler) throws IOException {
    String path = request.getServletPath();
    boolean neverExpire = checkConfig(path, response);
    if (neverExpire == false) {
        return chainHandler.service(request, response);
    }
    log.finer("GwtCachingFilter: Processing " + path);
    Request rq = new RequestImpl(request, applicationCharset, sessionFactory);
    Response rsp = new ResponseImpl(request, response);
    rg.storeRequestResponse(rq, rsp);
    rsp.setDateHeader("Expires", new Date().getTime() + InternalConstants.TEN_YEARS);
    try {
        return carh.handleAssetRequest(rq, rsp, pathProcessor.removeAssetPathPart(path));
    } catch (Exception e) {
        return chainHandler.service(request, response);
    }
}
Also used : Response(org.apache.tapestry5.services.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.apache.tapestry5.services.Request) RequestImpl(org.apache.tapestry5.internal.services.RequestImpl) ResponseImpl(org.apache.tapestry5.internal.services.ResponseImpl) Date(java.util.Date) IOException(java.io.IOException)

Example 3 with Request

use of org.apache.tapestry5.http.services.Request in project tapestry-5 by apache.

the class ResourceStreamerImpl method streamResource.

public boolean streamResource(Resource resource, StreamableResource streamable, String providedChecksum, Set<Options> options) throws IOException {
    assert streamable != null;
    assert providedChecksum != null;
    assert options != null;
    String actualChecksum = streamable.getChecksum();
    if (providedChecksum.length() > 0 && !providedChecksum.equals(actualChecksum)) {
        // TAP5-2185: Trying to find the wrongly-checksummed resource in the classpath and context,
        // so we can create an Asset with the correct checksum and redirect to it.
        Asset asset = null;
        if (resource != null) {
            asset = findAssetInsideWebapp(resource);
        }
        if (asset != null) {
            response.sendRedirect(asset.toClientURL());
            return true;
        }
        return false;
    }
    // ETag should be surrounded with quotes.
    String token = QUOTE + actualChecksum + QUOTE;
    // Even when sending a 304, we want the ETag associated with the request.
    // In most cases (except JavaScript modules), the checksum is also embedded into the URL.
    // However, E-Tags are also useful for enabling caching inside intermediate servers, CDNs, etc.
    response.setHeader("ETag", token);
    // If the client can send the correct ETag token, then its cache already contains the correct
    // content.
    String providedToken = request.getHeader("If-None-Match");
    if (token.equals(providedToken)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return true;
    }
    long lastModified = streamable.getLastModified();
    long ifModifiedSince;
    try {
        ifModifiedSince = request.getDateHeader(IF_MODIFIED_SINCE_HEADER);
    } catch (IllegalArgumentException ex) {
        // Simulate the header being missing if it is poorly formatted.
        ifModifiedSince = -1;
    }
    if (ifModifiedSince > 0 && ifModifiedSince >= lastModified) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return true;
    }
    // Prevent the upstream code from compressing when we don't want to.
    response.disableCompression();
    response.setDateHeader("Last-Modified", lastModified);
    if (productionMode && !options.contains(Options.OMIT_EXPIRATION)) {
        // Starting in 5.4, this is a lot less necessary; any change to a Resource will result
        // in a new asset URL with the changed checksum incorporated into the URL.
        response.setDateHeader("Expires", lastModified + InternalConstants.TEN_YEARS);
    }
    // mostly result in quick SC_NOT_MODIFIED responses.
    if (options.contains(Options.OMIT_EXPIRATION)) {
        response.setHeader("Cache-Control", omitExpirationCacheControlHeader);
    }
    if (streamable.getCompression() == CompressionStatus.COMPRESSED) {
        response.setHeader(TapestryHttpInternalConstants.CONTENT_ENCODING_HEADER, TapestryHttpInternalConstants.GZIP_CONTENT_ENCODING);
    }
    ResponseCustomizer responseCustomizer = streamable.getResponseCustomizer();
    if (responseCustomizer != null) {
        responseCustomizer.customizeResponse(streamable, response);
    }
    if (!request.getMethod().equals("HEAD")) {
        response.setContentLength(streamable.getSize());
        OutputStream os = response.getOutputStream(streamable.getContentType().toString());
        streamable.streamTo(os);
        os.close();
    }
    return true;
}
Also used : OutputStream(java.io.OutputStream) Asset(org.apache.tapestry5.Asset)

Example 4 with Request

use of org.apache.tapestry5.http.services.Request in project tapestry-5 by apache.

the class RequestSecurityManagerImpl method checkForInsecurePageRenderRequest.

public boolean checkForInsecurePageRenderRequest(PageRenderRequestParameters parameters) throws IOException {
    if (!needsRedirect(parameters.getLogicalPageName()))
        return false;
    // Page is secure but request is not, so redirect.
    Link link = componentEventLinkEncoder.createPageRenderLink(parameters);
    response.sendRedirect(link);
    return true;
}
Also used : Link(org.apache.tapestry5.http.Link)

Example 5 with Request

use of org.apache.tapestry5.http.services.Request in project tapestry-5 by apache.

the class ComponentEventDispatcherTest method request_for_whitelist_only_page_from_client_not_on_whitelist.

@Test
public void request_for_whitelist_only_page_from_client_not_on_whitelist() throws IOException {
    String requestPath = "/foo/MyPage:anevent";
    String localeName = "foo";
    String containerPageName = "foo/MyPage";
    ComponentRequestHandler handler = mockComponentRequestHandler();
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter localizationSetter = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = newMock(MetaDataLocator.class);
    ClientWhitelist whitelist = newMock(ClientWhitelist.class);
    train_getPath(request, requestPath);
    expect(localizationSetter.isSupportedLocaleName("foo")).andReturn(false);
    train_isPageName(resolver, containerPageName, true);
    train_canonicalizePageName(resolver, containerPageName, containerPageName);
    expect(metaDataLocator.findMeta(MetaDataConstants.WHITELIST_ONLY_PAGE, containerPageName, boolean.class)).andReturn(true);
    expect(whitelist.isClientRequestOnWhitelist()).andReturn(false);
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(handler, new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, localizationSetter, response, null, null, null, true, null, "", metaDataLocator, whitelist));
    assertFalse(dispatcher.dispatch(request, response));
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) ClientWhitelist(org.apache.tapestry5.services.security.ClientWhitelist) Request(org.apache.tapestry5.http.services.Request) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)86 Request (org.apache.tapestry5.http.services.Request)83 Response (org.apache.tapestry5.http.services.Response)25 HttpServletRequest (javax.servlet.http.HttpServletRequest)19 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)19 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)18 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)17 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)15 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 Session (org.apache.tapestry5.http.services.Session)14 Link (org.apache.tapestry5.http.Link)12 RequestImpl (org.apache.tapestry5.http.internal.services.RequestImpl)11 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)9 Context (org.apache.tapestry5.http.services.Context)8 RequestFilter (org.apache.tapestry5.http.services.RequestFilter)8 RequestHandler (org.apache.tapestry5.http.services.RequestHandler)8 IOException (java.io.IOException)7 BaseURLSourceImpl (org.apache.tapestry5.http.internal.services.BaseURLSourceImpl)7 BaseURLSource (org.apache.tapestry5.http.services.BaseURLSource)7 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)7