public IRequestHandler mapRequest(final Request request) { final Url url = this.decryptUrl(request, request.getUrl()); if (url == null) { return this.wrappedMapper.mapRequest(request); } return this.wrappedMapper.mapRequest(request.cloneWithUrl(url)); }
protected void onEvent(AjaxRequestTarget target) { Request request = RequestCycle.get().getRequest(); Overlay overlay = null; String markerParameter = request.getRequestParameters().getParameterValue("marker").toString(); if (markerParameter != null) { OpenLayersMap map = getOpenLayerMap(); for (Overlay ovl : map.getOverlays()) { if (ovl.getId().equals(markerParameter)) { overlay = ovl; break; } } } String markerEvent = request.getRequestParameters().getParameterValue("event").toString(); if (wantEvents) { // Translate from string to type! EventType eventType = EventType.valueOf(markerEvent); onEvent(target, overlay, eventType); } else { onClick(target, overlay); } }
/** * Processes the request. * * @return <code>true</code> if the request resolved to a Wicket request, <code>false</code> * otherwise. */ public boolean processRequest() { try { set(this); listeners.onBeginRequest(this); onBeginRequest(); IRequestHandler handler = resolveRequestHandler(); if (handler != null) { execute(handler); return true; } // Did not find any suitable handler, thus not executing the request log.debug( "No suitable handler found for URL {}, falling back to container to process this request", request.getUrl()); } catch (Exception e) { IRequestHandler handler = handleException(e); if (handler != null) { listeners.onExceptionRequestHandlerResolved(this, handler, e); executeExceptionRequestHandler(handler, getExceptionRetryCount()); listeners.onRequestHandlerExecuted(this, handler); } else { log.error("Error during request processing. URL=" + request.getUrl(), e); } return true; } finally { set(null); } return false; }
@Override public IRequestHandler mapRequest(final Request request) { Url url = decryptUrl(request, request.getUrl()); if (url == null) { return null; } return wrappedMapper.mapRequest(request.cloneWithUrl(url)); }
@Override protected final void respond(AjaxRequestTarget target) { Request request = RequestCycle.get().getRequest(); String newContent = request.getRequestParameters().getParameterValue(PARAM_HTMLCONT).toString(); newContent = onSave(target, newContent); Component component = getComponent(); IModel defaultModel = component.getDefaultModel(); defaultModel.setObject(newContent); target.add(component); }
private Url decryptUrl(final Request request, final Url encryptedUrl) { if (encryptedUrl.getSegments().isEmpty()) { return encryptedUrl; } List<String> encryptedSegments = encryptedUrl.getSegments(); if (encryptedSegments.size() < 1) { return null; } Url url = new Url(request.getCharset()); try { String encryptedUrlString = encryptedSegments.get(0); if (Strings.isEmpty(encryptedUrlString)) { return null; } String decryptedUrl = getCrypt().decryptUrlSafe(encryptedUrlString); if (decryptedUrl == null) { return null; } Url originalUrl = Url.parse(decryptedUrl, request.getCharset()); int originalNumberOfSegments = originalUrl.getSegments().size(); int encryptedNumberOfSegments = encryptedUrl.getSegments().size(); HashedSegmentGenerator generator = new HashedSegmentGenerator(encryptedUrlString); int segNo = 1; for (; segNo < encryptedNumberOfSegments; segNo++) { if (segNo > originalNumberOfSegments) { break; } String next = generator.next(); String encryptedSegment = encryptedSegments.get(segNo); if (!next.equals(encryptedSegment)) { break; } // unmodified segment url.getSegments().add(originalUrl.getSegments().get(segNo - 1)); } for (; segNo < encryptedNumberOfSegments; segNo++) { // modified or additional segment url.getSegments().add(encryptedUrl.getSegments().get(segNo)); } url.getQueryParameters().addAll(originalUrl.getQueryParameters()); } catch (Exception e) { log.error("Error decrypting URL", e); url = null; } return url; }
public final void onRequest() { RequestCycle requestCycle = getComponent().getRequestCycle(); Request request = requestCycle.getRequest(); IRequestParameters parameters = request.getRequestParameters(); StringValue input = parameters.getParameterValue("term"); final Iterable<T> choices = getChoices(input.toString("")); String jsonArray = createJson(choices); requestCycle.scheduleRequestHandlerAfterCurrent( new TextRequestHandler("application/json", "UTF-8", jsonArray)); }
@Override public void onResourceRequested() { // this is the callback that retrieves matching choices used to populate the dropdown Request request = getRequestCycle().getRequest(); IRequestParameters params = request.getRequestParameters(); // retrieve choices matching the search term String term = params.getParameterValue("term").toOptionalString(); int page = params.getParameterValue("page").toInt(1); // select2 uses 1-based paging, but in wicket world we are used to // 0-based page -= 1; Response<T> response = new Response<T>(); provider.query(term, page, response); // jsonize and write out the choices to the response WebResponse webResponse = (WebResponse) getRequestCycle().getResponse(); webResponse.setContentType("application/json"); OutputStreamWriter out = new OutputStreamWriter(webResponse.getOutputStream(), getRequest().getCharset()); JSONWriter json = new JSONWriter(out); try { json.object(); json.key("results").array(); for (T item : response) { json.object(); provider.toJson(item, json); json.endObject(); } json.endArray(); json.key("more").value(response.getHasMore()).endObject(); } catch (JSONException e) { throw new RuntimeException("Could not write Json response", e); } try { out.flush(); } catch (IOException e) { throw new RuntimeException("Could not write Json to servlet response", e); } }
/** * @see * org.apache.wicket.request.mapper.parameter.IPageParametersEncoder#decodePageParameters(org.apache.wicket.request.Request) */ public PageParameters decodePageParameters(final Request request) { PageParameters parameters = new PageParameters(); int i = 0; for (String s : request.getUrl().getSegments()) { parameters.set(i, s); ++i; } for (QueryParameter p : request.getUrl().getQueryParameters()) { parameters.add(p.getName(), p.getValue()); } return parameters.isEmpty() ? null : parameters; }
@Override public int getCompatibilityScore(Request request) { if (request.getUrl().getPath().equals(path)) { return Integer.MAX_VALUE; } return 0; }
/** * @see * org.apache.wicket.core.request.mapper.AbstractBookmarkableMapper#parseRequest(org.apache.wicket.request.Request) */ @Override protected UrlInfo parseRequest(Request request) { Url url = request.getUrl(); if (url.getSegments().size() >= 1) { // try to extract page and component information from URL PageComponentInfo info = getPageComponentInfo(url); // load the page class String className = url.getSegments().get(0); if (isValidClassName(className) == false) { return null; } className = transformFromUrl(className); String fullyQualifiedClassName = packageName.getName() + '.' + className; Class<? extends IRequestablePage> pageClass = getPageClass(fullyQualifiedClassName); if (pageClass != null && Modifier.isAbstract(pageClass.getModifiers()) == false && IRequestablePage.class.isAssignableFrom(pageClass)) { // extract the PageParameters from URL if there are any PageParameters pageParameters = extractPageParameters(request, 1, pageParametersEncoder); return new UrlInfo(info, pageClass, pageParameters); } } return null; }
@Override public IRequestHandler mapRequest(Request request) { if (request.getUrl().getPath().equals(path)) { return new RenderPageRequestHandler(new DummyPanelPageProvider(loader)); } return null; }
@Override public int getCompatibilityScore(Request request) { if (isInternalWicket(request)) { return 0; } // bluff we can parse all segments - makes sure we run first return request.getUrl().getSegments().size(); }
@Override public int getCompatibilityScore(Request request) { if (urlStartsWith(request.getUrl(), mountSegments)) { return mountSegments.length; } else { return 0; } }
private Url decryptUrl(final Request request, final Url encryptedUrl) { if (encryptedUrl.getSegments().isEmpty()) { return encryptedUrl; } final List<String> encryptedSegments = (List<String>) encryptedUrl.getSegments(); if (encryptedSegments.size() < 1) { return null; } Url url = new Url(request.getCharset()); try { final String encryptedUrlString = (String) encryptedSegments.get(0); if (Strings.isEmpty((CharSequence) encryptedUrlString)) { return null; } final String decryptedUrl = this.getCrypt().decryptUrlSafe(encryptedUrlString); if (decryptedUrl == null) { return null; } final Url originalUrl = Url.parse(decryptedUrl, request.getCharset()); final int originalNumberOfSegments = originalUrl.getSegments().size(); final int encryptedNumberOfSegments = encryptedUrl.getSegments().size(); final HashedSegmentGenerator generator = new HashedSegmentGenerator(encryptedUrlString); int segNo; for (segNo = 1; segNo < encryptedNumberOfSegments; ++segNo) { if (segNo > originalNumberOfSegments) { break; } final String next = generator.next(); final String encryptedSegment = (String) encryptedSegments.get(segNo); if (!next.equals(encryptedSegment)) { break; } url.getSegments().add(originalUrl.getSegments().get(segNo - 1)); } while (segNo < encryptedNumberOfSegments) { url.getSegments().add(encryptedUrl.getSegments().get(segNo)); ++segNo; } url.getQueryParameters().addAll(originalUrl.getQueryParameters()); } catch (Exception e) { CryptoMapper.log.error("Error decrypting URL", e); url = null; } return url; }
private Url encodeSharedResourceUrl(Url url) { if (url != null) { Request request = RequestCycle.get().getRequest(); StringBuilder urlBuilder = new StringBuilder(); urlBuilder.append(request.getContextPath()); urlBuilder.append(request.getFilterPath()); urlBuilder.append(PortletFilter.SHARED_RESOURCE_URL_PORTLET_WINDOW_ID_PREFIX); urlBuilder.append( Base64.encodeBase64URLSafeString(ThreadPortletContext.getWindowID().getBytes())); urlBuilder.append('/'); urlBuilder.append(url.toString()); url = Url.parse(urlBuilder.toString()); } return url; }
private boolean isInternalWicket(Request request) { Url url = request.getUrl(); if (url.getSegments().size() > 0) { if (url.getSegments().get(0).equals((Application.get().getMapperContext().getNamespace()))) { // starts with wicket namespace - is an internal wicket url return true; } } return false; }
@Override public Session newSession(final Request request, final Response response) { if (!DEMO_MODE_USING_CREDENTIALS_AS_QUERYARGS) { return super.newSession(request, response); } // else demo mode final AuthenticatedWebSessionForIsis s = (AuthenticatedWebSessionForIsis) super.newSession(request, response); IRequestParameters requestParameters = request.getRequestParameters(); final org.apache.wicket.util.string.StringValue user = requestParameters.getParameterValue("user"); final org.apache.wicket.util.string.StringValue password = requestParameters.getParameterValue("pass"); s.signIn(user.toString(), password.toString()); return s; }
public static String getWicketAppPath() { Request request = RequestCycle.get().getRequest(); return request.getContextPath() + request.getFilterPath() + "/"; }
@Override public IRequestHandler mapRequest(Request request) { final Url url = request.getClientUrl(); if (isInternalWicket(request)) { return null; } // TODO: This is just a quick fix if (url.getSegments().size() > 0) { if (url.getSegments().get(0).equals("webdav") || url.getSegments().get(0).equals("jcrwebdav")) { return null; } } Path path = new Path("/" + url.getPath()); // root path handling if (path.isRoot()) { if (handleHomePage) { final BrixNode node = getNodeForUriPath(path); return SitePlugin.get() .getNodePluginForNode(node) .respond( new BrixNodeModel(node), new BrixPageParameters(request.getRequestParameters())); } else { return null; } } IRequestHandler handler = null; try { while (handler == null) { final BrixNode node = getNodeForUriPath(path); if (node != null) { SiteNodePlugin plugin = SitePlugin.get().getNodePluginForNode(node); if (plugin instanceof AbstractSitePagePlugin) { handler = SitePlugin.get() .getNodePluginForNode(node) .respond(new BrixNodeModel(node), createBrixPageParams(request.getUrl(), path)); } else { handler = SitePlugin.get() .getNodePluginForNode(node) .respond( new BrixNodeModel(node), new BrixPageParameters(request.getRequestParameters())); } } if (handler != null || path.toString().equals(".")) { break; } path = path.parent(); if (path.isRoot()) { break; } } } catch (JcrException e) { logger.warn("JcrException caught due to incorrect url", e); } final PageComponentInfo info = getPageComponentInfo(request.getUrl()); if (info != null && info.getPageInfo().getPageId() != null) { Integer renderCount = info.getComponentInfo() != null ? info.getComponentInfo().getRenderCount() : null; if (info.getComponentInfo() == null) { PageProvider provider; if (handler instanceof BrixNodePageRequestHandler) { provider = new PageProvider(info.getPageInfo().getPageId(), BrixNodeWebPage.class, renderCount); BrixNodePageRequestHandler brixNodePageRequestHandler = (BrixNodePageRequestHandler) handler; final IPageProvider pageProviderAdapter = brixNodePageRequestHandler.getPageProvider(); provider.setPageSource( new IPageSource() { @Override public IRequestablePage getPageInstance(int pageId) { IRequestablePage page = null; Integer existingPageId = pageProviderAdapter.getPageId(); if (existingPageId != null && pageId == existingPageId) { page = pageProviderAdapter.getPageInstance(); } return page; } @Override public IRequestablePage newPageInstance( Class<? extends IRequestablePage> pageClass, PageParameters pageParameters) { IRequestablePage page = pageProviderAdapter.getPageInstance(); page.getPageParameters().set(info.toString(), ""); return page; } }); } else { provider = new PageProvider(info.getPageInfo().getPageId(), renderCount); provider.setPageSource(getContext()); } // render page return new RenderPageRequestHandler(provider); } else { ComponentInfo componentInfo = info.getComponentInfo(); PageAndComponentProvider provider = new PageAndComponentProvider( info.getPageInfo().getPageId(), renderCount, componentInfo.getComponentPath()); provider.setPageSource(getContext()); // listener interface RequestListenerInterface listenerInterface = requestListenerInterfaceFromString(componentInfo.getListenerInterface()); return new ListenerInterfaceRequestHandler( provider, listenerInterface, componentInfo.getBehaviorId()); } } return handler; }
public static HttpServletRequest getHttpServletRequest(final Request request) { return (HttpServletRequest) request.getContainerRequest(); }