List of usage examples for org.springframework.http MediaType TEXT_PLAIN_VALUE
String TEXT_PLAIN_VALUE
To view the source code for org.springframework.http MediaType TEXT_PLAIN_VALUE.
Click Source Link
From source file:com.boyuanitsm.fort.web.rest.AccountResource.java
/** * POST /account/reset_password/init : Send an e-mail to reset the password of the user * * @param mail the mail of the user//from ww w .java 2 s. c o m * @param request the HTTP request * @return the ResponseEntity with status 200 (OK) if the e-mail was sent, or status 400 (Bad Request) if the e-mail address is not registred */ @RequestMapping(value = "/account/reset_password/init", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE) @Timed public ResponseEntity<?> requestPasswordReset(@RequestBody String mail, HttpServletRequest request) { return userService.requestPasswordReset(mail).map(user -> { String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); mailService.sendPasswordResetMail(user, baseUrl); return new ResponseEntity<>("e-mail was sent", HttpStatus.OK); }).orElse(new ResponseEntity<>("e-mail address not registered", HttpStatus.BAD_REQUEST)); }
From source file:com.boyuanitsm.fort.web.rest.AccountResource.java
/** * POST /account/reset_password/finish : Finish to reset the password of the user * * @param keyAndPassword the generated key and the new password * @return the ResponseEntity with status 200 (OK) if the password has been reset, * or status 400 (Bad Request) or 500 (Internal Server Error) if the password could not be reset *///w ww . j a va 2 s.co m @RequestMapping(value = "/account/reset_password/finish", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE) @Timed public ResponseEntity<String> finishPasswordReset(@RequestBody KeyAndPasswordDTO keyAndPassword) { if (!checkPasswordLength(keyAndPassword.getNewPassword())) { return new ResponseEntity<>("Incorrect password", HttpStatus.BAD_REQUEST); } return userService.completePasswordReset(keyAndPassword.getNewPassword(), keyAndPassword.getKey()) .map(user -> new ResponseEntity<String>(HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)); }
From source file:com.rr.wabshs.ui.clients.engagementController.java
/** * The 'checkEngagementDate' GET request will query the sysetm to make sure the visit date entered is not already in the system for the * selected client.//from w w w. ja v a 2 s . c o m * * @param i * @param v * @param enteredDate * @return * @throws Exception */ @RequestMapping(value = "/checkEngagementDate", method = RequestMethod.GET, produces = { MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public String checkEngagementDate(@RequestParam String i, @RequestParam String v, @RequestParam Integer engagementId, @RequestParam String enteredDate) throws Exception { /* Decrypt the url */ decryptObject decrypt = new decryptObject(); Object obj = decrypt.decryptObject(i, v); String[] result = obj.toString().split((",")); int clientId = Integer.parseInt(result[0].substring(4)); SimpleDateFormat inputFormat = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Boolean dateOk = engagementmanager.checkEngagementDate(clientId, programId, engagementId, dateFormat.format(inputFormat.parse(enteredDate)), "visitDate"); return Boolean.toString(dateOk); }
From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java
@Test public void testGetAttributeValueAsString_Number() throws Exception { mockServer.expect(requestTo(baseURL + "/v2/entities/room1/attrs/text/value?type=Room")) .andExpect(method(HttpMethod.GET)).andExpect(header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN_VALUE)) .andRespond(withSuccess("some random text", MediaType.TEXT_PLAIN)); String result = ngsiClient.getAttributeValueAsString("room1", "Room", "text").get(); assertEquals("some random text", result); }
From source file:com.orange.ngsi2.server.Ngsi2BaseController.java
/** * Endpoint get /v2/entities/{entityId}/attrs/{attrName}/value * @param entityId the entity ID// w ww.java 2 s.c o m * @param attrName the attribute name * @param type an optional type of entity * @return the value and http status 200 (ok) or 409 (conflict) * @throws Exception */ @RequestMapping(method = RequestMethod.GET, value = { "/entities/{entityId}/attrs/{attrName}/value" }, produces = MediaType.TEXT_PLAIN_VALUE) final public ResponseEntity<String> retrievePlainTextAttributeValueEndpoint(@PathVariable String entityId, @PathVariable String attrName, @RequestParam Optional<String> type) throws Exception { validateSyntax(entityId, type.orElse(null), attrName); Object value = retrieveAttributeValue(entityId, attrName, type.orElse(null)); return new ResponseEntity<>(objectMapper.writeValueAsString(value), HttpStatus.OK); }
From source file:com.orange.ngsi2.server.Ngsi2BaseController.java
/** * Endpoint put /v2/entities/{entityId}/attrs/{attrName}/value * @param entityId the entity ID// ww w . ja v a 2 s.c o m * @param attrName the attribute name * @param type an optional type of entity * @return http status 204 (No Content) or 409 (conflict) * @throws Exception */ @RequestMapping(method = RequestMethod.PUT, value = { "/entities/{entityId}/attrs/{attrName}/value" }, consumes = MediaType.TEXT_PLAIN_VALUE) final public ResponseEntity updatePlainTextAttributeValueEndpoint(@PathVariable String entityId, @PathVariable String attrName, @RequestParam Optional<String> type, @RequestBody String value) throws Exception { validateSyntax(entityId, type.orElse(null), attrName); updateAttributeValue(entityId, attrName, type.orElse(null), Ngsi2ParsingHelper.parseTextValue(value)); return new ResponseEntity(HttpStatus.NO_CONTENT); }
From source file:com.netflix.genie.web.controllers.JobRestControllerUnitTests.java
/** * Make sure directory forwarding happens when all conditions are met. * * @throws IOException on error/*from w ww. j a va 2s. co m*/ * @throws ServletException on error * @throws GenieException on error */ @Test public void canHandleForwardJobOutputRequestWithSuccess() throws IOException, ServletException, GenieException { this.jobsProperties.getForwarding().setEnabled(true); final String jobId = UUID.randomUUID().toString(); final String forwardedFrom = null; final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); Mockito.doNothing().when(this.genieResourceHttpRequestHandler).handleRequest(request, response); final String jobHostName = UUID.randomUUID().toString(); Mockito.when(this.jobSearchService.getJobHost(jobId)).thenReturn(jobHostName); //Mock parts of the http request final String http = "http"; Mockito.when(request.getScheme()).thenReturn(http); final int port = 8080; Mockito.when(request.getServerPort()).thenReturn(port); final String requestURI = "/" + jobId + "/" + UUID.randomUUID().toString(); Mockito.when(request.getRequestURI()).thenReturn(requestURI); final Set<String> headerNames = Sets.newHashSet(HttpHeaders.ACCEPT); Mockito.when(request.getHeaderNames()).thenReturn(Collections.enumeration(headerNames)); Mockito.when(request.getHeader(HttpHeaders.ACCEPT)).thenReturn(MediaType.APPLICATION_JSON_VALUE); final String requestUrl = UUID.randomUUID().toString(); Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer(requestUrl)); //Mock parts of forward response final HttpResponse forwardResponse = Mockito.mock(HttpResponse.class); final StatusLine statusLine = Mockito.mock(StatusLine.class); Mockito.when(forwardResponse.getStatusLine()).thenReturn(statusLine); final int successCode = 200; Mockito.when(statusLine.getStatusCode()).thenReturn(successCode); final Header contentTypeHeader = Mockito.mock(Header.class); Mockito.when(contentTypeHeader.getName()).thenReturn(HttpHeaders.CONTENT_TYPE); Mockito.when(contentTypeHeader.getValue()).thenReturn(MediaType.TEXT_PLAIN_VALUE); Mockito.when(forwardResponse.getAllHeaders()).thenReturn(new Header[] { contentTypeHeader }); final String text = UUID.randomUUID().toString() + UUID.randomUUID().toString() + UUID.randomUUID().toString(); final ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes(UTF_8)); final HttpEntity entity = Mockito.mock(HttpEntity.class); Mockito.when(entity.getContent()).thenReturn(bis); Mockito.when(forwardResponse.getEntity()).thenReturn(entity); final ByteArrayServletOutputStream bos = new ByteArrayServletOutputStream(); Mockito.when(response.getOutputStream()).thenReturn(bos); final ClientHttpRequestFactory factory = Mockito.mock(ClientHttpRequestFactory.class); final ClientHttpRequest clientHttpRequest = Mockito.mock(ClientHttpRequest.class); Mockito.when(clientHttpRequest.execute()) .thenReturn(new MockClientHttpResponse(text.getBytes(UTF_8), HttpStatus.OK)); Mockito.when(clientHttpRequest.getHeaders()).thenReturn(new HttpHeaders()); Mockito.when(factory.createRequest(Mockito.any(), Mockito.any())).thenReturn(clientHttpRequest); final RestTemplate template = new RestTemplate(factory); final Registry registry = Mockito.mock(Registry.class); final Counter counter = Mockito.mock(Counter.class); Mockito.when(registry.counter(Mockito.anyString())).thenReturn(counter); final JobRestController jobController = new JobRestController(Mockito.mock(JobCoordinatorService.class), this.jobSearchService, Mockito.mock(AttachmentService.class), Mockito.mock(ApplicationResourceAssembler.class), Mockito.mock(ClusterResourceAssembler.class), Mockito.mock(CommandResourceAssembler.class), Mockito.mock(JobResourceAssembler.class), Mockito.mock(JobRequestResourceAssembler.class), Mockito.mock(JobExecutionResourceAssembler.class), Mockito.mock(JobSearchResultResourceAssembler.class), this.hostname, template, this.genieResourceHttpRequestHandler, this.jobsProperties, registry); jobController.getJobOutput(jobId, forwardedFrom, request, response); Assert.assertThat(new String(bos.toByteArray(), UTF_8), Matchers.is(text)); Mockito.verify(request, Mockito.times(1)).getHeader(HttpHeaders.ACCEPT); Mockito.verify(this.jobSearchService, Mockito.times(1)).getJobHost(Mockito.eq(jobId)); Mockito.verify(response, Mockito.never()).sendError(Mockito.anyInt()); Mockito.verify(this.genieResourceHttpRequestHandler, Mockito.never()).handleRequest(request, response); }
From source file:com.rr.wabshs.ui.fundingSource.fundingSourceController.java
/** * The 'checkForDuplicateFundingSource' GET request will query the system to make sure the same funding source does not * exist with the selected fiscal year, start and end dates. * /* w w w .ja va 2 s .c o m*/ * @param i * @param v * @param enteredDate * @return * @throws Exception */ @RequestMapping(value = "/checkForDuplicateFundingSource", method = RequestMethod.GET, produces = { MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public String checkForDuplicateFundingSource(@RequestParam Integer id, @RequestParam String fiscalYear, @RequestParam String startDate, @RequestParam String endDate, @RequestParam String name) throws Exception { boolean fundingSourceOk = fundingsourcemanager.checkForDuplicateFundingSource(programId, id, fiscalYear, startDate, endDate, name); if (fundingSourceOk == true) { return "0"; } else { return "1"; } }
From source file:com.rr.wabshs.ui.expenditureReporting.expenditureReportingController.java
/** * The 'checkForDuplicateReports' GET request will query the system to make sure their is not a same expenditure report in the system. * in the system.// ww w. j av a 2 s . c o m * * @param i * @param v * @param enteredDate * @return * @throws Exception */ @RequestMapping(value = "/checkForDuplicateReports", method = RequestMethod.GET, produces = { MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public String checkForDuplicateReports(@RequestParam Integer id, @RequestParam String contractNumber, @RequestParam String reportingMonth, @RequestParam String reportingYear, @RequestParam String reportNumber, @RequestParam Integer entity1Id, @RequestParam Integer entity2Id, @RequestParam Integer entity3Id) throws Exception { boolean fundingSourceOk = expenditurereportmanager.checkForDuplicateReports(programId, id, contractNumber, reportingMonth, reportingYear, reportNumber, entity1Id, entity2Id, entity3Id); if (fundingSourceOk == true) { return "0"; } else { return "1"; } }
From source file:com.rr.wabshs.ui.fundingSource.fundingSourceController.java
/** * The 'checkForDuplicateFundingSourceContracts' GET request will query the system to make sure their is not a same contract number * in the system./*from w ww . j a v a 2 s . c o m*/ * * @param i * @param v * @param enteredDate * @return * @throws Exception */ @RequestMapping(value = "/checkForDuplicateFundingSourceContracts", method = RequestMethod.GET, produces = { MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public String checkForDuplicateFundingSourceContracts(@RequestParam Integer id, @RequestParam String contractNumber) throws Exception { boolean fundingSourceOk = fundingsourcemanager.checkForDuplicateFundingSourceContracts(programId, id, contractNumber); if (fundingSourceOk == true) { return "0"; } else { return "1"; } }