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);
}
}
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;
}
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());
}
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));
}
}
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;
}
Aggregations