Example usage for org.springframework.util MimeTypeUtils APPLICATION_JSON_VALUE

List of usage examples for org.springframework.util MimeTypeUtils APPLICATION_JSON_VALUE

Introduction

In this page you can find the example usage for org.springframework.util MimeTypeUtils APPLICATION_JSON_VALUE.

Prototype

String APPLICATION_JSON_VALUE

To view the source code for org.springframework.util MimeTypeUtils APPLICATION_JSON_VALUE.

Click Source Link

Document

A String equivalent of MimeTypeUtils#APPLICATION_JSON .

Usage

From source file:org.craftercms.cstudio.publishing.servlet.StatusMonitoringServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType(MimeTypeUtils.APPLICATION_JSON_VALUE);
    response.getWriter().println("{ status: \"" + statusMessage + "\" }");
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:com.temetra.vroomapi.RouteController.java

@RequestMapping(value = "/route", produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public JsonNode route(@RequestParam(value = "loc") String[] locs,
        @RequestParam(value = "startAtFirst", defaultValue = "true") boolean startAtFirst,
        @RequestParam(value = "endAtLast", defaultValue = "false") boolean endAtLast,
        @RequestParam(value = "includeGeometry", defaultValue = "false") boolean includeGeometry)
        throws Exception {
    long millis = System.currentTimeMillis();

    File vroomBinFile = new File(vroomBinary);
    if (!vroomBinFile.exists()) {
        log.error("Vroom binary file doesn't exist");
        throw new Exception("Vroom binary file doesn't exist");
    }//from ww w.j av  a  2s. c om

    if (!vroomBinFile.canExecute()) {
        log.error("Cannot execute Vroom binary file");
        throw new Exception("Cannot execute Vroom binary file");
    }

    if (locs.length < 2) {
        log.error("Zero or one location sent");
        throw new Exception("Must send more than one location");
    }

    List<String> progArgs = new ArrayList<>();
    progArgs.add("./" + vroomBinFile.getName());
    if (startAtFirst) {
        progArgs.add("-s");
    }
    if (endAtLast) {
        progArgs.add("-e");
    }
    if (includeGeometry) {
        progArgs.add("-g");
    }

    progArgs.add("loc=" + Joiner.on("&loc=").join(locs) + "");
    log.info("Run (" + millis + "): " + Joiner.on(' ').join(progArgs));

    StringBuilder output = new StringBuilder();
    ProcessBuilder builder = new ProcessBuilder(progArgs);
    builder.directory(vroomBinFile.getParentFile());
    builder.redirectErrorStream(true);
    Process process = builder.start();

    try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
        String line;
        while ((line = reader.readLine()) != null) {
            output.append(line);
        }
        process.waitFor();
    }

    log.info("Output (" + millis + "): " + output.toString());
    return jsonMapper.readTree(output.toString());
}

From source file:de.codecentric.boot.admin.journal.web.JournalController.java

@RequestMapping(path = "/api/journal", produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public Collection<ClientApplicationEvent> getJournal() {
    return eventJournal.getEvents();
}

From source file:de.codecentric.boot.admin.notify.filter.web.NotificationFilterController.java

@RequestMapping(path = "/api/notifications/filters", method = {
        RequestMethod.GET }, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public Map<String, NotificationFilter> getFilters() {
    return filteringNotifier.getNotificationFilters();
}

From source file:org.tec.webapp.web.view.JSONView.java

/**
 * {@inheritDoc}/*w  ww.  j a  v  a2s  . co  m*/
 */
@Override()
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    try {
        JSONSerializable json = (JSONSerializable) model.get(JSONModelAndView.ERROR_KEY);

        if (json != null) {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "failed to process response");
        } else {
            json = (JSONSerializable) model.get(JSONModelAndView.JSON_KEY);

            if (json != null) {
                if (mLogger.isDebugEnabled()) {
                    mLogger.debug("JSON Response\n" + json.toJSON());
                }
                response.setContentType(MimeTypeUtils.APPLICATION_JSON_VALUE);
                PrintWriter pw = response.getWriter();
                pw.write(json.toJSON());
                pw.flush();
            } else // null json for controllers that usurp the response or didn't intend to
            {
                mLogger.warn("null json object");
            }
        }
    } catch (Exception e) {
        mLogger.error("error", e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "failed to process response");
    }
}

From source file:de.codecentric.boot.admin.notify.filter.web.NotificationFilterController.java

