Example usage for javax.servlet.http HttpServletResponse SC_BAD_REQUEST

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

Introduction

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

Prototype

int SC_BAD_REQUEST

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

Click Source Link

Document

Status code (400) indicating the request sent by the client was syntactically incorrect.

Usage

From source file:com.ppcxy.cyfm.showcase.demos.web.RemoteContentServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // ?URL/*from w  ww  . j  av a  2 s. c  o m*/
    String contentUrl = request.getParameter("contentUrl");
    if (StringUtils.isBlank(contentUrl)) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "contentUrl parameter is required.");
    }

    // ?HttpClientJDK ??URL
    String client = request.getParameter("client");
    if ("apache".equals(client)) {
        fetchContentByApacheHttpClient(response, contentUrl);
    } else {
        fetchContentByJDKConnection(response, contentUrl);
    }
}

From source file:com.oneops.transistor.ws.rest.CatalogRestController.java

@ExceptionHandler(TransistorException.class)
@ResponseBody//from ww  w. ja  v  a 2  s.c o m
public void handleExceptions(TransistorException e, HttpServletResponse response) throws IOException {
    logger.error(e);
    sendError(response, HttpServletResponse.SC_BAD_REQUEST, e);
}

From source file:eu.stratosphere.pact.client.web.PactJobJSONServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("application/json");

    String jobName = req.getParameter(JOB_PARAM_NAME);
    if (jobName == null) {
        LOG.warn("Received request without job parameter name.");
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return;//from   w w w .ja va2  s .c  om
    }

    // check, if the jar exists
    File jarFile = new File(jobStoreDirectory, jobName);
    if (!jarFile.exists()) {
        LOG.warn("Received request for non-existing jar file.");
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }

    // create the pact plan
    PactProgram pactProgram;
    try {
        pactProgram = new PactProgram(jarFile, new String[0]);
    } catch (Throwable t) {
        LOG.info("Instantiating the PactProgram for '" + jarFile.getName() + "' failed.", t);
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        resp.getWriter().print(t.getMessage());
        return;
    }

    String jsonPlan = null;
    String programDescription = null;

    try {
        jsonPlan = Client.getPreviewAsJSON(pactProgram);
    } catch (Throwable t) {
        LOG.error("Failed to create json dump of pact program.", t);
    }

    try {
        programDescription = pactProgram.getDescription();
    } catch (Throwable t) {
        LOG.error("Failed to create description of pact program.", t);
    }

    if (jsonPlan == null && programDescription == null) {
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return;
    } else {
        resp.setStatus(HttpServletResponse.SC_OK);
        PrintWriter wrt = resp.getWriter();
        wrt.print("{ \"jobname\": \"");
        wrt.print(jobName);
        if (jsonPlan != null) {
            wrt.print("\", \"plan\": ");
            wrt.println(jsonPlan);
        }
        if (programDescription != null) {
            wrt.print(", \"description\": \"");
            wrt.print(escapeString(programDescription));
        }

        wrt.print("\"");
        wrt.println("}");
    }
}

From source file:com.conwet.silbops.connectors.comet.handlers.PublishResponse.java

@Override
protected void reply(HttpServletRequest req, HttpServletResponse res, PrintWriter writer,
        HttpEndPoint httpEndPoint, EndPoint connection) {
    try {//  w w  w.  j a va  2s  . c  o m
        String notification = retriveParameter(req, "notification");
        String context = retriveParameter(req, "context");

        JSONObject jsonNotification = (JSONObject) JSONValue.parseWithException(notification);
        JSONObject jsonContext = (JSONObject) JSONValue.parseWithException(context);

        PublishMsg msg = new PublishMsg();
        msg.setNotification(Notification.fromJSON(jsonNotification));
        msg.setContext(Context.fromJSON(jsonContext));

        broker.receiveMessage(msg, connection);
        writeOut(writer, httpEndPoint.getEndPoint(), "publish success");

    } catch (ParseException ex) {
        logger.warn("publish exception: " + ex.getMessage());
        try {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST);
        } catch (IOException ex1) {
            logger.warn(ex1.getMessage());
        }
    }
}

From source file:org.dspace.webmvc.controller.ResourceController.java

