List of usage examples for org.springframework.http MediaType TEXT_PLAIN
MediaType TEXT_PLAIN
To view the source code for org.springframework.http MediaType TEXT_PLAIN.
Click Source Link
From source file:com.github.ffremont.microservices.springboot.node.services.MsService.java
public byte[] getContentOfProperties(String msName) { MasterUrlBuilder builder = new MasterUrlBuilder(cluster, node, masterhost, masterPort, masterCR); builder.setUri(msName + "/properties"); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_PLAIN)); HttpEntity<byte[]> entity = new HttpEntity<>(headers); ResponseEntity<byte[]> response = restTempate.exchange(builder.build(), HttpMethod.GET, entity, byte[].class); return HttpStatus.OK.equals(response.getStatusCode()) ? response.getBody() : null; }
From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java
@Override public String checkStatus(final InstanceConfig config, final URI triggerUrl) throws ResponseStatusException { Preconditions.checkArgument(config != null); Preconditions.checkArgument(triggerUrl != null); final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(), config.getUsername(), config.getPassword()); final URI url = triggerUrl.resolve(triggerUrl.getPath() + STATUS_PATH); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); final HttpEntity<String> httpEntity = new HttpEntity<>(headers); final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class); final HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.OK)) { return response.getBody(); } else {/* w w w . j a v a 2 s . c o m*/ throw new ResponseStatusException( "HttpStatus " + status.toString() + " response received. Load trigger monitoring failed."); } }
From source file:org.client.one.service.OAuthAuthenticationService.java
public boolean registerUserIntranet(String token, Profile profile) throws JsonGenerationException, JsonMappingException, IOException, JSONException { RestOperations rest = new RestTemplate(); HttpHeaders headersA = new HttpHeaders(); headersA.set("Authorization", "Bearer " + token); headersA.setContentType(MediaType.TEXT_PLAIN); ObjectMapper mapper = new ObjectMapper(); HttpEntity<String> request = new HttpEntity<String>(mapper.writeValueAsString(profile), headersA); ResponseEntity<String> responseUpdate = rest.exchange( oauthServerBaseURL + "/resources/profile/registerUser", HttpMethod.POST, request, String.class); JSONObject responseUpdateJSON = new JSONObject(responseUpdate.getBody()); return responseUpdateJSON.getBoolean("success"); }
From source file:access.controller.AccessController.java
/** * Requests a file download that has been prepared by this Access component. This will return the raw bytes of the * resource./*from w ww . jav a 2s . c om*/ * * @param dataId * The Id of the Data Item to get. Assumes this file is ready to be downloaded. */ @SuppressWarnings("rawtypes") @RequestMapping(value = "/file/{dataId}", method = RequestMethod.GET) public ResponseEntity accessFile(@PathVariable(value = "dataId") String dataId, @RequestParam(value = "fileName", required = false) String name) { final String returnAction = "returningFileBytes"; try { // Get the DataResource item DataResource data = accessor.getData(dataId); String fileName = StringUtils.isNullOrEmpty(name) ? dataId : name; pzLogger.log(String.format("Processing Data File for %s", dataId), Severity.INFORMATIONAL, new AuditElement(ACCESS, "beginProcessingFile", dataId)); if (data == null) { pzLogger.log(String.format("Data not found for requested Id %s", dataId), Severity.WARNING); return new ResponseEntity<>( new ErrorResponse(String.format("Data not found: %s", dataId), ACCESS_COMPONENT_NAME), HttpStatus.NOT_FOUND); } if (data.getDataType() instanceof TextDataType) { // Stream the Bytes back TextDataType textData = (TextDataType) data.getDataType(); pzLogger.log(String.format("Returning Bytes for %s", dataId), Severity.INFORMATIONAL, new AuditElement(ACCESS, returnAction, dataId)); return getResponse(MediaType.TEXT_PLAIN, String.format("%s%s", fileName, ".txt"), textData.getContent().getBytes()); } else if (data.getDataType() instanceof PostGISDataType) { // Obtain geoJSON from postGIS StringBuilder geoJSON = getPostGISGeoJSON(data); // Log the Request pzLogger.log(String.format("Returning Bytes for %s of length %s", dataId, geoJSON.length()), Severity.INFORMATIONAL, new AuditElement(ACCESS, returnAction, dataId)); // Stream the Bytes back return getResponse(MediaType.TEXT_PLAIN, String.format("%s%s", fileName, ".geojson"), geoJSON.toString().getBytes()); } else if (!(data.getDataType() instanceof FileRepresentation)) { String message = String.format("File download not available for Data Id %s; type is %s", dataId, data.getDataType().getClass().getSimpleName()); pzLogger.log(message, Severity.WARNING, new AuditElement(ACCESS, "accessBytesError", "")); throw new InvalidInputException(message); } else { byte[] bytes = accessUtilities.getBytesForDataResource(data); // Log the Request pzLogger.log(String.format("Returning Bytes for %s of length %s", dataId, bytes.length), Severity.INFORMATIONAL, new AuditElement(ACCESS, returnAction, dataId)); // Preserve the file extension from the original file. String originalFileName = ((FileRepresentation) data.getDataType()).getLocation().getFileName(); String extension = FilenameUtils.getExtension(originalFileName); // Stream the Bytes back return getResponse(MediaType.APPLICATION_OCTET_STREAM, String.format("%s.%s", fileName, extension), bytes); } } catch (Exception exception) { String error = String.format("Error fetching Data %s: %s", dataId, exception.getMessage()); LOGGER.error(error, exception); pzLogger.log(error, Severity.ERROR, new AuditElement(ACCESS, "errorAccessingBytes", dataId)); return new ResponseEntity<>( new ErrorResponse("Error fetching File: " + exception.getMessage(), ACCESS_COMPONENT_NAME), HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:org.wcy123.ProtobufMessageConverter.java
@Override protected void writeInternal(Message message, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { MediaType contentType = outputMessage.getHeaders().getContentType(); Charset charset = getCharset(contentType); if (MediaType.TEXT_HTML.isCompatibleWith(contentType)) { throw new UnsupportedOperationException("not supported yet"); } else if (MediaType.APPLICATION_JSON.isCompatibleWith(contentType)) { final OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputMessage.getBody(), charset); printer.appendTo(message, outputStreamWriter); outputStreamWriter.flush();/*from w w w . j a v a 2 s . c o m*/ } else if (MediaType.TEXT_PLAIN.isCompatibleWith(contentType)) { final OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputMessage.getBody(), charset); TextFormat.print(message, outputStreamWriter); outputStreamWriter.flush(); } else if (MediaType.APPLICATION_XML.isCompatibleWith(contentType)) { throw new UnsupportedOperationException("not supported yet"); } else if (PROTOBUF.isCompatibleWith(contentType)) { setProtoHeader(outputMessage, message); FileCopyUtils.copy(message.toByteArray(), outputMessage.getBody()); } }
From source file:org.client.one.service.OAuthAuthenticationService.java
public boolean registerUserWS(String token, Profile profile) throws JsonGenerationException, JsonMappingException, IOException, JSONException { RestOperations rest = new RestTemplate(); HttpHeaders headersA = new HttpHeaders(); headersA.set("Authorization", "Bearer " + token); headersA.setContentType(MediaType.TEXT_PLAIN); ObjectMapper mapper = new ObjectMapper(); HttpEntity<String> request = new HttpEntity<String>( mapper.writeValueAsString(new RequestProfile(token, profile)), headersA); ResponseEntity<String> responseUpdate = rest.exchange( appThreeServicesBaseURL + "/resources/profile/registerUser", HttpMethod.POST, request, String.class); JSONObject responseUpdateJSON = new JSONObject(responseUpdate.getBody()); return responseUpdateJSON.getBoolean("success"); }
From source file:net.sf.jsog.spring.StringJsogHttpMessageConverterTest.java
@Test public void testCanWriteNotAppJson() { assertFalse(instance.canWrite(JSOG.class, MediaType.TEXT_PLAIN)); }
From source file:net.solarnetwork.node.setup.web.SettingsController.java
@RequestMapping(value = "/export", method = RequestMethod.GET) @ResponseBody/* w ww .ja va 2 s. co m*/ public void exportSettings(@RequestParam(required = false, value = "backup") String backupKey, HttpServletResponse response) throws IOException { final SettingsService service = settingsServiceTracker.service(); if (service != null) { response.setContentType(MediaType.TEXT_PLAIN.toString()); response.setHeader("Content-Disposition", "attachment; filename=settings" + (backupKey == null ? "" : "_" + backupKey) + ".txt"); if (backupKey != null) { Reader r = service.getReaderForBackup(new SettingsBackup(backupKey, null)); if (r != null) { FileCopyUtils.copy(r, response.getWriter()); } } else { service.exportSettingsCSV(response.getWriter()); } } }