/** * @return a servlet's URL from the request. * */ public static String getServletLocation(final HttpServletRequest request) { return buildContextLocation(request, request.getServletPath()); }
/** * Switches between getRequestLocationIncludingQueryParameter and * getRequestLocationIncludingParameter based on the * consumeFORMURLEncodedBody flag. */ public static String getRequestLocationIncludingParameter(final HttpServletRequest request, boolean consumeFORMURLEncodedBody) { if (!consumeFORMURLEncodedBody || "GET".equals(request.getMethod())) { return getRequestLocationIncludingQueryParameter(request); } if (mayContainRequestParameter(request)) { StringBuilder currentRequestLocation = new StringBuilder(getRequestLocation(request)); appendRequestParameter(currentRequestLocation, request); return currentRequestLocation.toString(); } return getRequestLocationIncludingQueryParameter(request); }
/** * Appends all parameters from the request (also HTTP POST * parameters) to the request location. */ public static String getRequestLocationIncludingParameter(final HttpServletRequest request) { return getRequestLocationIncludingParameter(request, true); }
/** * Initiates redirect based on the length of the redirection URL. * Chooses between location header redirect or form POST redirect. */ public static void sendRedirect(String redirectUrl, HttpServletResponse response) { // max length of url in ie is 2.083 if (redirectUrl.length() > 2083) { sendFormPostRedirect(redirectUrl, response); return; } sendLocationHeaderRedirect(redirectUrl, response); }
String baseUrl = ServletUtils.getContextLocation(request); String facadeUrl = baseUrl + facadeServletPath + "/" + facade.getFacadeNameWithPathInfo(); ServletUtils.sendRedirect(returnUrl.toString(), response);
public EnforcementServiceRequest getInstance(HttpServletRequest servletRequest) { String servletUrl = ServletUtils.getServletLocation(servletRequest); String servletPath = servletRequest.getServletPath(); String pathInfo = servletRequest.getPathInfo(); if (targetPathPatternMappingService != null) { String trimmedPathInfo = servletPath.substring(1, servletPath.length()); PathMapping mapping = targetPathPatternMappingService.match(trimmedPathInfo); mapping.getTarget(); String recalculatedPathInfo = servletPath.replace("/" + mapping.getPath(), ""); if (servletPath.startsWith("/") && !mapping.getPath().startsWith("/")) { recalculatedPathInfo = recalculatedPathInfo.replaceFirst("/", ""); } return new TransparentAuthEnforcementServiceRequest(mapping.getTarget(), recalculatedPathInfo, ServletUtils.buildContextLocation(servletRequest, "/" + mapping.getPath())); } return new WSSRequestUrl(servletUrl, servletPath, pathInfo, this); }
public static String buildContextLocation(HttpServletRequest request, String... contextRelativePath) { if (contextRelativePath == null || contextRelativePath.length == 0) { return getContextLocation(request); } StringBuilder path = new StringBuilder(getContextLocation(request)); boolean first = true; for (String subpath : contextRelativePath) { if (subpath != null) { if (first && subpath.matches("^(?i:https?)://.*")) { path.setLength(0); path.append(subpath); } else { path.append(subpath); } } first = false; } return path.toString(); }
/** * Sends a HTML form redirect. Builds an HTML fragment as content containing a form * which sends itself after loading. Usefull for URLs * with a long parameter list. All URL parameters are encoded as POST body * parameters. */ public static void sendFormPostRedirect(String redirectUrl, HttpServletResponse response) { sendFormPostRedirect(redirectUrl, response, URLUtils.parseQueryStringFromUrl(redirectUrl)); }
private String buildSessionInitRedirectUrl(HttpServletRequest servletRequest) { return m_sessionLoginRedirect + "?returnUrl=" + ServletUtils.getRequestLocationIncludingQueryParameter(servletRequest); }
public void sendRedirect(String redirectLocation) { // we send the redirect manual to support adding of cookies/deleting of cookies ServletUtils.sendRedirect(redirectLocation, getResponse()); }
public String getRequestLocation() { return ServletUtils.getRequestLocation(getRequest()); }
public static void sendFormPostRedirect(String redirectUrl, HttpServletResponse response, Map<String, Iterable<String>> params) { String htmlRedirect = buildHTMLFormRedirect(redirectUrl, params); response.setContentType("text/html;charset=UTF-8"); try { PrintWriter writer = response.getWriter(); writer.write(htmlRedirect); } catch (IOException e) { throw new IllegalStateException("can't resolve writer from http servlet response", e); } }
public String getContextLocation() { return ServletUtils.getContextLocation(getRequest()); }
public ActionForward execute(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception { LicenseBrokerClientResponseForm lbcrForm = (LicenseBrokerClientResponseForm) form; HTTPClientFactory clientFactory = getHttpClientFactory(); try { if (lbcrForm.isInitialCall()) { PreconditionContext precCtx = getPreconditionContext(request); IdentifyPrecondition idPrec = lookupIdentifyPrecondition(request); String wasUrl = getWasUrl(idPrec); SAMLResponse samlResponse = new WAS1_1Adapter(wasUrl, clientFactory).getSAMLResponse("", PasswordAuthenticationMethod.URN, idPrec.getCredential()); URL wssUrl = getFacadeProperties(request).getSecurityClient().getURL(); LicensePrecondition licPrec = (LicensePrecondition) getPreconditionHandler(request.getSession()).currentPrecondition(); String returnUrlParamValue = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/LicRefPreconditionAction.do"; returnUrlParamValue += ";jsessionid=" + request.getSession().getId(); Map<String, Iterable<String>> params = new HashMap<String, Iterable<String>>(); params.put("ticket", Arrays.asList(samlResponse.getTicket())); params.put("WSS", Arrays.asList(wssUrl.toExternalForm())); params.put("returnURL", Arrays.asList(returnUrlParamValue)); ServletUtils.sendFormPostRedirect(licPrec.getRedirectUrl(), response, params); return null; } IteratingPreconditionHandler precHandler = getPreconditionHandler(request.getSession()); return handleLicensePrecondition(mapping, lbcrForm, (LicensePrecondition) precHandler.currentPrecondition()); } catch (Exception e) { ActionMessages lErrors = new ActionMessages(); lErrors.add("licRef.failed", new ActionMessage("failure.text.licRefFailed")); saveErrors(request, lErrors); return mapping.findForward(FacadeAction.FAILURE_FORWARD); } }
public static String getRequestLocation(final HttpServletRequest request) { return buildContextLocation(request, request.getServletPath(), request.getPathInfo()); // return URLUtils.removeDefaultPort(httpRequest.getRequestURL().toString()); }
public String getRequestLocationIncludingParameter(boolean consumeFORMURLEncodedBody) { return ServletUtils.getRequestLocationIncludingParameter(getRequest(),consumeFORMURLEncodedBody); }
public String buildContextLocation(String... contextRelativePath) { return ServletUtils.buildContextLocation(getRequest(), contextRelativePath); }