Example usage for javax.servlet.http HttpServletResponse SC_MOVED_PERMANENTLY

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

Introduction

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

Prototype

int SC_MOVED_PERMANENTLY

To view the source code for javax.servlet.http HttpServletResponse SC_MOVED_PERMANENTLY.

Click Source Link

Document

Status code (301) indicating that the resource has permanently moved to a new location, and that future references should use a new URI with their requests.

Usage

From source file:com.google.ie.common.openid.appengine.Openid4javaFetcher.java

private static boolean isRedirect(int responseCode) {
    switch (responseCode) {
    case HttpServletResponse.SC_MOVED_PERMANENTLY:
    case HttpServletResponse.SC_MOVED_TEMPORARILY:
    case HttpServletResponse.SC_SEE_OTHER:
    case HttpServletResponse.SC_TEMPORARY_REDIRECT:
        return true;
    default:// w  ww. j av  a 2s .c om
        return false;
    }
}

From source file:com.meltmedia.cadmium.servlets.AbstractSecureRedirectStrategy.java

/**
 * Sends a moved perminately redirect to the secure form of the request URL.
 * // ww  w  . j  a v a  2s  .co m
 * @request the request to make secure.
 * @response the response for the request.
 */
@Override
public void makeSecure(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    response.setHeader("Location", secureUrl(request, response));
    response.getOutputStream().flush();
    response.getOutputStream().close();
}

From source file:net.ymate.framework.core.util.WebUtils.java

/**
 * @param response HttpServletResponse//  w ww. jav  a2  s  .com
 * @param url      URL?
 * @return HeaderLocation?
 */
public static String doRedirectHeaderLocation(HttpServletResponse response, String url) {
    response.setHeader("Location", url);
    return "http:" + HttpServletResponse.SC_MOVED_PERMANENTLY;
}

From source file:com.meltmedia.cadmium.servlets.AbstractSecureRedirectStrategy.java

/**
 * Sends a moved perminately redirect to the insecure form of the request URL.
 * //  www .j  av a2s .co m
 * @request the request to make secure.
 * @response the response for the request.
 */
@Override
public void makeInsecure(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    response.setHeader("Location", insecureUrl(request, response));
    response.getOutputStream().flush();
    response.getOutputStream().close();
}

From source file:ch.entwine.weblounge.common.impl.request.WebloungeResponseImpl.java

/**
 * {@inheritDoc}/* ww  w .  j a v  a 2 s  . c  o  m*/
 * 
 * @see javax.servlet.http.HttpServletResponseWrapper#sendRedirect(java.lang.String)
 */
@Override
public void sendRedirect(String location) throws IOException {
    super.sendRedirect(location);
    responseStatus = HttpServletResponse.SC_MOVED_PERMANENTLY;
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractLogoController.java

private void logoResponse(String imagePath, String defaultImagePath, HttpServletResponse response,
        String cssdkFilesDirectory) {
    FileInputStream fileinputstream = null;
    String rootImageDir = config.getValue(Names.com_citrix_cpbm_portal_settings_images_uploadPath);
    if (StringUtils.isNotBlank(cssdkFilesDirectory)) {
        rootImageDir = cssdkFilesDirectory;
    }/*w  w w . jav a2 s  .co  m*/
    if (rootImageDir != null && !rootImageDir.trim().equals("")) {
        try {
            if (imagePath != null && !imagePath.trim().equals("")) {
                String absoluteImagePath = FilenameUtils.concat(rootImageDir, imagePath);
                fileinputstream = new FileInputStream(absoluteImagePath);
                if (fileinputstream != null) {
                    int numberBytes = fileinputstream.available();
                    byte bytearray[] = new byte[numberBytes];
                    fileinputstream.read(bytearray);
                    response.setContentType("image/" + FilenameUtils.getExtension(imagePath));
                    // TODO:Set Cache headers for browser to force browser to cache to reduce load
                    OutputStream outputStream = response.getOutputStream();
                    response.setContentLength(numberBytes);
                    outputStream.write(bytearray);
                    outputStream.flush();
                    outputStream.close();
                    fileinputstream.close();
                    return;
                }
            }
        } catch (FileNotFoundException e) {
            logger.debug("###File not found in retrieving logo " + imagePath);
        } catch (IOException e) {
            logger.debug("###IO Error in retrieving logo");
        }
    }
    response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    response.setHeader("Location", defaultImagePath);
}

From source file:org.opencms.main.CmsAliasResourceHandler.java

/**
 * Helper method for sending a redirect to a new URI.<p>
 *
 * @param req the current request/*from www .  jav a  2s.  co  m*/
 * @param res the current response
 * @param link the redirect target
 * @param isPermanent if true, sends a 'moved permanently' redirect
 *
 * @throws IOException
 * @throws CmsResourceInitException
 */
private void redirectToTarget(HttpServletRequest req, HttpServletResponse res, String link, boolean isPermanent)
        throws IOException, CmsResourceInitException {

    CmsResourceInitException resInitException = new CmsResourceInitException(getClass());
    if (res != null) {
        // preserve request parameters for the redirect
        String query = req.getQueryString();
        if (query != null) {
            link += "?" + query;
        }
        // disable 404 handler
        resInitException.setClearErrors(true);
        if (isPermanent) {
            res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
            res.setHeader("Location", link);
        } else {
            res.sendRedirect(link);
        }
    }
    throw resInitException;
}

From source file:com.fiveamsolutions.nci.commons.web.filter.SessionFixationProtectionFilter.java

/**
 * {@inheritDoc}/*w  w  w  .  jav  a  2s.  c om*/
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest hReq = (HttpServletRequest) request;
    HttpServletResponse hResp = (HttpServletResponse) response;
    if (hReq.isRequestedSessionIdFromURL()) {
        String requestUrl = hReq.getRequestURL().toString();
        String queryStr = hReq.getQueryString();
        StringBuilder url = new StringBuilder(JSESSIONID_REGEX.matcher(requestUrl).replaceAll(""));
        if (!StringUtils.isEmpty(queryStr)) {
            url.append("?").append(JSESSIONID_REGEX.matcher(queryStr).replaceAll(""));
        }
        hResp.setHeader("Location", url.toString());
        hResp.sendError(HttpServletResponse.SC_MOVED_PERMANENTLY);
        return;
    }

    SessionIdBlockingResponse wrapped = new SessionIdBlockingResponse((HttpServletResponse) response);
    chain.doFilter(request, wrapped);
}

