List of usage examples for org.apache.http.entity ContentType TEXT_PLAIN
ContentType TEXT_PLAIN
To view the source code for org.apache.http.entity ContentType TEXT_PLAIN.
Click Source Link
From source file:com.joyent.manta.client.MantaClient.java
/** * Submits inputs to an already created job, as created by createJob(). * Inputs are object names, and are fed in as a \n separated stream. * Inputs will be processed as they are received. * * @param jobId UUID of the Manta job//from w w w .ja v a2s .c o m * @param inputs stream of paths to Manta objects to be added as inputs * @throws IOException thrown when we are unable to add inputs over the network */ public void addJobInputs(final UUID jobId, final Stream<String> inputs) throws IOException { Validate.notNull(inputs, "Inputs must not be null"); ContentType contentType = ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8); HttpEntity entity = new StringIteratorHttpContent(inputs, contentType); addJobInputs(jobId, entity); }
From source file:org.openstreetmap.josm.plugins.mapillary.oauth.UploadUtils.java
/** * @param file File that is going to be uploaded * @param hash Information attached to the upload * @throws IllegalArgumentException if the hash doesn't contain all the needed keys. */// w ww .j av a2s .com private static void uploadFile(File file, Map<String, String> hash) throws IOException { HttpClientBuilder builder = HttpClientBuilder.create(); HttpPost httpPost = new HttpPost(UPLOAD_URL); try (CloseableHttpClient httpClient = builder.build()) { MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); for (String key : keys) { if (hash.get(key) == null) throw new IllegalArgumentException(); entityBuilder.addPart(key, new StringBody(hash.get(key), ContentType.TEXT_PLAIN)); } entityBuilder.addPart("file", new FileBody(file)); HttpEntity entity = entityBuilder.build(); httpPost.setEntity(entity); try (CloseableHttpResponse response = httpClient.execute(httpPost)) { if (response.getStatusLine().toString().contains("204")) { PluginState.imageUploaded(); Main.info(PluginState.getUploadString() + " (Mapillary)"); } else { Main.info("Upload error"); } } } if (!file.delete()) { Main.error("MapillaryPlugin: File could not be deleted during upload"); } MapillaryUtils.updateHelpText(); }
From source file:ste.web.http.handlers.BugFreeFileHandler.java
@Test public void mime_type_based_on_file_extension() throws Exception { FileHandler h = new FileHandler("src/test/mime"); BasicHttpRequest request = HttpUtils.getSimpleGet("/test.txt"); BasicHttpResponse response = HttpUtils.getBasicResponse(); h.handle(request, response, new HttpSessionContext()); then(response.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK); then(response.getEntity().getContentType().getValue()).isEqualTo(ContentType.TEXT_PLAIN.getMimeType()); request = HttpUtils.getSimpleGet("/test.html"); h.handle(request, response, new HttpSessionContext()); then(response.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK); then(response.getEntity().getContentType().getValue()).isEqualTo(ContentType.TEXT_HTML.getMimeType()); request = HttpUtils.getSimpleGet("/test.png"); h.handle(request, response, new HttpSessionContext()); then(response.getStatusLine().getStatusCode()).isEqualTo(HttpStatus.SC_OK); then(response.getEntity().getContentType().getValue()) .isEqualTo(ContentType.create("image/png").getMimeType()); }