Example usage for javax.servlet.http HttpServletResponse encodeRedirectUrl

List of usage examples for javax.servlet.http HttpServletResponse encodeRedirectUrl

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse encodeRedirectUrl.

Prototype

@Deprecated
public String encodeRedirectUrl(String url);

Source Link

Usage

From source file:org.commoncrawl.service.listcrawler.RequestLogServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    int maxLines = DEFAULT_MAX_LINES;

    if (req.getParameter("maxLines") == null) {
        resp.sendRedirect(resp.encodeRedirectURL(servletPath + "?maxLines=25"));
    } else {/*  w  w w  . j av a 2  s .  com*/
        try {
            maxLines = Integer.parseInt(req.getParameter("maxLines"));
        } catch (NumberFormatException e) {

        }

        File requestLogFile = new File(ProxyServer.getSingleton().getLogDirectory(),
                ProxyServer.getRequestLogFileName());

        List<String> tailList = LogFileUtils.tail(requestLogFile, maxLines);

        resp.setContentType("text/plain");
        PrintWriter writer = resp.getWriter();
        try {
            for (String line : tailList) {
                writer.println(line);
            }
        } finally {
            writer.flush();
            writer.close();
        }
    }
}

From source file:org.dspace.authenticate.PasswordAuthentication.java

/**
 * Returns URL of password-login servlet.
 *
 * @param context/* ww w  .j  av  a 2 s.  c o m*/
 *  DSpace context, will be modified (EPerson set) upon success.
 *
 * @param request
 *  The HTTP request that started this operation, or null if not applicable.
 *
 * @param response
 *  The HTTP response from the servlet method.
 *
 * @return fully-qualified URL
 */
@Override
public String loginPageURL(Context context, HttpServletRequest request, HttpServletResponse response) {
    return response.encodeRedirectURL(request.getContextPath() + "/password-login");
}

From source file:br.com.flucianofeijao.security.JsfRedirectStrategy.java

/**
 * Redirects the response to the supplied URL.
 * <p>/* w  w w  .ja v a  2  s  . c  om*/
 * If <tt>contextRelative</tt> is set, the redirect value will be the value after the request context path. Note
 * that this will result in the loss of protocol information (HTTP or HTTPS), so will cause problems if a
 * redirect is being performed to change to HTTPS, for example.
 */
public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url)
        throws IOException {
    String redirectUrl = calculateRedirectUrl(request.getContextPath(), url);
    redirectUrl = response.encodeRedirectURL(redirectUrl);

    if (logger.isDebugEnabled()) {
        logger.debug("Redirecting to '" + redirectUrl + "'");
    }

    //we should redirect using ajax response if the case warrants
    boolean ajaxRedirect = request.getHeader("faces-request") != null
            && request.getHeader("faces-request").toLowerCase().indexOf("ajax") > -1;

    if (ajaxRedirect) {
        //javax.faces.context.FacesContext ctxt = javax.faces.context.FacesContext.getCurrentInstance();
        //ctxt.getExternalContext().redirect(redirectUrl);

        String ajaxRedirectXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                + "<partial-response><redirect url=\"" + redirectUrl + "\"></redirect></partial-response>";
        response.setContentType("text/xml");
        response.getWriter().write(ajaxRedirectXml);
    } else {
        response.sendRedirect(redirectUrl);
    }

}

From source file:br.com.sisped.security.JsfRedirectStrategy.java

/**
 * Redirects the response to the supplied URL.
 * <p>//from w  ww .  j  a  v  a2 s . c o  m
 * If <tt>contextRelative</tt> is set, the redirect value will be the value
 * after the request context path. Note that this will result in the loss of
 * protocol information (HTTP or HTTPS), so will cause problems if a
 * redirect is being performed to change to HTTPS, for example.
 */
