Search in sources :

Example 6 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class UndertowPushBuilder method push.

@Override
public void push(HttpServletRequest httpServletRequest, PushItem... pushItems) {
    Request request = RequestCycle.get().getRequest();
    HttpServletRequest httpRequest = (HttpServletRequest) request.getContainerRequest();
    io.undertow.servlet.spec.HttpServletRequestImpl undertowRequest = (io.undertow.servlet.spec.HttpServletRequestImpl) httpRequest;
    // Added explicit cast here to ensure this is the implementation of undertow
    io.undertow.servlet.spec.PushBuilderImpl pushBuilder = (io.undertow.servlet.spec.PushBuilderImpl) undertowRequest.getPushBuilder();
    if (pushBuilder != null) {
        for (PushItem pushItem : pushItems) {
            pushBuilder.path(pushItem.getUrl());
            pushItem.getHeaders().entrySet().stream().forEach(pushHeader -> {
                String key = pushHeader.getKey();
                PushItemHeaderValue value = pushHeader.getValue();
                if (value.getOperation() == HeaderOperation.ADD) {
                    pushBuilder.addHeader(key, value.getValue());
                } else {
                    pushBuilder.setHeader(key, value.getValue());
                }
            });
            pushBuilder.push();
        }
    } else {
        LOG.warn("Attempted to use HTTP2 Push but it is not supported for the current request: {}!", httpRequest);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.apache.wicket.request.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest)

Example 7 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class Tomcat85PushBuilder method push.

@Override
public void push(HttpServletRequest httpServletRequest, PushItem... pushItems) {
    Request request = RequestCycle.get().getRequest();
    HttpServletRequest httpRequest = (HttpServletRequest) request.getContainerRequest();
    org.apache.catalina.connector.RequestFacade tomcatRequest = (org.apache.catalina.connector.RequestFacade) httpRequest;
    ApplicationPushBuilder pushBuilder = (ApplicationPushBuilder) tomcatRequest.newPushBuilder();
    if (pushBuilder != null) {
        for (PushItem pushItem : pushItems) {
            pushBuilder.path(pushItem.getUrl());
            pushItem.getHeaders().entrySet().stream().forEach(pushHeader -> {
                String key = pushHeader.getKey();
                PushItemHeaderValue value = pushHeader.getValue();
                if (value.getOperation() == HeaderOperation.ADD) {
                    pushBuilder.addHeader(key, value.getValue());
                } else {
                    pushBuilder.setHeader(key, value.getValue());
                }
            });
            pushBuilder.push();
        }
    } else {
        LOG.warn("Attempted to use HTTP2 Push but it is not supported for the current request: {}!", httpRequest);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ApplicationPushBuilder(org.apache.catalina.core.ApplicationPushBuilder) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.apache.wicket.request.Request)

Example 8 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class Servlet4PushBuilder method push.

@Override
public void push(HttpServletRequest httpServletRequest, PushItem... pushItems) {
    Request request = RequestCycle.get().getRequest();
    HttpServletRequest httpRequest = (HttpServletRequest) request.getContainerRequest();
    javax.servlet.http.PushBuilder pushBuilder = httpRequest.newPushBuilder();
    if (pushBuilder != null) {
        for (PushItem pushItem : pushItems) {
            pushBuilder.path(pushItem.getUrl());
            pushItem.getHeaders().entrySet().stream().forEach(pushHeader -> {
                String key = pushHeader.getKey();
                PushItemHeaderValue value = pushHeader.getValue();
                if (value.getOperation() == HeaderOperation.ADD) {
                    pushBuilder.addHeader(key, value.getValue());
                } else {
                    pushBuilder.setHeader(key, value.getValue());
                }
            });
            pushBuilder.push();
        }
    } else {
        LOG.warn("Attempted to use HTTP2 Push but it is not supported for the current request: {}!", httpRequest);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.apache.wicket.request.Request)

Example 9 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class WebPageRenderer method isAjax.

protected boolean isAjax(RequestCycle requestCycle) {
    boolean isAjax = false;
    Request request = requestCycle.getRequest();
    if (request instanceof WebRequest) {
        WebRequest webRequest = (WebRequest) request;
        isAjax = webRequest.isAjax();
    }
    return isAjax;
}
Also used : WebRequest(org.apache.wicket.request.http.WebRequest) WebRequest(org.apache.wicket.request.http.WebRequest) Request(org.apache.wicket.request.Request)

Example 10 with Request

use of org.apache.wicket.request.Request in project wicket by apache.

the class CustomHomeMapper method mapRequest.

/**
 * Removes the leading segment if it a valid Locale
 *
 * @see org.apache.wicket.core.request.mapper.HomePageMapper#mapRequest(org.apache.wicket.request.Request)
 */
@Override
public IRequestHandler mapRequest(Request request) {
    IRequestHandler requestHandler = null;
    Url url = request.getUrl();
    List<String> segments = url.getSegments();
    if (segments.size() == 1) {
        String localeAsString = segments.get(0);
        Locale locale = LocaleHelper.parseLocale(localeAsString);
        if (locale != null) {
            Session.get().setLocale(locale);
            segments.remove(0);
            Request requestWithoutLocale = request.cloneWithUrl(url);
            requestHandler = super.mapRequest(requestWithoutLocale);
        }
    }
    return requestHandler;
}
Also used : Locale(java.util.Locale) IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) Url(org.apache.wicket.request.Url)

Aggregations

Request (org.apache.wicket.request.Request)61 Test (org.junit.Test)28 IRequestHandler (org.apache.wicket.request.IRequestHandler)26 Url (org.apache.wicket.request.Url)23 WebRequest (org.apache.wicket.request.http.WebRequest)9 Response (org.apache.wicket.request.Response)8 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)8 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)6 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 IPageRequestHandler (org.apache.wicket.core.request.handler.IPageRequestHandler)5 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)5 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)5 MockApplication (org.apache.wicket.mock.MockApplication)4 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)4 Session (org.apache.wicket.Session)3 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)3 Attributes (org.apache.wicket.request.resource.IResource.Attributes)3 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)3 UrlAttributes (org.apache.wicket.request.resource.ResourceReference.UrlAttributes)3