List of usage examples for org.springframework.http MediaType APPLICATION_JSON_VALUE
String APPLICATION_JSON_VALUE
To view the source code for org.springframework.http MediaType APPLICATION_JSON_VALUE.
Click Source Link
From source file:com.kajj.tools.logviewer.LogViewerRestController.java
@RequestMapping(value = "/logs", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<List<String>> getlogFileNames() { final List<String> logFileNames = logRepository.getLogFileNames(); return new ResponseEntity(logFileNames, HttpStatus.OK); }
From source file:net.bafeimao.umbrella.web.controller.CaptchaController.java
@RequestMapping(value = "/match", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody//from www . j av a 2s .com public String match(HttpSession session, String text) { String captchaText = session.getAttribute(Constants.KAPTCHA_SESSION_KEY).toString(); if (text != null && text.equals(captchaText)) { return "{\"result\":true}"; } else { return "{\"result\":false}"; } }
From source file:com.github.lynxdb.server.api.http.handlers.EpSuggest.java
@RequestMapping(path = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity post(@RequestBody @Valid SuggestRequest _request, Authentication _authentication, BindingResult _bindingResult) {/*w w w.j a v a 2s .c om*/ if (_bindingResult.hasErrors()) { ArrayList<String> errors = new ArrayList(); _bindingResult.getFieldErrors().forEach((FieldError t) -> { errors.add(t.getField() + ": " + t.getDefaultMessage()); }); return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, errors.toString(), null).response(); } return response(_request, _authentication); }
From source file:org.openlmis.fulfillment.web.BaseTransferPropertiesControllerIntegrationTest.java
@Test public void shouldCreateProperties() { // given/*from w w w . j a v a 2s. c om*/ T properties = generateProperties(); given(transferPropertiesRepository.save(any(TransferProperties.class))) .willAnswer(new SaveAnswer<TransferProperties>()); // when restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(MediaType.APPLICATION_JSON_VALUE).body(toDto(properties)).when().post(RESOURCE_URL) .then().statusCode(201); // then assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations()); }
From source file:se.skltp.cooperation.web.rest.v1.controller.ServiceDomainController.java
/** * GET /serviceDomains -> get all the serviceDomains as json *//*from ww w . j a va2 s.c o m*/ @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public List<ServiceDomainDTO> getAllAsJson(@RequestParam(required = false) String namespace) { log.debug("REST request to get all ServiceDomains as json"); return getAll(namespace); }
From source file:org.note.application.NoteController.java
/** * This method is used to get all the notes added into map * @return/*from w w w . j a v a2 s . co m*/ * @throws ServiceException * @throws IOException */ @ExceptionHandler(ServiceException.class) @RequestMapping(value = "/get/ALL", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ArrayList<Note> getAll() throws ServiceException, IOException { LOGGER.info("Getting all the note details"); ArrayList<Note> notes = service.getAll(); LOGGER.info("Successfully got all the notes"); return notes; }
From source file:nc.noumea.mairie.appock.ws.RadiWSConsumer.java
private ClientResponse createAndFireRequest(Map<String, String> parameters, String url, boolean isPost, String postContent) throws Exception { Client client = Client.create();/*from w w w . jav a 2s . co m*/ WebResource webResource = client.resource(url); for (String key : parameters.keySet()) { webResource = webResource.queryParam(key, parameters.get(key)); } ClientResponse response = null; try { if (isPost) if (postContent == null) response = webResource.type(MediaType.APPLICATION_JSON_VALUE).post(ClientResponse.class); else response = webResource.type(MediaType.APPLICATION_JSON_VALUE).post(ClientResponse.class, postContent); else response = webResource.type(MediaType.APPLICATION_JSON_VALUE).get(ClientResponse.class); } catch (ClientHandlerException ex) { throw new Exception(String.format("An error occured when querying '%s'.", url), ex); } return response; }
From source file:io.getlime.security.powerauth.app.server.service.controller.RESTResponseExceptionResolver.java
@Override protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) { try {//from w w w .j a v a 2s . c om // Build the error list RESTErrorModel error = new RESTErrorModel(); error.setCode("ERR_SPRING_JAVA"); error.setMessage(exception.getMessage()); error.setLocalizedMessage(exception.getLocalizedMessage()); List<RESTErrorModel> errorList = new LinkedList<>(); errorList.add(error); // Prepare the response RESTResponseWrapper<List<RESTErrorModel>> errorResponse = new RESTResponseWrapper<>("ERROR", errorList); // Write the response in JSON and send it ObjectMapper mapper = new ObjectMapper(); String responseString = mapper.writeValueAsString(errorResponse); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.setCharacterEncoding(StandardCharsets.UTF_8.name()); response.setContentType(MediaType.APPLICATION_JSON_VALUE); response.getOutputStream().print(responseString); response.flushBuffer(); } catch (IOException e) { // Response object does have an output stream here } return new ModelAndView(); }
From source file:org.exoplatform.acceptance.rest.JsonErrorHandler.java
/** * Catch HttpMessageNotReadableException to log it (helps to diagnose errors and attacks on REST services). * * @param ex The exception trapped/* w w w. jav a2s . c om*/ * @return A standardized {@link org.exoplatform.acceptance.rest.JsonErrorResponse} * @throws java.io.IOException if any. */ @ExceptionHandler(HttpMessageNotReadableException.class) @RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody public JsonErrorResponse handleHttpMessageNotReadableException(HttpMessageNotReadableException ex) throws IOException { LOGGER.warn("Http Message Not Readable : {}", ex.getMessage()); return new JsonErrorResponse(ex); }
From source file:com.jvoid.core.controller.HomeController.java
@RequestMapping(value = "/login", method = RequestMethod.POST) public @ResponseBody String loginToJvoid( @RequestParam(required = false, value = "params") JSONObject jsonParams) { System.out.println("Login:jsonParams=>" + jsonParams.toString()); RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(ServerUris.CUSTOMER_SERVER_URI + URIConstants.GET_CUSTOMER_BY_EMAIL) .queryParam("params", jsonParams); HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, entity, String.class); return returnString.getBody(); }