Example usage for org.springframework.http HttpStatus value

List of usage examples for org.springframework.http HttpStatus value

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus value.

Prototype

int value

To view the source code for org.springframework.http HttpStatus value.

Click Source Link

Usage

From source file:org.mitre.openid.connect.view.ClientInformationResponseView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) {/* w  ww .  j  av a  2  s . c  o  m*/

    response.setContentType(MediaType.APPLICATION_JSON_VALUE);

    RegisteredClient c = (RegisteredClient) model.get("client");
    //OAuth2AccessTokenEntity token = (OAuth2AccessTokenEntity) model.get("token");
    //String uri = (String)model.get("uri"); //request.getRequestURL() + "/" + c.getClientId();

    HttpStatus code = (HttpStatus) model.get(HttpCodeView.CODE);
    if (code == null) {
        code = HttpStatus.OK;
    }
    response.setStatus(code.value());

    JsonObject o = ClientDetailsEntityJsonProcessor.serialize(c);

    try {
        Writer out = response.getWriter();
        gson.toJson(o, out);
    } catch (JsonIOException e) {

        logger.error("JsonIOException in ClientInformationResponseView.java: ", e);

    } catch (IOException e) {

        logger.error("IOException in ClientInformationResponseView.java: ", e);

    }

}

From source file:com.envision.envservice.rest.CourseResource.java

@GET
@Path("/feedback/{courseId}")
@Produces(MediaType.APPLICATION_JSON)/*from  w  w w.  jav a 2  s. co m*/
public Response queryFeedback(@PathParam("courseId") int courseId) throws ServiceException {
    HttpStatus status = HttpStatus.OK;
    String response = JSON.toJSONString(courseService.feedback(courseId), JSONFilter.NULLFILTER);

    return Response.status(status.value()).entity(response).build();
}

From source file:com.envision.envservice.rest.CourseResource.java

@GET
@Produces(MediaType.APPLICATION_JSON)/*from  w  w  w  .  j  a  v  a2s.  c  o m*/
public Response queryAll() throws Exception {
    HttpStatus status = HttpStatus.OK;
    String response = JSON.toJSONString(courseService.queryAll(), JSONFilter.NULL_UNDERLINE_FILTERS);

    return Response.status(status.value()).entity(response).build();
}

From source file:org.mitre.openid.connect.view.JsonEntityView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) {//from  w w w  .  j  av  a2s . com

    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    response.setCharacterEncoding("UTF-8");

    HttpStatus code = (HttpStatus) model.get(HttpCodeView.CODE);
    if (code == null) {
        code = HttpStatus.OK; // default to 200
    }

    response.setStatus(code.value());

    try {

        Writer out = response.getWriter();
        Object obj = model.get(ENTITY);
        gson.toJson(obj, out);

    } catch (IOException e) {

        logger.error("IOException in JsonEntityView.java: ", e);

    }
}

From source file:com.epam.ta.reportportal.commons.exception.rest.RestExceptionHandler.java

private void applyStatusIfPossible(ServletWebRequest webRequest, HttpStatus status) {
    if (!WebUtils.isIncludeRequest(webRequest.getRequest())) {
        webRequest.getResponse().setStatus(status.value());
    }/*from www  .  j av  a2  s.  co m*/
}

From source file:org.mitre.uma.view.ResourceSetEntityView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) {/*from w ww.j  av a  2  s.c o  m*/

    response.setContentType("application/json");

    HttpStatus code = (HttpStatus) model.get("code");
    if (code == null) {
        code = HttpStatus.OK; // default to 200
    }

    response.setStatus(code.value());

    String location = (String) model.get("location");
    if (!Strings.isNullOrEmpty(location)) {
        response.setHeader(HttpHeaders.LOCATION, location);
    }

    try {

        Writer out = response.getWriter();
        ResourceSet rs = (ResourceSet) model.get("entity");

        JsonObject o = new JsonObject();

        o.addProperty("_id", rs.getId().toString()); // send the id as a string
        o.addProperty("user_access_policy_uri", config.getIssuer() + "manage/resource/" + rs.getId());
        o.addProperty("name", rs.getName());
        o.addProperty("uri", rs.getUri());
        o.addProperty("type", rs.getType());
        o.add("scopes", JsonUtils.getAsArray(rs.getScopes()));
        o.addProperty("icon_uri", rs.getIconUri());

        gson.toJson(o, out);

    } catch (IOException e) {

        logger.error("IOException in ResourceSetEntityView.java: ", e);

    }
}