protected LookupResult lookupNoCache(HttpServletRequest req) {
    final String path = getPath(req);
    if (isForbidden(path)) {
        return new Error(HttpServletResponse.SC_FORBIDDEN, "Forbidden");
    }//from   ww  w .  j av a2s.c  o  m

    final URL url;
    try {
        url = req.getSession().getServletContext().getResource(path);
    } catch (MalformedURLException e) {
        return new Error(HttpServletResponse.SC_BAD_REQUEST, "Malformed path");
    }

    final String mimeType = getMimeType(req, path);

    final String realpath = req.getSession().getServletContext().getRealPath(path);
    if (url != null && realpath != null) {
        // Try as an ordinary file
        File f = new File(realpath);
        if (!f.isFile()) {
            return new Error(HttpServletResponse.SC_FORBIDDEN, "Forbidden");
        } else {
            return new StaticFile(f.lastModified(), mimeType, (int) f.length(), acceptsDeflate(req), url);
        }
    } else {
        ClassPathResource cpr = new ClassPathResource(path);
        if (cpr.exists()) {
            URL cprURL = null;
            try {
                cprURL = cpr.getURL();

                // Try as a JAR Entry
                final ZipEntry ze = ((JarURLConnection) cprURL.openConnection()).getJarEntry();
                if (ze != null) {
                    if (ze.isDirectory()) {
                        return new Error(HttpServletResponse.SC_FORBIDDEN, "Forbidden");
                    } else {
                        return new StaticFile(ze.getTime(), mimeType, (int) ze.getSize(), acceptsDeflate(req),
                                cprURL);
                    }
                } else {
                    // Unexpected?
                    return new StaticFile(-1, mimeType, -1, acceptsDeflate(req), cprURL);
                }
            } catch (ClassCastException e) {
                // Unknown resource type
                if (url != null) {
                    return new StaticFile(-1, mimeType, -1, acceptsDeflate(req), cprURL);
                } else {
                    return new Error(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal server error");
                }
            } catch (IOException e) {
                return new Error(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal server error");
            }
        } else {
            return new Error(HttpServletResponse.SC_NOT_FOUND, "Not found");
        }
    }
}

From source file:com.conwet.silbops.connectors.comet.handlers.AdvertiseResponse.java

@Override
protected void reply(HttpServletRequest req, HttpServletResponse res, PrintWriter writer,
        HttpEndPoint httpEndPoint, EndPoint connection) {
    try {//w w w.j ava  2  s .c  o  m
        AdvertiseMsg msg = new AdvertiseMsg();
        msg.setAdvertise(extract(req, "advertise"));
        msg.setContext(extract(req, "context"));
        logger.debug("Endpoint {}, AdvertiseRequest: {}", httpEndPoint, msg);

        broker.receiveMessage(msg, connection);
        writeOut(writer, httpEndPoint.getEndPoint(), "advertise success");
    } catch (Exception ex) {
        logger.warn("exception on AdvertiseRequest=" + ex.getMessage());
        try {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST);
        } catch (IOException ex1) {
            logger.warn(ex1.getMessage());
        }
    }
}

From source file:com.conwet.silbops.connectors.comet.handlers.UnadvertiseResponse.java

@Override
protected void reply(HttpServletRequest req, HttpServletResponse res, PrintWriter writer,
        HttpEndPoint httpEndPoint, EndPoint connection) {

    try {/*from w  w w . j ava2  s  .  c om*/
        UnadvertiseMsg msg = new UnadvertiseMsg();
        msg.setAdvertise(extract(req, "advertise"));
        msg.setContext(extract(req, "context"));
        logger.debug("Endpoint {}, UnadvertiseRequest: {}", httpEndPoint, msg);

        broker.receiveMessage(msg, connection);
        writeOut(writer, httpEndPoint.getEndPoint(), "unadvertise success");

    } catch (Exception ex) {
        logger.warn("exception on UnadvertiseRquest=" + ex.getMessage());
        try {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST);
        } catch (IOException ex1) {
            logger.warn(ex1.getMessage());
        }
    }
}

From source file:com.natpryce.piazza.BuildMonitorController.java

protected ModelAndView doHandle(HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (requestHasParameter(request, BUILD_TYPE_ID)) {
        return showBuildType(request.getParameter(BUILD_TYPE_ID), response);
    } else if (requestHasParameter(request, PROJECT_ID)) {
        return showProject(request.getParameter(PROJECT_ID),
                Boolean.parseBoolean(request.getParameter(SHOW_FEATURE_BRANCH_BUILDS_ONLY)), response);
    } else {/*from  w  w  w  .java  2s  .co  m*/
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no build type id specified");
        return null;
    }
}

From source file:org.pentaho.pat.server.servlet.PentahoServlet.java

public void simpleXmla(final HttpServletRequest request, final HttpServletResponse response,
        final HttpSession session) throws Exception {
    final StringBuilder redirect = new StringBuilder(redirectTarget);

    // Validate url.
    final String xmlaUrl = request.getParameter(xmlaUrlParameter);
    if (!this.verifyXmlaUrl(xmlaUrl)) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "A valid XMLA service URL is required."); //$NON-NLS-1$
    }//from w  w  w  .j a  va  2  s.com
    // Validate MDX
    // String mdxQuery = request.getParameter(mdxQueryParameter);
    // if (mdxQuery==null
    // || mdxQuery.length()<1) {
    // response.sendError(HttpServletResponse.SC_BAD_REQUEST,
    // "A valid MDX query is required.");
    // }

    // These two are optional. No need to validate.
    final String xmlaUsername = request.getParameter(xmlaUsernameParameter);
    final String xmlaPassword = request.getParameter(xmlaPasswordParameter);

    // Create a new session.
    final String userId = SecurityContextHolder.getContext().getAuthentication().getName();
    final String sessionId = this.sessionService.createNewSession(userId);

    // Build the URL
    final String olap4jUrl = "jdbc:xmla:Server=".concat(xmlaUrl); //$NON-NLS-1$

    // Establish the connection
    ((SessionServiceImpl) this.sessionService).createConnection(userId, sessionId,
            "org.olap4j.driver.xmla.XmlaOlap4jDriver", olap4jUrl, xmlaUsername, xmlaPassword); //$NON-NLS-1$

    // Build the redirect URL
    redirect.append("?MODE=BISERVERPUC"); //$NON-NLS-1$
    redirect.append("&SESSION=").append(sessionId); //$NON-NLS-1$

    // Send the redirect HTTP message
    response.sendRedirect(request.getContextPath().concat(redirect.toString()));
}

From source file:com.bt.aloha.batchtest.ultramonkey.Servlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST);
}