Example usage for javax.servlet.http HttpServletResponse setStatus

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

Introduction

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

Prototype

public void setStatus(int sc);

Source Link

Document

Sets the status code for this response.

Usage

From source file:se.kth.csc.controller.ExceptionHandlerAdvice.java

@ExceptionHandler(value = DataIntegrityViolationException.class)
@ResponseBody//  w  w  w  . j  a v  a  2s .c o m
public String dataIntegrityViolation(Exception exception, WebRequest request, HttpServletResponse response) {
    response.setStatus(409); // Conflict
    return String.format("%s: %s", request.getDescription(true), exception.getMessage());
}

From source file:se.kth.csc.controller.ExceptionHandlerAdvice.java

/**
 * Handle exceptions thrown by handlers.
 *//*  www  . j  ava2 s  . c o m*/
@ExceptionHandler(value = NotFoundException.class)
@ResponseBody
public String notFound(Exception exception, WebRequest request, HttpServletResponse response) {
    response.setStatus(404); // Not found
    return String.format("%s: %s", request.getDescription(true), exception.getMessage());
}

From source file:com.netflix.spinnaker.halyard.errors.v1.HalconfigExceptionHandler.java

@ExceptionHandler({ HalException.class })
@ResponseBody//from   w ww .j  a v  a2s  . c o  m
public DaemonResponse<Void> handleHalconfigException(HttpServletResponse response, HalException exception) {
    response.setStatus(exception.getResponseCode());
    return new DaemonResponse<>(null, exception.getProblems());
}

From source file:io.hawt.testing.env.builtin.NotFound.java

@Override
public void handle(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
    resp.setContentType("application/json");
    resp.setCharacterEncoding("UTF-8");
    JSONObject r = new JSONObject();
    r.put("error", HttpServletResponse.SC_NOT_FOUND);
    r.put("message", "Environment not found");
    resp.getWriter().println(r.toJSONString());
    resp.getWriter().close();//from   w w w  . ja va  2 s  . c o  m
}

From source file:info.raack.appliancedetection.evaluation.web.BaseController.java

@ExceptionHandler
public ModelAndView handleUncaughtException(Exception ex, HttpServletRequest request,
        HttpServletResponse response) {

    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    errorService.reportError("Error", URGENCY.URGENT, ex);
    logger.error("An exception was caught while processing", ex);

    return new ModelAndView("error", new ModelMap());
}

From source file:com.berrysys.ussdgw.HttpUtils.java

/**
 * Do post./*from  w w  w . j  a v  a  2  s.co  m*/
 *
 * @param req the req
 * @param resp the resp
 * @param dialogListener the dialog listener
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void doPost(HttpServletRequest req, HttpServletResponse resp, final DialogListener dialogListener)
        throws IOException {

    boolean available = GlobalNetworkInitiatedSemaphore.getInstance().getSemaphore().tryAcquire();

    if (!available) {
        queueFullLogic(resp);
        return;
    }

    final String ussdAppUrl = req.getHeader("ussd-app-url");

    log.trace(String.format("ussd-app-url: %s", ussdAppUrl));

    final String payload = getPayload(req);

    log.trace(String.format("payload: %s", payload));

    HawtDispatchUtil.getInstance().queueExecute(new Runnable() {

        @Override
        public void run() {
            processHttpRequest(payload, ussdAppUrl, dialogListener);
        }

    });

    String response = "Request received successfully.";

    resp.setContentType("text/html");
    resp.setStatus(HttpServletResponse.SC_OK);
    resp.getWriter().println(response);

}

From source file:de.iew.web.controllers.JavascriptConfigController.java

@ExceptionHandler(value = Exception.class)
public void onException(Exception e, HttpServletResponse response) {
    response.setStatus(404);
    if (log.isErrorEnabled()) {
        log.error("Fehler beim Rendern eines der Javascript Konfiguration.", e);
    }//  w  w  w.  j  av a 2 s . c o  m
}

From source file:com.tamnd.app.config.security.LogoutSuccessHandler.java

@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) {
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:com.graphhopper.http.InvalidRequestServlet.java

@Override
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setStatus(HttpServletResponse.SC_NOT_FOUND);
    res.setContentType("text/plain");
    res.setContentType("UTF-8");
    JSONObject json = new JSONObject();
    json.put("error_code", "404");
    writeJson(req, res, json);//from w  w w  . jav a2s.  c  o m
}

From source file:com.ibm.jaggr.core.test.TestUtils.java

public static HttpServletResponse createMockResponse(final Map<String, String> responseAttributes) {
    HttpServletResponse mockResponse = EasyMock.createNiceMock(HttpServletResponse.class);
    mockResponse.setContentLength(EasyMock.anyInt());
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
        public Object answer() throws Throwable {
            if (responseAttributes != null) {
                responseAttributes.put("Content-Length",
                        ((Integer) EasyMock.getCurrentArguments()[0]).toString());
            }//from www  . j a  v a  2  s. c  o  m
            return null;
        }
    }).anyTimes();
    mockResponse.setStatus(EasyMock.anyInt());
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
        public Object answer() throws Throwable {
            if (responseAttributes != null) {
                responseAttributes.put("Status", ((Integer) EasyMock.getCurrentArguments()[0]).toString());
            }
            return null;
        }
    }).anyTimes();
    EasyMock.expect(mockResponse.getStatus()).andAnswer(new IAnswer<Integer>() {
        @Override
        public Integer answer() throws Throwable {
            int result = 0;
            if (responseAttributes != null) {
                result = Integer.parseInt(responseAttributes.get("Status"));
            }
            return result;
        }
    }).anyTimes();

    return mockResponse;
}