From source file:org.mycore.iview2.frontend.MCRTileCombineServlet.java

/**
 * prepares render process and gets IView2 file and combines tiles.
 * The image dimensions and path are determined from {@link HttpServletRequest#getPathInfo()}:
 * <code>/{zoomAlias}/{derivateID}/{absoluteImagePath}</code>
 * where <code>zoomAlias</code> is mapped like this:
 * <table>//from w  w  w. ja  va 2s.c  o m
 * <caption>Mapping of zoomAlias to actual zoom level</caption>
 * <tr><th>zoomAlias</th><th>zoom level</th></tr>
 * <tr><td>'MIN'</td><td>1</td></tr>
 * <tr><td>'MID'</td><td>2</td></tr>
 * <tr><td>'MAX'</td><td>3</td></tr>
 * <tr><td>default and all others</td><td>0</td></tr>
 * </table>
 * 
 * See {@link #init()} how to attach a footer to every generated image.
 */
@Override
protected void think(final MCRServletJob job) throws IOException, JDOMException {
    final HttpServletRequest request = job.getRequest();
    try {
        String pathInfo = request.getPathInfo();
        if (pathInfo.startsWith("/")) {
            pathInfo = pathInfo.substring(1);
        }
        String zoomAlias = pathInfo.substring(0, pathInfo.indexOf('/'));
        pathInfo = pathInfo.substring(zoomAlias.length() + 1);
        final String derivate = pathInfo.substring(0, pathInfo.indexOf('/'));
        String imagePath = pathInfo.substring(derivate.length());
        LOGGER.info("Zoom-Level: " + zoomAlias + ", derivate: " + derivate + ", image: " + imagePath);
        final Path iviewFile = MCRImage.getTiledFile(MCRIView2Tools.getTileDir(), derivate, imagePath);
        try (FileSystem fs = MCRIView2Tools.getFileSystem(iviewFile)) {
            Path iviewFileRoot = fs.getRootDirectories().iterator().next();
            final MCRTiledPictureProps pictureProps = MCRTiledPictureProps
                    .getInstanceFromDirectory(iviewFileRoot);
            final int maxZoomLevel = pictureProps.getZoomlevel();
            request.setAttribute(THUMBNAIL_KEY, iviewFile);
            LOGGER.info("IView2 file: " + iviewFile);
            int zoomLevel = 0;
            switch (zoomAlias) {
            case "MIN":
                zoomLevel = 1;
                break;
            case "MID":
                zoomLevel = 2;
                break;
            case "MAX":
                zoomLevel = 3;
                break;
            }
            HttpServletResponse response = job.getResponse();
            if (zoomLevel > maxZoomLevel) {
                switch (maxZoomLevel) {
                case 2:
                    zoomAlias = "MID";
                    break;
                case 1:
                    zoomAlias = "MIN";
                    break;
                default:
                    zoomAlias = "THUMB";
                    break;
                }
                if (!imagePath.startsWith("/"))
                    imagePath = "/" + imagePath;
                String redirectURL = response.encodeRedirectURL(MessageFormat.format("{0}{1}/{2}/{3}{4}",
                        request.getContextPath(), request.getServletPath(), zoomAlias, derivate, imagePath));
                response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
                response.setHeader("Location", redirectURL);
                response.flushBuffer();
                return;
            }
            if (zoomLevel == 0 && footerImpl == null) {
                //we're done, sendThumbnail is called in render phase
                return;
            }
            ImageReader reader = MCRIView2Tools.getTileImageReader();
            try {
                BufferedImage combinedImage = MCRIView2Tools.getZoomLevel(iviewFileRoot, pictureProps, reader,
                        zoomLevel);
                if (combinedImage != null) {
                    if (footerImpl != null) {
                        BufferedImage footer = footerImpl.getFooter(combinedImage.getWidth(), derivate,
                                imagePath);
                        combinedImage = attachFooter(combinedImage, footer);
                    }
                    request.setAttribute(IMAGE_KEY, combinedImage);
                } else {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                    return;
                }
            } finally {
                reader.dispose();
            }
        }

    } finally {
        LOGGER.info("Finished sending " + request.getPathInfo());
    }
}