@RequestMapping(path = "/api/notifications/filters", method = {
        RequestMethod.POST }, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public ResponseEntity<?> addFilter(@RequestParam(name = "id", required = false) String id,
        @RequestParam(name = "name", required = false) String name,
        @RequestParam(name = "ttl", required = false, defaultValue = "-1") long ttl) {
    if (hasText(id) || hasText(name)) {
        NotificationFilter filter = createFilter(id, name, ttl);
        String filterId = filteringNotifier.addFilter(filter);
        return ResponseEntity.ok(Collections.singletonMap(filterId, filter));
    } else {// w w w  .  j ava  2  s.  c  om
        return ResponseEntity.badRequest().body("Either 'id' or 'name' must be set");
    }
}

From source file:org.mitre.uma.web.UserClaimSearchHelper.java

@RequestMapping(method = RequestMethod.GET, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String search(@RequestParam(value = "identifier") String email, Model m, Authentication auth,
        HttpServletRequest req) {/*from www.  j a  v  a 2  s.  co  m*/

    // check locally first
    UserInfo localUser = userInfoService.getByEmailAddress(email);

    if (localUser != null) {
        Map<String, Object> e = new HashMap<>();
        e.put("issuer", ImmutableSet.of(config.getIssuer()));
        e.put("name", "email");
        e.put("value", localUser.getEmail());

        Map<String, Object> ev = new HashMap<>();
        ev.put("issuer", ImmutableSet.of(config.getIssuer()));
        ev.put("name", "email_verified");
        ev.put("value", localUser.getEmailVerified());

        Map<String, Object> s = new HashMap<>();
        s.put("issuer", ImmutableSet.of(config.getIssuer()));
        s.put("name", "sub");
        s.put("value", localUser.getSub());

        m.addAttribute(JsonEntityView.ENTITY, ImmutableSet.of(e, ev, s));
        return JsonEntityView.VIEWNAME;
    } else {

        // otherwise do a webfinger lookup
        IssuerServiceResponse resp = webfingerIssuerService.getIssuer(req);

        if (resp != null && resp.getIssuer() != null) {
            // we found an issuer, return that
            Map<String, Object> e = new HashMap<>();
            e.put("issuer", ImmutableSet.of(resp.getIssuer()));
            e.put("name", "email");
            e.put("value", email);

            Map<String, Object> ev = new HashMap<>();
            ev.put("issuer", ImmutableSet.of(resp.getIssuer()));
            ev.put("name", "email_verified");
            ev.put("value", true);

            m.addAttribute(JsonEntityView.ENTITY, ImmutableSet.of(e, ev));
            return JsonEntityView.VIEWNAME;
        } else {
            m.addAttribute(HttpCodeView.CODE, HttpStatus.NOT_FOUND);
            return JsonErrorView.VIEWNAME;
        }
    }
}

From source file:com.reactivetechnologies.platform.rest.depre.SimpleHttpServerBean.java

/**
 * Send a JSON response with HTTP 200/*from w w  w.  java 2 s  . co  m*/
 * @param json
 * @return
 */
protected static Response success(String json) {
    return newFixedLengthResponse(Status.OK, MimeTypeUtils.APPLICATION_JSON_VALUE, json);
}

From source file:org.mitre.uma.web.ClaimsAPI.java

@RequestMapping(value = "", method = RequestMethod.GET, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String getResourceSetsForCurrentUser(Model m, Authentication auth) {

    Collection<ResourceSet> resourceSets = resourceSetService.getAllForOwner(auth.getName());

    m.addAttribute(JsonEntityView.ENTITY, resourceSets);

    return JsonEntityView.VIEWNAME;
}

From source file:org.mitre.uma.web.PermissionRegistrationEndpoint.java

@RequestMapping(method = RequestMethod.POST, consumes = MimeTypeUtils.APPLICATION_JSON_VALUE, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String getPermissionTicket(@RequestBody String jsonString, Model m, Authentication auth) {

    ensureOAuthScope(auth, SystemScopeService.UMA_PROTECTION_SCOPE);

    try {//from www .j  av  a2 s. com

        // parse the permission request

        JsonElement el = parser.parse(jsonString);
        if (el.isJsonObject()) {
            JsonObject o = el.getAsJsonObject();

            Long rsid = getAsLong(o, "resource_set_id");
            Set<String> scopes = getAsStringSet(o, "scopes");

            if (rsid == null || scopes == null || scopes.isEmpty()) {
                // missing information
                m.addAttribute("code", HttpStatus.BAD_REQUEST);
                m.addAttribute("errorMessage",
                        "Missing required component of permission registration request.");
                return JsonErrorView.VIEWNAME;
            }

            // trim any restricted scopes
            Set<SystemScope> scopesRequested = scopeService.fromStrings(scopes);
            scopesRequested = scopeService.removeRestrictedAndReservedScopes(scopesRequested);
            scopes = scopeService.toStrings(scopesRequested);

            ResourceSet resourceSet = resourceSetService.getById(rsid);

            // requested resource set doesn't exist
            if (resourceSet == null) {
                m.addAttribute("code", HttpStatus.NOT_FOUND);
                m.addAttribute("errorMessage", "Requested resource set not found: " + rsid);
                return JsonErrorView.VIEWNAME;
            }

            // authorized user of the token doesn't match owner of the resource set
            if (!resourceSet.getOwner().equals(auth.getName())) {
                m.addAttribute("code", HttpStatus.FORBIDDEN);
                m.addAttribute("errorMessage",
                        "Party requesting permission is not owner of resource set, expected "
                                + resourceSet.getOwner() + " got " + auth.getName());
                return JsonErrorView.VIEWNAME;
            }

            // create the permission
            PermissionTicket permission = permissionService.createTicket(resourceSet, scopes);

            if (permission != null) {
                // we've created the permission, return the ticket
                JsonObject out = new JsonObject();
                out.addProperty("ticket", permission.getTicket());
                m.addAttribute("entity", out);

                m.addAttribute("code", HttpStatus.CREATED);

                return JsonEntityView.VIEWNAME;
            } else {
                // there was a failure creating the permission object

                m.addAttribute("code", HttpStatus.INTERNAL_SERVER_ERROR);
                m.addAttribute("errorMessage", "Unable to save permission and generate ticket.");

                return JsonErrorView.VIEWNAME;
            }

        } else {
            // malformed request
            m.addAttribute("code", HttpStatus.BAD_REQUEST);
            m.addAttribute("errorMessage", "Malformed JSON request.");
            return JsonErrorView.VIEWNAME;
        }
    } catch (JsonParseException e) {
        // malformed request
        m.addAttribute("code", HttpStatus.BAD_REQUEST);
        m.addAttribute("errorMessage", "Malformed JSON request.");
        return JsonErrorView.VIEWNAME;
    }

}