Example usage for javax.servlet.http HttpServletResponse sendRedirect

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

Introduction

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

Prototype

public void sendRedirect(String location) throws IOException;

Source Link

Document

Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer.

Usage

From source file:edu.harvard.i2b2.fhir.oauth2.ws.WebsiteFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    String url = ((HttpServletRequest) request).getRequestURI().toString();
    String servletPath = ((HttpServletRequest) request).getServletPath();
    logger.info("url:" + url);

    String query = ((HttpServletRequest) request).getQueryString();
    if (query == null)
        query = "";
    String fullUrl = url + "?" + query;
    LogEntry le = new LogEntry();
    HttpSession session = ((HttpServletRequest) request).getSession();
    le.setUrl(fullUrl);//from  w w w.  j a va 2  s.c  o  m
    le.setDateAccessed(new Date());
    le.setSessionId(session.getId());
    String accessToken = "-";
    String clientId = "-";
    if (session.getAttribute("accessToken") != null) {
        accessToken = ((AccessToken) session.getAttribute("accessToken")).getTokenString();
        clientId = ((AccessToken) session.getAttribute("accessToken")).getClientId();

    }
    le.setAccessToken(accessToken);
    le.setClientId(clientId);
    le.setUserId(-1);

    if ((servletPath.startsWith("/user")
            //|| servletPath.startsWith("/config")
            || servletPath.startsWith("/client"))) {

        Object u = ((HttpServletRequest) request).getSession().getAttribute("authenticatedUser");

        if (u == null) {
            logger.info("User is not authenticated. Hence redirecting to login page");
            HttpServletResponse httpServletResponse = (HttpServletResponse) response;
            httpServletResponse.sendRedirect("../login/signin.xhtml");
        }

        if (u != null) {
            le.setUserId(User.class.cast(u).getId());
        }

    }

    logEntryService.create(le);

    chain.doFilter(new PublicClientWrapper((HttpServletRequest) request), response);

}

From source file:com.antelink.sourcesquare.server.servlet.ErrorHandler.java

@Override
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) {
    try {//from w  w w .ja  v a  2s.  co m
        HttpConnection connection = HttpConnection.getCurrentConnection();
        connection.getRequest().setHandled(true);
        response.sendRedirect("/index.jsp");
    } catch (IOException e) {
        logger.error("Error handling errorPage", e);
    }
}

From source file:com.pawelniewiadomski.devs.jira.servlet.LicenseServlet.java

private void redirectToLogin(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.sendRedirect(
            loginUriProvider.getLoginUri(URI.create(request.getRequestURL().toString())).toASCIIString());
}

From source file:com.fdu.jira.plugin.servlet.LicenseServlet.java

private void redirectToLogin(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.sendRedirect(loginUriProvider.getLoginUri(URI.create(req.getRequestURL().toString())).toASCIIString());
}

From source file:ar.com.zauber.commons.social.oauth.examples.web.controllers.TwitterLoginController.java

/**
 * Sing in with Twitter// ww  w. j  ava 2  s  .c om
 * 
 * @throws IOException
 * @throws OAuthAccessException
 * @throws ServletException
 */
@RequestMapping(method = RequestMethod.GET)
public final void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws OAuthAccessException, IOException, ServletException {
    final String callback = "http://localhost:8080" + twitterCallbackURL;
    response.sendRedirect(accessManager.getAuthenticationUrl(callback));
}

From source file:th.co.geniustree.osgi.prototype.authen.impl.AuthenServiceImpl.java

@Override
public void signOut(HttpServletRequest request, HttpServletResponse response, String callbackUrl) {
    try {// w ww .j  av a 2 s.co  m
        String sessionId = (String) request.getSession().getAttribute("session.id");

        response.sendRedirect(SIGNOUT_URL + "?sessionId=" + sessionId + "&redirect_url=" + callbackUrl);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:com.rapid.server.Rapid.java

public static void gotoStartPage(HttpServletRequest request, HttpServletResponse response, Application app,
        boolean invalidate) throws IOException {
    // clear the session if requested to
    if (invalidate)
        request.getSession().invalidate();
    // go to the start page
    response.sendRedirect("~?a=" + app.getId() + "&v=" + app.getVersion());
}

From source file:Controller.KaryawanController.java

@RequestMapping(value = "ProsesTambahKaryawan.htm")
public void ProsesTambahKaryawan(HttpServletResponse response, @ModelAttribute("Karyawan") Karyawan j)
        throws IOException {
    KaryawanImplement ai = new KaryawanImplement();
    ai.insert(j);/*from w w w  .j av a 2  s.co  m*/
    response.sendRedirect("TampilAllKaryawan.htm");
}

From source file:Controller.KaryawanController.java

@RequestMapping(value = "ProsesUpdateKaryawan.htm")
public void ProsesUpdateKaryawan(HttpServletResponse response, @ModelAttribute("Karyawan") Karyawan j)
        throws IOException {
    KaryawanImplement ai = new KaryawanImplement();
    ai.update(j);/*from w ww .  ja v  a  2  s .co  m*/
    response.sendRedirect("TampilAllKaryawan.htm");
}

From source file:org.jdal.auth.AuthFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws ServletException, IOException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;

    if (!isLoginPage(req) && req.getSession().getAttribute(SESSION_USER_KEY) == null) {
        // not authorized
        res.sendRedirect(req.getContextPath() + "/" + loginPage);
    } else {/*from  w w w  .jav a 2  s.c  o m*/
        // authorized
        chain.doFilter(request, response);
    }

}