Example usage for javax.servlet.http HttpServletResponse SC_OK

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

Introduction

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

Prototype

int SC_OK

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

Click Source Link

Document

Status code (200) indicating the request succeeded normally.

Usage

From source file:org.nubomedia.marketplace.api.SimpleCorsFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    HttpServletRequest request = (HttpServletRequest) req;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers",
            "Auth-token, x-requested-with, authorization, content-type, origin");

    if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
        response.setStatus(HttpServletResponse.SC_OK);
    } else {//from   w w  w.j a v a  2 s. co m
        chain.doFilter(req, res);
    }
}

From source file:org.openbaton.nfvo.security.authentication.SimpleCorsFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    HttpServletRequest request = (HttpServletRequest) req;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers",
            "x-requested-with, authorization, content-type, Cache-Control");

    if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
        response.setStatus(HttpServletResponse.SC_OK);
    } else {//from   w  ww .java  2 s .  c o  m
        chain.doFilter(req, res);
    }
}

From source file:com.ar.dev.tierra.hasar.api.config.security.CustomLogoutSuccessHandler.java

@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {

    String token = request.getHeader(HEADER_AUTHORIZATION);
    if (token != null && token.startsWith(BEARER_AUTHENTICATION)) {
        OAuth2AccessToken oAuth2AccessToken = tokenStore.readAccessToken(token.split(" ")[1]);
        if (oAuth2AccessToken != null) {
            tokenStore.removeAccessToken(oAuth2AccessToken);
            response.setStatus(HttpServletResponse.SC_OK);
        } else {//ww w  .java  2  s . c o  m
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    }
}

From source file:de.steilerdev.myVerein.server.security.rest.RestLogoutSuccessHandler.java

@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    User currentUser = (User) authentication.getPrincipal();
    logger.info("[{}] Successfully logged user out from IP {}", currentUser,
            SecurityHelper.getClientIpAddr(request));
    if (!response.isCommitted()) {
        response.sendError(HttpServletResponse.SC_OK, "Successfully logged out");
    }/*  w  ww . j  a  v  a 2 s.c om*/
}

From source file:com.ns.cm.ProvisionServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("Redirecting...");
    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);
    response.sendRedirect(request.getContextPath());
}

From source file:com.k42b3.quantum.handler.MessageHandler.java

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    if (request.getMethod().equals("GET")) {
        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType("application/json;charset=utf-8");
        baseRequest.setHandled(true);/* w  w  w.  jav  a2s .  c  o  m*/

        try {
            String modifiedSince = request.getHeader("If-Modified-Since");
            Date date = null;

            if (modifiedSince != null && !modifiedSince.isEmpty()) {
                date = DateUtils.parseDate(modifiedSince);
            }

            response.getWriter()
                    .print(container.getGson().toJson(container.getMessageRepository().getAll(date)));
        } catch (SQLException e) {
            this.handleException(response, e);
        }
    } else if (request.getMethod().equals("POST")) {
        Message message = container.getGson().fromJson(readRequestBody(request), Message.class);

        container.getEventPublisher().publish(null, message);

        response.setContentType("application/json;charset=utf-8");
        response.setStatus(HttpServletResponse.SC_CREATED);
        response.getWriter().print(container.getGson().toJson(message));
    }
}

From source file:cn.org.once.cstack.config.UserAjaxAuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {

    logger.info("SC_OK");
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:at.struct.wasbugs.wasbug17.TestServlet.java

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

    // this is a rather new method which only got introduced in commons-codec-1.10
    // https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/StringUtils.html#equals%28java.lang.CharSequence,%20java.lang.CharSequence%29
    StringUtils.equals("hiho", "you");

    resp.setStatus(HttpServletResponse.SC_OK);
    resp.setContentType("text/plain");
    resp.getWriter().append("OK");
}

From source file:edu.stanford.muse.webapp.HTMLToImage.java

/**
 * Convert an HTML page at the specified URL into an image who's data is
 * written to the provided output stream.
 *
 * @param url    URL to the page that is to be imaged.
 * @param os     An output stream that is to be opened for writing.  Image
 *               data will be written to the provided stream.  The stream
 *               will not be closed under any circumstances by this method.
 * @param width  The desired width of the image that will be created.
 * @param height The desired height of the image that will be created.
 *
 * @returns true if the page at the provided URL was loaded, converted to an
 *          image, and the image data has been written to the output stream,
 *          false if an error has ocurred along the way.
 *
 * @throws HTMLImagerException if an error has ocurred.
 *//*from  w ww. j  av a2s.c  o  m*/
public static boolean image(String url, OutputStream os, int width, int height) {
    if (log.isDebugEnabled())
        log.debug("Imaging url '" + url + "'.");

    boolean successful = false;

    try {
        HttpClient httpClient = new HttpClient();
        GetMethod getMethod = new GetMethod(url);

        httpClient.executeMethod(getMethod);

        int httpStatus = getMethod.getStatusCode();

        if (httpStatus == HttpServletResponse.SC_OK) {
            Tidy tidy = new Tidy();

            tidy.setQuiet(true);
            tidy.setXHTML(true);
            tidy.setHideComments(true);
            tidy.setInputEncoding("UTF-8");
            tidy.setOutputEncoding("UTF-8");
            tidy.setShowErrors(0);
            tidy.setShowWarnings(false);

            Document doc = tidy.parseDOM(getMethod.getResponseBodyAsStream(), null);

            if (doc != null) {
                BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
                Graphics2D graphics = (Graphics2D) buf.getGraphics();
                Graphics2DRenderer renderer = new Graphics2DRenderer();
                SharedContext context = renderer.getSharedContext();
                UserAgentCallback userAgent = new HTMLImagerUserAgent(url);

                context.setUserAgentCallback(userAgent);
                context.setNamespaceHandler(new XhtmlNamespaceHandler());

                renderer.setDocument(doc, url);
                renderer.layout(graphics, new Dimension(width, height));
                renderer.render(graphics);
                graphics.dispose();

                /*
                JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam( buf );
                        
                param.setQuality( (float)1.0, false );
                        
                JPEGImageEncoder imageEncoder = JPEGCodec.createJPEGEncoder( os,
                      param );
                        
                imageEncoder.encode( buf );
                */
                successful = true;
            } else {
                if (log.isDebugEnabled())
                    log.debug("Unable to image URL '" + url
                            + "'.  The HTML that was returned could not be tidied.");
            }
        } else {
            if (log.isDebugEnabled())
                log.debug("Unable to image URL '" + url + "'.  Server returned status code '" + httpStatus
                        + "'.");
        }
    }

    catch (Exception e) {
        throw new RuntimeException("Unable to image URL '" + url + "'.", e);
    }

    return successful;
}

From source file:de.knightsoftnet.validators.server.security.HttpLogoutSuccessHandler.java

@Override
public void onLogoutSuccess(final HttpServletRequest prequest, final HttpServletResponse presponse,
        final Authentication pauthentication) throws IOException {
    LOGGER.info("User logged out!");
    presponse.setStatus(HttpServletResponse.SC_OK);
    this.csrfCookieHandler.setCookie(prequest, presponse);
}