From source file:org.mitre.uma.view.ResourceSetEntityAbbreviatedView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) {//  www.jav  a 2  s .  c o m

    response.setContentType("application/json");

    HttpStatus code = (HttpStatus) model.get(HttpCodeView.CODE);
    if (code == null) {
        code = HttpStatus.OK; // default to 200
    }

    response.setStatus(code.value());

    String location = (String) model.get(LOCATION);
    if (!Strings.isNullOrEmpty(location)) {
        response.setHeader(HttpHeaders.LOCATION, location);
    }

    try {

        Writer out = response.getWriter();
        ResourceSet rs = (ResourceSet) model.get(JsonEntityView.ENTITY);

        JsonObject o = new JsonObject();

        o.addProperty("_id", rs.getId().toString()); // set the ID to a string
        o.addProperty("user_access_policy_uri", config.getIssuer() + "manage/user/policy/" + rs.getId());

        gson.toJson(o, out);

    } catch (IOException e) {

        logger.error("IOException in ResourceSetEntityView.java: ", e);

    }
}

From source file:org.mitre.discovery.view.WebfingerView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) {/*w w w  . ja v  a2s. c  om*/

    response.setContentType("application/jrd+json");

    HttpStatus code = (HttpStatus) model.get(HttpCodeView.CODE);
    if (code == null) {
        code = HttpStatus.OK; // default to 200
    }

    response.setStatus(code.value());

    try {

        String resource = (String) model.get("resource");
        String issuer = (String) model.get("issuer");

        JsonObject obj = new JsonObject();
        obj.addProperty("subject", resource);

        JsonArray links = new JsonArray();
        JsonObject link = new JsonObject();
        link.addProperty("rel", "http://openid.net/specs/connect/1.0/issuer");
        link.addProperty("href", issuer);
        links.add(link);

        obj.add("links", links);

        Writer out = response.getWriter();
        gson.toJson(obj, out);

    } catch (IOException e) {

        logger.error("IOException in JsonEntityView.java: ", e);

    }
}

From source file:com.envision.envservice.rest.UserCaseCommentResource.java

@GET
@Path("{caseId}")
@Produces(MediaType.APPLICATION_JSON)/*from w  w  w  .  jav  a 2s.  c om*/
public Response queryByCaseId(@PathParam("caseId") int caseId) throws UnsupportedEncodingException {
    HttpStatus status = HttpStatus.OK;
    String response = JSON.toJSONString(userCaseCommentService.queryByCaseId(caseId),
            JSONFilter.NULL_UNDERLINE_FILTERS);

    return Response.status(status.value()).entity(response).build();
}

From source file:com.github.lynxdb.server.api.http.handlers.EpError.java

@RequestMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity error(HttpServletRequest request, HttpServletResponse response) {

    HttpStatus status = HttpStatus.valueOf((int) request.getAttribute("javax.servlet.error.status_code"));

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode error = mapper.createObjectNode();
    error.put("code", status.value());
    error.put("message", status.getReasonPhrase());
    error.put("details", getErrorAttributes(request, true).get("message").toString());
    if (getErrorAttributes(request, true).get("exception") != null) {
        error.put("trace", getErrorAttributes(request, true).get("exception").toString() + "\n"
                + getErrorAttributes(request, true).get("trace").toString());
    }//w w  w .  j a v a2s  .  co m

    return ResponseEntity.status(status).body(error.toString());
}