public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url)
        throws IOException {
    String redirectUrl = calculateRedirectUrl(request.getContextPath(), url);
    redirectUrl = response.encodeRedirectURL(redirectUrl);

    if (logger.isDebugEnabled()) {
        logger.debug("Redirecting to '" + redirectUrl + "'");
    }

    // we should redirect using ajax response if the case warrants
    boolean ajaxRedirect = request.getHeader("faces-request") != null
            && request.getHeader("faces-request").toLowerCase().indexOf("ajax") > -1;

    if (ajaxRedirect) {
        // javax.faces.context.FacesContext ctxt =
        // javax.faces.context.FacesContext.getCurrentInstance();
        // ctxt.getExternalContext().redirect(redirectUrl);

        String ajaxRedirectXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                + "<partial-response><redirect url=\"" + redirectUrl + "\"></redirect></partial-response>";
        response.setContentType("text/xml");
        response.getWriter().write(ajaxRedirectXml);
    } else {
        response.sendRedirect(redirectUrl);
    }

}

From source file:com.hp.autonomy.hod.sso.HodTokenLogoutSuccessHandlerTest.java

@Test
public void redirectsWithAuthentication() throws IOException, ServletException {
    final HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getContextPath()).thenReturn(CONTEXT_PATH);

    final String mockRedirectUrl = "/mock/redirect/url";
    final HttpServletResponse response = mock(HttpServletResponse.class);

    final String expectedPath = CONTEXT_PATH + REDIRECT_PATH + "?token=CMB%3ASIMPLE%3Atoken-id%3Atoken-secret";
    when(response.encodeRedirectURL(expectedPath)).thenReturn(mockRedirectUrl);

    final HodAuthenticationPrincipal principal = new HodAuthenticationPrincipal(UUID.randomUUID(),
            UUID.randomUUID(), new ResourceIdentifier("APP-DOMAIN", "APP-NAME"),
            new UserStoreInformation(UUID.randomUUID(), "STORE-DOMAIN", "STORE-NAME"),
            new AuthenticationInformation(UUID.randomUUID(), AuthenticationType.LEGACY_API_KEY),
            new AuthenticationInformation(UUID.randomUUID(), AuthenticationType.LEGACY_API_KEY), null, null,
            null);// ww  w  . j av a2s.c o  m

    final HodAuthentication<EntityType.Combined> authentication = new HodAuthentication<>(tokenProxy,
            Collections.<GrantedAuthority>emptySet(), principal);

    logoutSuccessHandler.onLogoutSuccess(request, response, authentication);

    verify(response).sendRedirect(mockRedirectUrl);
}

From source file:br.com.gerenciapessoal.security.JsfRedirectStrategy.java

/**
 * Redirects the response to the supplied URL.
 * <p>/*w ww.j a v  a2 s . com*/
 * If <tt>contextRelative</tt> is set, the redirect value will be the value
 * after the request context path. Note that this will result in the loss of
 * protocol information (HTTP or HTTPS), so will cause problems if a
 * redirect is being performed to change to HTTPS, for example.
 *
 * @param request
 * @param response
 * @param url
 * @throws java.io.IOException
 */
@Override
public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url)
        throws IOException {
    String redirectUrl = calculateRedirectUrl(request.getContextPath(), url);
    redirectUrl = response.encodeRedirectURL(redirectUrl);

    if (logger.isDebugEnabled()) {
        logger.debug("Redirecting to '" + redirectUrl + "'");
    }

    //we should redirect using ajax response if the case warrants
    boolean ajaxRedirect = request.getHeader("faces-request") != null
            && request.getHeader("faces-request").toLowerCase().contains("ajax");

    if (ajaxRedirect) {
        //javax.faces.context.FacesContext ctxt = javax.faces.context.FacesContext.getCurrentInstance();
        //ctxt.getExternalContext().redirect(redirectUrl);

        String ajaxRedirectXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                + "<partial-response><redirect url=\"" + redirectUrl + "\"></redirect></partial-response>";
        response.setContentType("text/xml");
        response.getWriter().write(ajaxRedirectXml);
    } else {
        response.sendRedirect(redirectUrl);
    }

}

From source file:org.cloudfoundry.identity.uaa.provider.saml.LoginSamlDiscovery.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    try {/*  w ww . ja v a  2s  .  c  o m*/
        super.doFilter(request, response, chain);
    } catch (UnableToFindSamlIDPException x) {
        logger.warn(x);
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        httpServletResponse.sendRedirect(httpServletResponse
                .encodeRedirectURL(httpServletRequest.getContextPath() + "/login?error=idp_not_found"));
    }
}

