List of usage examples for org.apache.http.entity ContentType DEFAULT_TEXT
ContentType DEFAULT_TEXT
To view the source code for org.apache.http.entity ContentType DEFAULT_TEXT.
Click Source Link
From source file:interoperabilite.webservice.fluent.FluentRequests.java
public static void main(String[] args) throws Exception { // Execute a GET with timeout settings and return response content as String. Request.Get("http://somehost/").connectTimeout(1000).socketTimeout(1000).execute().returnContent() .asString();//from w w w . j a v a2 s . c om // Execute a POST with the 'expect-continue' handshake, using HTTP/1.1, // containing a request body as String and return response content as byte array. Request.Post("http://somehost/do-stuff").useExpectContinue().version(HttpVersion.HTTP_1_1) .bodyString("Important stuff", ContentType.DEFAULT_TEXT).execute().returnContent().asBytes(); // Execute a POST with a custom header through the proxy containing a request body // as an HTML form and save the result to the file Request.Post("http://somehost/some-form").addHeader("X-Custom-header", "stuff") .viaProxy(new HttpHost("myproxy", 8080)) .bodyForm(Form.form().add("username", "vip").add("password", "secret").build()).execute() .saveContent(new File("result.dump")); }
From source file:interoperabilite.webservice.fluent.FluentExecutor.java
public static void main(String[] args) throws Exception { Executor executor = Executor.newInstance().auth(new HttpHost("somehost"), "username", "password") .auth(new HttpHost("myproxy", 8080), "username", "password") .authPreemptive(new HttpHost("myproxy", 8080)); // Execute a GET with timeout settings and return response content as String. executor.execute(Request.Get("http://somehost/").connectTimeout(1000).socketTimeout(1000)).returnContent() .asString();/*from w ww. ja v a 2s. com*/ // Execute a POST with the 'expect-continue' handshake, using HTTP/1.1, // containing a request body as String and return response content as byte array. executor.execute(Request.Post("http://somehost/do-stuff").useExpectContinue().version(HttpVersion.HTTP_1_1) .bodyString("Important stuff", ContentType.DEFAULT_TEXT)).returnContent().asBytes(); // Execute a POST with a custom header through the proxy containing a request body // as an HTML form and save the result to the file executor.execute(Request.Post("http://somehost/some-form").addHeader("X-Custom-header", "stuff") .viaProxy(new HttpHost("myproxy", 8080)) .bodyForm(Form.form().add("username", "vip").add("password", "secret").build())) .saveContent(new File("result.dump")); }
From source file:io.aos.protocol.http.httpcommon.FluentRequests.java
public static void main(String... args) throws Exception { // Execute a GET with timeout settings and return response content as String. Request.Get("http://somehost/").connectTimeout(1000).socketTimeout(1000).execute().returnContent() .asString();/*from ww w.j ava 2 s. c o m*/ // Execute a POST with the 'expect-continue' handshake, using HTTP/1.1, // containing a request body as String and return response content as byte array. Request.Post("http://somehost/do-stuff").useExpectContinue().version(HttpVersion.HTTP_1_1) .bodyString("Important stuff", ContentType.DEFAULT_TEXT).execute().returnContent().asBytes(); // Execute a POST with a custom header through the proxy containing a request body // as an HTML form and save the result to the file Request.Post("http://somehost/some-form").addHeader("X-Custom-header", "stuff") .viaProxy(new HttpHost("myproxy", 8080)) .bodyForm(Form.form().add("username", "vip").add("password", "secret").build()).execute() .saveContent(new File("result.dump")); }
From source file:io.aos.protocol.http.httpcommon.FluentExecutor.java
public static void main(String... args) throws Exception { Executor executor = Executor.newInstance().auth(new HttpHost("somehost"), "username", "password") .auth(new HttpHost("myproxy", 8080), "username", "password") .authPreemptive(new HttpHost("myproxy", 8080)); // Execute a GET with timeout settings and return response content as String. executor.execute(Request.Get("http://somehost/").connectTimeout(1000).socketTimeout(1000)).returnContent() .asString();//from w w w . ja v a 2s .c om // Execute a POST with the 'expect-continue' handshake, using HTTP/1.1, // containing a request body as String and return response content as byte array. executor.execute(Request.Post("http://somehost/do-stuff").useExpectContinue().version(HttpVersion.HTTP_1_1) .bodyString("Important stuff", ContentType.DEFAULT_TEXT)).returnContent().asBytes(); // Execute a POST with a custom header through the proxy containing a request body // as an HTML form and save the result to the file executor.execute(Request.Post("http://somehost/some-form").addHeader("X-Custom-header", "stuff") .viaProxy(new HttpHost("myproxy", 8080)) .bodyForm(Form.form().add("username", "vip").add("password", "secret").build())) .saveContent(new File("result.dump")); }
From source file:com.helger.httpclient.response.ResponseHandlerString.java
public ResponseHandlerString() { // text/plain with ISO-8859-1 this(ContentType.DEFAULT_TEXT); }
From source file:com.sugarcrm.candybean.webservices.WS.java
/** * Send a DELETE, GET, POST, or PUT http request * * @param op The type of http request * @param uri The http endpoint//w w w . j a v a 2s . c o m * @param headers Map of header key value pairs * @param body String representation of the request body * @return Key Value pairs of the response * @throws Exception When http request failed * @deprecated Use {@link #request(OP, String, Map, String, ContentType)} */ @Deprecated public static Map<String, Object> request(OP op, String uri, Map<String, String> headers, String body) throws Exception { return request(op, uri, headers, body, ContentType.DEFAULT_TEXT); }
From source file:org.elasticsearch.shell.command.HttpPutCommand.java
@SuppressWarnings("unused") public HttpCommandResponse execute(String url, String body) throws IOException { HttpPut httpPut = new HttpPut(url); httpPut.setEntity(new StringEntity(body, ContentType.DEFAULT_TEXT)); return new HttpCommandResponse(shellHttpClient.getHttpClient().execute(httpPut)); }
From source file:org.elasticsearch.shell.command.HttpPostCommand.java
@SuppressWarnings("unused") public HttpCommandResponse execute(String url, String body) throws IOException { HttpPost httpPut = new HttpPost(url); httpPut.setEntity(new StringEntity(body, ContentType.DEFAULT_TEXT)); return new HttpCommandResponse(shellHttpClient.getHttpClient().execute(httpPut)); }
From source file:com.sugarcrm.candybean.webservices.WSSystemTest.java
License:asdf
@Test public void testHeaders() { headers.put("Test-Header-Key", "Test-Header-Value"); try {//w ww . j a va 2s. c o m response = WS.request(WS.OP.GET, uri + "/headers", headers, "", ContentType.DEFAULT_TEXT); } catch (Exception e) { Assert.fail(e.toString()); } Assert.assertTrue(response != null); Assert.assertEquals("application/json", ((JSONObject) response.get("headers")).get("Accept")); Assert.assertEquals("Test-Header-Value", ((JSONObject) response.get("headers")).get("Test-Header-Key")); }
From source file:ch.ralscha.extdirectspring_itest.FileUploadServiceTest.java
@Test public void testUpload() throws IOException { CloseableHttpClient client = HttpClientBuilder.create().build(); CloseableHttpResponse response = null; try {/* w w w.j a va 2s . co m*/ HttpPost post = new HttpPost("http://localhost:9998/controller/router"); InputStream is = getClass().getResourceAsStream("/UploadTestFile.txt"); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); ContentBody cbFile = new InputStreamBody(is, ContentType.create("text/plain"), "UploadTestFile.txt"); builder.addPart("fileUpload", cbFile); builder.addPart("extTID", new StringBody("2", ContentType.DEFAULT_TEXT)); builder.addPart("extAction", new StringBody("fileUploadService", ContentType.DEFAULT_TEXT)); builder.addPart("extMethod", new StringBody("uploadTest", ContentType.DEFAULT_TEXT)); builder.addPart("extType", new StringBody("rpc", ContentType.DEFAULT_TEXT)); builder.addPart("extUpload", new StringBody("true", ContentType.DEFAULT_TEXT)); builder.addPart("name", new StringBody("Jim", ContentType.create("text/plain", Charset.forName("UTF-8")))); builder.addPart("firstName", new StringBody("Ralph", ContentType.DEFAULT_TEXT)); builder.addPart("age", new StringBody("25", ContentType.DEFAULT_TEXT)); builder.addPart("email", new StringBody("test@test.ch", ContentType.DEFAULT_TEXT)); post.setEntity(builder.build()); response = client.execute(post); HttpEntity resEntity = response.getEntity(); assertThat(resEntity).isNotNull(); String responseString = EntityUtils.toString(resEntity); String prefix = "<html><body><textarea>"; String postfix = "</textarea></body></html>"; assertThat(responseString).startsWith(prefix); assertThat(responseString).endsWith(postfix); String json = responseString.substring(prefix.length(), responseString.length() - postfix.length()); ObjectMapper mapper = new ObjectMapper(); Map<String, Object> rootAsMap = mapper.readValue(json, Map.class); assertThat(rootAsMap).hasSize(5); assertThat(rootAsMap.get("method")).isEqualTo("uploadTest"); assertThat(rootAsMap.get("type")).isEqualTo("rpc"); assertThat(rootAsMap.get("action")).isEqualTo("fileUploadService"); assertThat(rootAsMap.get("tid")).isEqualTo(2); @SuppressWarnings("unchecked") Map<String, Object> result = (Map<String, Object>) rootAsMap.get("result"); assertThat(result).hasSize(7); assertThat(result.get("name")).isEqualTo("Jim"); assertThat(result.get("firstName")).isEqualTo("Ralph"); assertThat(result.get("age")).isEqualTo(25); assertThat(result.get("e-mail")).isEqualTo("test@test.ch"); assertThat(result.get("fileName")).isEqualTo("UploadTestFile.txt"); assertThat(result.get("fileContents")).isEqualTo("contents of upload file"); assertThat(result.get("success")).isEqualTo(Boolean.TRUE); EntityUtils.consume(resEntity); is.close(); } finally { IOUtils.closeQuietly(response); IOUtils.closeQuietly(client); } }