use of org.apache.wicket.request.mapper.parameter.PageParametersEncoder in project wicket by apache.
the class PushHeaderItem method push.
/**
* Creates a URL and pushes the resource to the client - this is only supported if http2 is
* enabled
*
* @param pushItems
* a list of items to be pushed to the client
* @return the current push header item
*/
@SuppressWarnings("unchecked")
public PushHeaderItem push(List<PushItem> pushItems) {
RequestCycle requestCycle = RequestCycle.get();
if (isHttp2(getContainerRequest(requestCycle.getRequest())))
for (PushItem pushItem : pushItems) {
Object object = pushItem.getObject();
PageParameters parameters = pushItem.getPageParameters();
if (object == null) {
throw new WicketRuntimeException("Please provide an object to the items to be pushed, so that the url can be created for the given resource.");
}
CharSequence url = null;
if (object instanceof ResourceReference) {
url = requestCycle.urlFor((ResourceReference) object, parameters);
} else if (Page.class.isAssignableFrom(object.getClass())) {
url = requestCycle.urlFor((Class<? extends Page>) object, parameters);
} else if (object instanceof IRequestHandler) {
url = requestCycle.urlFor((IRequestHandler) object);
} else if (pushItem.getUrl() != null) {
url = pushItem.getUrl();
} else {
Url encoded = new PageParametersEncoder().encodePageParameters(parameters);
String queryString = encoded.getQueryString();
url = object.toString() + (queryString != null ? "?" + queryString : "");
}
if (url.toString().equals(".")) {
url = "/";
} else if (url.toString().startsWith(".")) {
url = url.toString().substring(1);
}
// The context path and the filter have to be applied to the URL, because otherwise
// the resource is not pushed correctly
StringBuilder partialUrl = new StringBuilder();
String contextPath = WebApplication.get().getServletContext().getContextPath();
partialUrl.append(contextPath);
if (!"/".equals(contextPath)) {
partialUrl.append('/');
}
String filterPath = WebApplication.get().getWicketFilter().getFilterPath();
if ("/".equals(filterPath)) {
filterPath = "";
} else if (filterPath.endsWith("/")) {
filterPath = filterPath.substring(0, filterPath.length() - 1);
}
partialUrl.append(filterPath);
partialUrl.append(url.toString());
// Set the url the resource is going to be pushed with
pushItem.setUrl(partialUrl.toString());
// Apply the push item to be used during the push process
this.pushItems.add(pushItem);
}
return this;
}
use of org.apache.wicket.request.mapper.parameter.PageParametersEncoder in project midpoint by Evolveum.
the class MidPointApplication method init.
@Override
public void init() {
super.init();
getCspSettings().blocking().disabled();
getJavaScriptLibrarySettings().setJQueryReference(new PackageResourceReference(MidPointApplication.class, // todo no jquery.js is found
"../../../../../webjars/AdminLTE/2.4.18/bower_components/jquery/dist/jquery.min.js"));
getComponentInstantiationListeners().add(new SpringComponentInjector(this, applicationContext, true));
systemConfigurationChangeDispatcher.registerListener(new DeploymentInformationChangeListener(this));
SystemConfigurationType config = getSystemConfigurationIfAvailable();
if (config != null) {
deploymentInfo = config.getDeploymentInformation();
}
ResourceSettings resourceSettings = getResourceSettings();
resourceSettings.setParentFolderPlaceholder("$-$");
resourceSettings.setHeaderItemComparator(new PriorityFirstComparator(true));
SecurePackageResourceGuard guard = (SecurePackageResourceGuard) resourceSettings.getPackageResourceGuard();
guard.addPattern("+*.woff2");
List<IStringResourceLoader> resourceLoaders = resourceSettings.getStringResourceLoaders();
resourceLoaders.add(0, new MidPointStringResourceLoader(localizationService));
IResourceStreamLocator locator = new CachingResourceStreamLocator(new MidPointResourceStreamLocator(resourceSettings.getResourceFinders()));
resourceSettings.setResourceStreamLocator(locator);
resourceSettings.setThrowExceptionOnMissingResource(false);
getMarkupSettings().setStripWicketTags(true);
getMarkupSettings().setStripComments(true);
if (RuntimeConfigurationType.DEVELOPMENT.equals(getConfigurationType())) {
getDebugSettings().setAjaxDebugModeEnabled(true);
getDebugSettings().setDevelopmentUtilitiesEnabled(true);
initializeDevelopmentSerializers();
mount(new MountedMapper("/inspector", InspectorPage.class, new PageParametersEncoder()));
mount(new MountedMapper("/liveSession", LiveSessionsPage.class, new PageParametersEncoder()));
mount(new MountedMapper("/pageStore", PageStorePage.class, new PageParametersEncoder()));
}
// pretty url for resources (e.g. images)
mountFiles(ImgResources.BASE_PATH, ImgResources.class);
// exception handling an error pages
ApplicationSettings appSettings = getApplicationSettings();
appSettings.setAccessDeniedPage(PageError401.class);
appSettings.setInternalErrorPage(PageError.class);
appSettings.setPageExpiredErrorPage(PageError.class);
mount(new MountedMapper(MOUNT_INTERNAL_SERVER_ERROR, PageError.class, new PageParametersEncoder()));
mount(new MountedMapper(MOUNT_UNAUTHORIZED_ERROR, PageError401.class, new PageParametersEncoder()));
mount(new MountedMapper(MOUNT_FORBIDEN_ERROR, PageError403.class, new PageParametersEncoder()));
mount(new MountedMapper(MOUNT_NOT_FOUND_ERROR, PageError404.class, new PageParametersEncoder()));
mount(new MountedMapper(MOUNT_GONE_ERROR, PageError410.class, new PageParametersEncoder()));
getRequestCycleListeners().add(new LoggingRequestCycleListener(this));
getAjaxRequestTargetListeners().add(new AjaxRequestTarget.IListener() {
@Override
public void updateAjaxAttributes(AbstractDefaultAjaxBehavior behavior, AjaxRequestAttributes attributes) {
// check whether behavior will use POST method, if not then don't put CSRF token there
if (!isPostMethodTypeBehavior(behavior, attributes)) {
return;
}
CsrfToken csrfToken = SecurityUtils.getCsrfToken();
if (csrfToken == null) {
return;
}
String parameterName = csrfToken.getParameterName();
String value = csrfToken.getToken();
attributes.getExtraParameters().put(parameterName, value);
}
});
getSessionListeners().add((ISessionListener) asyncWebProcessManager);
// descriptor loader, used for customization
new PageMounter().loadData(this);
descriptorLoader.loadData();
if (applicationContext != null) {
Map<String, MidPointApplicationConfiguration> map = applicationContext.getBeansOfType(MidPointApplicationConfiguration.class);
if (map != null) {
map.forEach((key, value) -> value.init(this));
}
}
// for schrodinger selenide library
initializeSchrodinger();
ServletContext servletContext = getServletContext();
if (servletContext != null) {
taskManager.setWebContextPath(servletContext.getContextPath());
}
}
Aggregations