From source file:azkaban.web.JobManagerServlet.java

private void setMessagedUrl(HttpServletResponse response, String redirectUrl, String message)
        throws IOException {
    String url = redirectUrl + "/" + message;
    response.sendRedirect(response.encodeRedirectURL(url));
}

From source file:org.xine.marketplace.frontend.views.security.JsfRedirectStrategy.java

/**
 * Redirects the response to the supplied URL.
 * <p>/* w w  w . j  a v a 2  s .c o  m*/
 * If <tt>contextRelative</tt> is set, the redirect value will be the value after the request
 * context path. Note that this will result in the loss of protocol information (HTTP or
 * HTTPS), so will cause problems if a redirect is being performed to change to HTTPS, for
 * example.
 */
@Override
public void sendRedirect(final HttpServletRequest request, final HttpServletResponse response, final String url)
        throws IOException {
    String redirectUrl = calculateRedirectUrl(request.getContextPath(), url);
    redirectUrl = response.encodeRedirectURL(redirectUrl);

    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Redirecting to '" + redirectUrl + "'");
    }

    // we should redirect using ajax response if the case warrants
    final boolean ajaxRedirect = request.getHeader("faces-request") != null
            && request.getHeader("faces-request").toLowerCase().indexOf("ajax") > -1;

    if (ajaxRedirect) {
        // javax.faces.context.FacesContext ctxt =
        // javax.faces.context.FacesContext.getCurrentInstance();
        // ctxt.getExternalContext().redirect(redirectUrl);

        final String ajaxRedirectXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                + "<partial-response><redirect url=\"" + redirectUrl + "\"></redirect></partial-response>";
        response.setContentType("text/xml");
        response.getWriter().write(ajaxRedirectXml);
    } else {
        response.sendRedirect(redirectUrl);
    }

}

From source file:org.hdiv.js.ajax.SpringJavascriptAjaxHandlerHDIV.java

public void sendAjaxRedirectInternal(String targetUrl, HttpServletRequest request, HttpServletResponse response,
        boolean popup) throws IOException {

    if (popup) {/* www  .  ja v  a2  s  .  c om*/
        response.setHeader(POPUP_VIEW_HEADER, "true");
    }

    String encodeRedirectURL = response.encodeRedirectURL(targetUrl);

    if (request.getSession(false) != null) {

        if (!encodeRedirectURL.startsWith("/")) {
            String requestUri = request.getRequestURI();
            int lastSlash = requestUri.lastIndexOf('/');

            encodeRedirectURL = requestUri.substring(0, lastSlash) + "/" + encodeRedirectURL;
        }
        LinkUrlProcessor linkUrlProcessor = HDIVUtil
                .getLinkUrlProcessor(request.getSession().getServletContext());
        encodeRedirectURL = linkUrlProcessor.processUrl(request, targetUrl);
    }

    /* original...
    if (request.getSession(false) != null) {         
            
       ServletContext servletContext = request.getSession().getServletContext();
       HDIVConfig hdivConfig = HDIVUtil.getHDIVConfig(servletContext);
       if (HDIVRequestUtils.hasActionOrServletExtension(encodeRedirectURL, hdivConfig.getProtectedURLPatterns())) {
    if (!encodeRedirectURL.startsWith("/")) {
       String requestUri = request.getRequestURI();
       int lastSlash = requestUri.lastIndexOf('/');
               
       encodeRedirectURL = requestUri.substring(0, lastSlash) + "/" + encodeRedirectURL;   
    }
    encodeRedirectURL = HDIVRequestUtils.addHDIVParameterIfNecessary(request, encodeRedirectURL, hdivConfig.isValidationInUrlsWithoutParamsActivated());
       }
    }
    */

    if (log.isDebugEnabled()) {
        log.debug("Send Ajax Redirect to:" + encodeRedirectURL);
    }

    response.setHeader(REDIRECT_URL_HEADER, encodeRedirectURL);
}