Search in sources :

Example 51 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class AbstractResource method setRequestRangeMetaData.

protected void setRequestRangeMetaData(WebRequest webRequest) {
    String rangeHeader = webRequest.getHeader("range");
    // The content range header is only be calculated if a range is given
    if (!Strings.isEmpty(rangeHeader) && rangeHeader.contains(ContentRangeType.BYTES.getTypeName())) {
        // fixing white spaces
        rangeHeader = rangeHeader.replaceAll(" ", "");
        String range = rangeHeader.substring(rangeHeader.indexOf('=') + 1, rangeHeader.length());
        // support only the first range (WICKET-5995)
        final int idxOfComma = range.indexOf(',');
        String firstRange = idxOfComma > -1 ? range.substring(0, idxOfComma) : range;
        String[] rangeParts = Strings.split(firstRange, '-');
        String startByteString = rangeParts[0];
        String endByteString = rangeParts[1];
        long startbyte = !Strings.isEmpty(startByteString) ? Long.parseLong(startByteString) : 0;
        long endbyte = !Strings.isEmpty(endByteString) ? Long.parseLong(endByteString) : -1;
        // Make the content range information available for the whole request cycle
        RequestCycle requestCycle = RequestCycle.get();
        requestCycle.setMetaData(CONTENT_RANGE_STARTBYTE, startbyte);
        requestCycle.setMetaData(CONTENT_RANGE_ENDBYTE, endbyte);
    }
}
Also used : RequestCycle(org.apache.wicket.request.cycle.RequestCycle)

Example 52 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class Application method createRequestCycle.

/**
 * @param request
 * @param response
 * @return request cycle
 */
public final RequestCycle createRequestCycle(final Request request, final Response response) {
    RequestCycleContext context = new RequestCycleContext(request, response, getRootRequestMapper(), getExceptionMapperProvider().get());
    RequestCycle requestCycle = getRequestCycleProvider().apply(context);
    requestCycle.getListeners().add(requestCycleListeners);
    requestCycle.getListeners().add(new IRequestCycleListener() {

        @Override
        public void onDetach(final RequestCycle requestCycle) {
            if (Session.exists()) {
                Session.get().getPageManager().commitRequest();
            }
            if (Application.exists()) {
                IRequestLogger requestLogger = Application.get().getRequestLogger();
                if (requestLogger != null) {
                    requestLogger.requestTime((System.currentTimeMillis() - requestCycle.getStartTime()));
                }
            }
        }
    });
    return requestCycle;
}
Also used : IRequestLogger(org.apache.wicket.protocol.http.IRequestLogger) IRequestCycleListener(org.apache.wicket.request.cycle.IRequestCycleListener) RequestCycleContext(org.apache.wicket.request.cycle.RequestCycleContext) RequestCycle(org.apache.wicket.request.cycle.RequestCycle)

Example 53 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class Application method internalInit.

/**
 * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT OVERRIDE OR CALL.
 *
 * Internal initialization.
 */
protected void internalInit() {
    settingsAccessible = true;
    PageSettings pageSettings = getPageSettings();
    // Install default component resolvers
    pageSettings.addComponentResolver(new HtmlHeaderResolver());
    pageSettings.addComponentResolver(new WicketLinkTagHandler());
    pageSettings.addComponentResolver(new WicketMessageResolver());
    pageSettings.addComponentResolver(new RelativePathPrefixHandler());
    pageSettings.addComponentResolver(new EnclosureHandler());
    pageSettings.addComponentResolver(new InlineEnclosureHandler());
    pageSettings.addComponentResolver(new WicketMessageTagHandler());
    pageSettings.addComponentResolver(new WicketContainerResolver());
    getResourceSettings().getResourceFinders().add(new ClassPathResourceFinder(""));
    // Install button image resource factory
    getResourceSettings().addResourceFactory("buttonFactory", new DefaultButtonImageResourceFactory());
    String applicationKey = getApplicationKey();
    applicationKeyToApplication.put(applicationKey, this);
    converterLocator = newConverterLocator();
    setPageManagerProvider(new DefaultPageManagerProvider(this));
    resourceReferenceRegistry = newResourceReferenceRegistry();
    sharedResources = newSharedResources(resourceReferenceRegistry);
    resourceBundles = newResourceBundles(resourceReferenceRegistry);
    // set up default request mapper
    setRootRequestMapper(new SystemMapper(this));
    pageFactory = newPageFactory();
    requestCycleProvider = (context) -> new RequestCycle(context);
    exceptionMapperProvider = () -> new DefaultExceptionMapper();
    // add a request cycle listener that logs each request for the requestlogger.
    getRequestCycleListeners().add(new RequestLoggerRequestCycleListener());
}
Also used : RelativePathPrefixHandler(org.apache.wicket.markup.parser.filter.RelativePathPrefixHandler) PageSettings(org.apache.wicket.settings.PageSettings) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) HtmlHeaderResolver(org.apache.wicket.markup.resolver.HtmlHeaderResolver) WicketMessageTagHandler(org.apache.wicket.markup.parser.filter.WicketMessageTagHandler) ClassPathResourceFinder(org.apache.wicket.core.util.resource.ClassPathResourceFinder) DefaultButtonImageResourceFactory(org.apache.wicket.markup.html.image.resource.DefaultButtonImageResourceFactory) WicketMessageResolver(org.apache.wicket.markup.resolver.WicketMessageResolver) InlineEnclosureHandler(org.apache.wicket.markup.parser.filter.InlineEnclosureHandler) InlineEnclosureHandler(org.apache.wicket.markup.parser.filter.InlineEnclosureHandler) EnclosureHandler(org.apache.wicket.markup.parser.filter.EnclosureHandler) RequestLoggerRequestCycleListener(org.apache.wicket.protocol.http.RequestLoggerRequestCycleListener) WicketContainerResolver(org.apache.wicket.markup.resolver.WicketContainerResolver) WicketLinkTagHandler(org.apache.wicket.markup.parser.filter.WicketLinkTagHandler)

