List of usage examples for org.springframework.http MediaType APPLICATION_JSON
MediaType APPLICATION_JSON
To view the source code for org.springframework.http MediaType APPLICATION_JSON.
Click Source Link
From source file:fi.helsinki.opintoni.web.rest.privateapi.portfolio.PrivateContactInformationResourcePermissionTest.java
@Test public void thatUserCannotUpdateContactInformationFromPrivateApiThatSheDoesNotOwn() throws Exception { UpdateKeywordsRequest updateKeywordsRequest = new UpdateKeywordsRequest(); mockMvc.perform(post(RESOURCE_URL).with(securityContext(teacherSecurityContext())) .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON) .content(WebTestUtils.toJsonBytes(updateKeywordsRequest)).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isNotFound()); }
From source file:cz.muni.fi.mushroomhunter.restclient.MushroomUpdateSwingWorker.java
@Override protected Integer doInBackground() throws Exception { DefaultTableModel model = (DefaultTableModel) restClient.getTblMushroom().getModel(); int selectedRow = restClient.getTblMushroom().getSelectedRow(); RestTemplate restTemplate = new RestTemplate(); String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); List<MediaType> mediaTypeList = new ArrayList<>(); mediaTypeList.add(MediaType.ALL);/*from w w w . jav a2 s . co m*/ headers.setAccept(mediaTypeList); headers.add("Authorization", "Basic " + base64Creds); HttpEntity request = new HttpEntity<>(headers); ResponseEntity<MushroomDto> responseEntity = restTemplate.exchange( RestClient.SERVER_URL + "pa165/rest/mushroom/" + RestClient.getMushroomIDs().get(selectedRow), HttpMethod.GET, request, MushroomDto.class); MushroomDto mushroomDto = responseEntity.getBody(); mushroomDto.setName(restClient.getTfMushroomName().getText()); SimpleDateFormat formatter = new SimpleDateFormat("dd-MMMM-yyyy", new Locale("en_US")); //to create date object only month is used, day and year are fixed values String dateInString = "01-" + restClient.getComboBoxMushroomStartOfOccurence().getSelectedItem().toString() + "-2000"; mushroomDto.setStartOfOccurence(formatter.parse(dateInString)); //to create date object only month is used, day and year are fixed values dateInString = "01-" + restClient.getComboBoxMushroomEndOfOccurence().getSelectedItem().toString() + "-2000"; mushroomDto.setEndOfOccurence(formatter.parse(dateInString)); ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(mushroomDto); request = new HttpEntity(json, headers); restTemplate.exchange(RestClient.SERVER_URL + "pa165/rest/mushroom", HttpMethod.PUT, request, MushroomDto.class); return selectedRow; }
From source file:org.zalando.github.spring.UsersTemplateTest.java
@Test public void getEmails() throws Exception { mockServer.expect(requestTo("https://api.github.com/user/emails")).andExpect(method(HttpMethod.GET)) // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN")) .andRespond(withSuccess(new ClassPathResource("listEmails.json", getClass()), MediaType.APPLICATION_JSON)); List<Email> emailList = usersTemplate.listEmails(); Assertions.assertThat(emailList).isNotNull(); Assertions.assertThat(emailList.size()).isEqualTo(1); }
From source file:fi.helsinki.opintoni.web.rest.privateapi.UsefulLinksResourcePermissionsTest.java
@Test public void thatUserCannotUpdateUsefulLinksSheDoesNotOwn() throws Exception { UsefulLinkDto usefulLinkDto = createValidUsefulLink(); mockMvc.perform(put("/api/private/v1/usefullinks/1").with(securityContext(teacherSecurityContext())) .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON) .content(WebTestUtils.toJsonBytes(usefulLinkDto)).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isForbidden()); }
From source file:io.getlime.push.service.fcm.FcmClient.java
/** * Create a new FCM service client.//from w w w . java2 s . c o m * @param serverKey Server key tp be used. */ public FcmClient(String serverKey) { headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.set("Authorization", "key=" + serverKey); restTemplate = new AsyncRestTemplate(); }
From source file:fi.helsinki.opintoni.exception.GlobalExceptionHandlersTest.java
@Test public void thatNotFoundIsReturned() throws Exception { mockMvc.perform(/*from www. j a v a 2s . c om*/ get("/notfound").with(securityContext(studentSecurityContext())).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isNotFound()).andExpect(jsonPath("$.error").value("Not found")); }
From source file:fi.helsinki.opintoni.web.rest.privateapi.portfolio.PrivateComponentVisibilityResourcePermissionTest.java
@Test public void thatUserCannotUpdateComponentVisibilityThatSheDoesNotOwn() throws Exception { UpdateComponentVisibilityRequest request = new UpdateComponentVisibilityRequest(); mockMvc.perform(post(RESOURCE_URL).with(securityContext(teacherSecurityContext())) .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON) .content(WebTestUtils.toJsonBytes(request)).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isNotFound()); }
From source file:fi.helsinki.opintoni.web.rest.privateapi.UnicafeFavoriteResourceTest.java
private void insertUnicafeFavorite(Integer restaurantId, ResultMatcher expectedResult) throws Exception { UnicafeFavoriteRequest unicafeFavoriteRequest = new UnicafeFavoriteRequest(); unicafeFavoriteRequest.restaurantId = restaurantId; mockMvc.perform(post("/api/private/v1/favorites/unicafe").with(securityContext(studentSecurityContext())) .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON) .content(WebTestUtils.toJsonBytes(unicafeFavoriteRequest))).andExpect(expectedResult); }
From source file:fi.helsinki.opintoni.web.rest.privateapi.UsefulLinksResourceTest.java
@Test public void thatUsefulLinksReturnCorrectResponse() throws Exception { mockMvc.perform(get("/api/private/v1/usefullinks").with(securityContext(studentSecurityContext())) .characterEncoding("UTF-8").contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) .andExpect(content().contentType(WebConstants.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$").isArray()).andExpect(jsonPath("$", hasSize(2))) .andExpect(jsonPath("$[0].id").value(1)) .andExpect(jsonPath("$[0].createdDate").value(any(Number.class))) .andExpect(jsonPath("$[0].url").value("http://www.google.com")) .andExpect(jsonPath("$[0].description").value("Google")) .andExpect(jsonPath("$[0].type").value("USER_DEFINED")).andExpect(jsonPath("$[1].id").value(2)) .andExpect(jsonPath("$[1].createdDate").value(any(Number.class))) .andExpect(jsonPath("$[1].url").value("http://www.helsinki.fi")) .andExpect(jsonPath("$[1].description").value("Helsinki University")) .andExpect(jsonPath("$[1].type").value("USER_DEFINED")); }
From source file:com.sra.biotech.submittool.persistence.client.SubmitExceptionHandler.java
@ExceptionHandler({ InvalidRequestException.class }) protected ResponseEntity<Object> handleInvalidRequest(RuntimeException e, WebRequest request) { InvalidRequestException ire = (InvalidRequestException) e; List<FieldErrorResource> fieldErrorResources = new ArrayList<>(); List<FieldError> fieldErrors = ire.getErrors().getFieldErrors(); for (FieldError fieldError : fieldErrors) { FieldErrorResource fieldErrorResource = new FieldErrorResource(); fieldErrorResource.setResource(fieldError.getObjectName()); fieldErrorResource.setField(fieldError.getField()); fieldErrorResource.setCode(fieldError.getCode()); fieldErrorResource.setMessage(fieldError.getDefaultMessage()); fieldErrorResources.add(fieldErrorResource); }/*from w ww. ja va 2 s . c om*/ ErrorResource error = new ErrorResource("InvalidRequest", ire.getMessage()); error.setFieldErrors(fieldErrorResources); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(e, error, headers, HttpStatus.UNPROCESSABLE_ENTITY, request); }