List of usage examples for org.apache.http.message BasicHeader BasicHeader
public BasicHeader(String str, String str2)
From source file:org.codehaus.httpcache4j.resolver.HTTPClientResponseResolverTest.java
@Test public void testNotSoSimpleGET() throws IOException { HTTPClientResponseResolver resolver = new TestableResolver(); HttpResponse mockedResponse = mock(HttpResponse.class); when(mockedResponse.getAllHeaders()).thenReturn(new org.apache.http.Header[] { new BasicHeader("Date", HeaderUtils.toHttpDate("Date", new DateTime()).getValue()) }); when(mockedResponse.getStatusLine()).thenReturn(new BasicStatusLine(new HttpVersion(1, 1), 200, "OK")); when(mockedResponse.getEntity()).thenReturn(new InputStreamEntity(new NullInputStream(1), 1)); when(client.execute(Mockito.<HttpUriRequest>anyObject())).thenReturn(mockedResponse); HTTPResponse response = resolver.resolve(new HTTPRequest(URI.create("http://www.vg.no"))); assertNotNull("Response was null", response); assertEquals("Wrong header size", 1, response.getHeaders().size()); assertTrue("Response did not have payload", response.hasPayload()); }
From source file:org.elasticsearch.client.RestClientTestUtil.java
/** * Create a random number of {@link Header}s. * Generated header names will either be the {@code baseName} plus its index, or exactly the provided {@code baseName} so that the * we test also support for multiple headers with same key and different values. *//*from www . j a v a2 s. c o m*/ static Header[] randomHeaders(Random random, final String baseName) { int numHeaders = RandomNumbers.randomIntBetween(random, 0, 5); final Header[] headers = new Header[numHeaders]; for (int i = 0; i < numHeaders; i++) { String headerName = baseName; //randomly exercise the code path that supports multiple headers with same key if (random.nextBoolean()) { headerName = headerName + i; } headers[i] = new BasicHeader(headerName, RandomStrings.randomAsciiOfLengthBetween(random, 3, 10)); } return headers; }
From source file:org.talend.components.elasticsearch.runtime_2_4.ElasticsearchBeamRuntimeTestIT.java
@Before public void init() throws IOException, ExecutionException, InterruptedException { client = ElasticsearchTestUtils.createClient(ElasticsearchTestConstants.HOSTS.split(":")[0], ElasticsearchTestConstants.TRANSPORT_PORT, ElasticsearchTestConstants.CLUSTER_NAME); datastoreProperties = new ElasticsearchDatastoreProperties("datastore"); datastoreProperties.init();//from ww w . j av a 2 s. com datastoreProperties.nodes.setValue(ElasticsearchTestConstants.HOSTS); RestClient restClient = ElasticsearchConnection.createClient(datastoreProperties); BasicHeader emptyHeader = new BasicHeader("", ""); Map<String, String> emptyParams = new HashMap<>(); ElasticsearchTestUtils.deleteIndex(INDEX_NAME, client); Response checkExistsResponse = restClient.performRequest("HEAD", "/" + INDEX_NAME, emptyParams); ElasticsearchResponse checkExists = new ElasticsearchResponse(checkExistsResponse); if (!checkExists.isOk()) { // create index for test, name is 'beam' restClient.performRequest("PUT", "/" + INDEX_NAME, emptyHeader); } }
From source file:org.sharetask.controller.TaskControllerIT.java
@Test public void testGetEvents() throws IOException { //given//from w w w. j ava 2s . co m final HttpGet httpGet = new HttpGet(URL_TASK + "/1/event"); httpGet.addHeader(new BasicHeader("Content-Type", "application/json")); //when final HttpResponse response = getClient().execute(httpGet); //then Assert.assertEquals(HttpStatus.OK.value(), response.getStatusLine().getStatusCode()); final String responseData = EntityUtils.toString(response.getEntity()); Assert.assertTrue(responseData.contains("\"message\":\"TASK_CREATED\"")); }
From source file:com.jaspersoft.android.jaspermobile.test.utils.TestResponses.java
public TestHttpResponse xml(String fileName) { BasicHeader contentType = new BasicHeader("Content-Type", "application/xml"); return new TestHttpResponse(200, TestResources.get().rawData(fileName), contentType); }
From source file:org.ardverk.daap.DaapHeaderConstructor.java
/** * Creates an Audio Header//from w w w . j av a 2 s. c o m * * @param request * @param contentLength * @return */ public static byte[] createAudioHeader(DaapRequest request, long pos, long end, long contentLength) { try { DaapConnection connection = request.getConnection(); int version = connection.getProtocolVersion(); if (version == DaapUtil.NULL) throw new IOException("Client Protocol Version is unknown"); String serverName = connection.getServer().getConfig().getServerName(); String statusLine = null; List<Header> headers = new ArrayList<Header>(); headers.add(new BasicHeader("Date", DaapUtil.now())); headers.add(new BasicHeader("DAAP-Server", serverName)); headers.add(new BasicHeader("Content-Type", "application/x-dmap-tagged")); headers.add(new BasicHeader("Connection", "close")); // if (pos == 0 || version <= DaapUtil.DAAP_VERSION_2) { statusLine = HTTP_OK; headers.add(new BasicHeader("Content-Length", Long.toString(contentLength))); } else { statusLine = HTTP_PARTIAL_CONTENT; String cotentLengthStr = Long.toString(contentLength - pos); String contentRange = "bytes " + pos + "-" + (contentLength - 1) + "/" + contentLength; headers.add(new BasicHeader("Content-Length", cotentLengthStr)); headers.add(new BasicHeader("Content-Range", contentRange)); } headers.add(new BasicHeader("Accept-Ranges", "bytes")); return toByteArray(statusLine, headers.toArray(new Header[0])); } catch (IOException err) { // Should never happen throw new RuntimeException(err); } }
From source file:com.joyent.manta.client.StringIteratorHttpContent.java
@Override public Header getContentType() { return new BasicHeader(HttpHeaders.CONTENT_TYPE, contentType.toString()); }
From source file:com.google.gerrit.acceptance.rest.change.CorsIT.java
@Test public void putWithOriginRefused() throws Exception { Result change = createChange(); String origin = "http://example.com"; RestResponse r = adminRestSession.putWithHeader("/changes/" + change.getChangeId() + "/topic", new BasicHeader(ORIGIN, origin), "A"); r.assertOK();//from w w w . j a v a 2s. com checkCors(r, false, origin); }
From source file:org.soyatec.windowsazure.blob.internal.BlobConstraints.java
public IBlobConstraints isSourceMatch(String etag) { constraints.add(new BasicHeader(HeaderNames.IfSourceMatch, etag)); return this; }