Example 54 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class ComponentEventSender method breadth.

/**
 * Breadth broadcast
 *
 * @param event
 */
private void breadth(final ComponentEvent<?> event) {
    IEventSink sink = event.getSink();
    boolean targetsApplication = sink instanceof Application;
    boolean targetsSession = targetsApplication || sink instanceof Session;
    boolean targetsCycle = targetsSession || sink instanceof RequestCycle;
    boolean targetsComponent = sink instanceof Component;
    if (!targetsComponent && !targetsCycle) {
        dispatcher.dispatchEvent(sink, event, null);
        return;
    }
    if (targetsApplication) {
        dispatcher.dispatchEvent(source.getApplication(), event, null);
    }
    if (event.isStop()) {
        return;
    }
    if (targetsSession) {
        dispatcher.dispatchEvent(source.getSession(), event, null);
    }
    if (event.isStop()) {
        return;
    }
    if (targetsCycle) {
        dispatcher.dispatchEvent(source.getRequestCycle(), event, null);
    }
    if (event.isStop()) {
        return;
    }
    Component cursor = targetsCycle ? source.getPage() : (Component) sink;
    dispatchToComponent(dispatcher, cursor, event);
    if (event.isStop()) {
        return;
    }
    // reset shallow flag
    event.resetShallow();
    if (cursor instanceof MarkupContainer) {
        ((MarkupContainer) cursor).visitChildren(new ComponentEventVisitor(event, dispatcher));
    }
}
Also used : IEventSink(org.apache.wicket.event.IEventSink) RequestCycle(org.apache.wicket.request.cycle.RequestCycle)

Example 55 with RequestCycle

use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.

the class DefaultExceptionMapper method isProcessingAjaxRequest.

/**
 * @return true if current request is an AJAX request, false otherwise.
 */
protected boolean isProcessingAjaxRequest() {
    RequestCycle rc = RequestCycle.get();
    Request request = rc.getRequest();
    if (request instanceof WebRequest) {
        return ((WebRequest) request).isAjax();
    }
    return false;
}
Also used : WebRequest(org.apache.wicket.request.http.WebRequest) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) WebRequest(org.apache.wicket.request.http.WebRequest) Request(org.apache.wicket.request.Request)

Aggregations

RequestCycle (org.apache.wicket.request.cycle.RequestCycle)69 WebResponse (org.apache.wicket.request.http.WebResponse)14 IRequestHandler (org.apache.wicket.request.IRequestHandler)9 Url (org.apache.wicket.request.Url)9 Response (org.apache.wicket.request.Response)8 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)7 BufferedWebResponse (org.apache.wicket.protocol.http.BufferedWebResponse)7 Page (org.apache.wicket.Page)6 Request (org.apache.wicket.request.Request)6 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)5 IRequestCycle (org.apache.wicket.request.IRequestCycle)5 AbstractRequestCycleListener (org.apache.wicket.request.cycle.AbstractRequestCycleListener)5 Test (org.junit.Test)5 Application (org.apache.wicket.Application)4 IHeaderResponse (org.apache.wicket.markup.head.IHeaderResponse)4 WebClientInfo (org.apache.wicket.protocol.http.request.WebClientInfo)4 WebRequest (org.apache.wicket.request.http.WebRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 WebApplication (org.apache.wicket.protocol.http.WebApplication)3 UrlRenderer (org.apache.wicket.request.UrlRenderer)3