List of usage examples for org.apache.http.message BasicHeader BasicHeader
public BasicHeader(String str, String str2)
From source file:com.microsoft.live.mock.MockHttpEntity.java
@Override public Header getContentEncoding() { return new BasicHeader("Content-encoding", HTTP.UTF_8); }
From source file:org.kiji.checkin.TestCheckinClient.java
@Test public void testCheckin() throws IOException, URISyntaxException { LOG.info("Creating mocks."); // We'll create an UpgradeServerClient using a mock http client. The client will // execute one request, which will return an http response, which in turn will return // an entity that will provide the content for the response. InputStream contentStream = IOUtils.toInputStream(RESPONSE_JSON); HttpEntity mockResponseEntity = EasyMock.createMock(HttpEntity.class); EasyMock.expect(mockResponseEntity.getContent()).andReturn(contentStream); EasyMock.expect(mockResponseEntity.getContentLength()).andReturn(-1L).times(2); EasyMock.expect(mockResponseEntity.getContentType()) .andReturn(new BasicHeader("ContentType", ContentType.APPLICATION_JSON.toString())); HttpResponse mockResponse = EasyMock.createMock(HttpResponse.class); EasyMock.expect(mockResponse.getEntity()).andReturn(mockResponseEntity); HttpClient mockClient = EasyMock.createMock(HttpClient.class); EasyMock.expect(mockClient.execute(EasyMock.isA(HttpPost.class))).andReturn(mockResponse); LOG.info("Replaying mocks."); EasyMock.replay(mockResponseEntity); EasyMock.replay(mockResponse);//from www . ja va2s. co m EasyMock.replay(mockClient); // Create the upgrade server client. LOG.info("Creating upgrade server client and making request."); CheckinClient upgradeClient = CheckinClient.create(mockClient, new URI("http://www.foocorp.com")); UpgradeCheckin checkinMessage = new UpgradeCheckin.Builder(this.getClass()).withId("12345") .withLastUsedMillis(1L).build(); UpgradeResponse response = upgradeClient.checkin(checkinMessage); LOG.info("Verifying mocks."); EasyMock.verify(mockResponseEntity, mockResponse, mockClient); // Verify the response content. LOG.info("Verifying response content."); assertEquals("Bad response format.", "bento-checkversion-1.0.0", response.getResponseFormat()); assertEquals("Bad latest version", "2.0.0", response.getLatestVersion()); assertEquals("Bad latest version URL.", "http://www.foocorp.com", response.getLatestVersionURL().toString()); assertEquals("Bad compatible version.", "2.0.0", response.getCompatibleVersion()); assertEquals("Bad compatible version URL.", "http://www.foocorp.com", response.getCompatibleVersionURL().toString()); assertEquals("Bad response msg.", "better upgrade!", response.getMessage()); }
From source file:nya.miku.wishmaster.http.client.DCP.java
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { String timestamp = Long.toString(System.currentTimeMillis()); if (timestamp.length() > 10) timestamp = timestamp.substring(0, 10); String sid = CryptoUtils.computeMD5(timestamp + AUTH_VALUE + timestamp); String key = "ps=" + timestamp + "-" + getRandom() + "-" + getRandom() + "-" + getRandom() + ", sid=" + sid + ", b=2228, p=0, c=win"; request.addHeader(new BasicHeader("Chrome-Proxy", key)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { request.removeHeaders(HttpHeaders.ACCEPT); request.addHeader(new BasicHeader(HttpHeaders.ACCEPT, "image/webp,*/*;q=0.8")); }/*from ww w . ja va 2 s . c om*/ }
From source file:nl.nn.adapterframework.http.HttpSenderResultTest.java
public HttpSender createHttpSender(InputStream responseStream, String contentType) throws IOException { CloseableHttpClient httpClient = mock(CloseableHttpClient.class); CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class); StatusLine statusLine = mock(StatusLine.class); HttpEntity httpEntity = mock(HttpEntity.class); when(statusLine.getStatusCode()).thenReturn(200); when(httpResponse.getStatusLine()).thenReturn(statusLine); if (contentType != null) { Header contentTypeHeader = new BasicHeader("Content-Type", contentType); when(httpEntity.getContentType()).thenReturn(contentTypeHeader); }/*from w ww. ja v a2 s. c o m*/ when(httpEntity.getContent()).thenReturn(responseStream); when(httpResponse.getEntity()).thenReturn(httpEntity); //Mock all requests when(httpClient.execute(any(HttpHost.class), any(HttpRequestBase.class), any(HttpContext.class))) .thenReturn(httpResponse); HttpSender sender = spy(new HttpSender()); when(sender.getHttpClient()).thenReturn(httpClient); //Some default settings, url will be mocked. sender.setUrl("http://127.0.0.1/"); sender.setIgnoreRedirects(true); sender.setVerifyHostname(false); sender.setAllowSelfSignedCertificates(true); return sender; }
From source file:sample.jdbc.StagemonitorIntegrationTest.java
@Before public void setUp() throws Exception { httpClient = HttpClientBuilder.create() .setDefaultHeaders(Arrays.asList(new BasicHeader("Accept", "text/html"))).build(); this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); }
From source file:com.spectralogic.ds3client.metadata.WindowsMetadataRestore_Test.java
@Test public void restoreFileTimes_Test() throws Exception { final BasicHeader basicHeader[] = new BasicHeader[3]; final Path filePath = ResourceUtils.loadFileResource(FILE_NAME); final BasicFileAttributes attr = Files.readAttributes(filePath, BasicFileAttributes.class); basicHeader[0] = new BasicHeader(METADATA_PREFIX + MetadataKeyConstants.KEY_CREATION_TIME, String.valueOf(attr.creationTime().toMillis())); basicHeader[1] = new BasicHeader(METADATA_PREFIX + MetadataKeyConstants.KEY_ACCESS_TIME, String.valueOf(attr.lastAccessTime().toMillis())); basicHeader[2] = new BasicHeader(METADATA_PREFIX + MetadataKeyConstants.KEY_LAST_MODIFIED_TIME, String.valueOf(attr.lastModifiedTime().toMillis())); final Metadata metadata = genMetadata(basicHeader); final WindowsMetadataRestore windowsMetadataRestore = new WindowsMetadataRestore(metadata, filePath.toString(), MetaDataUtil.getOS()); windowsMetadataRestore.restoreFileTimes(); final BasicFileAttributes fileAttributes = Files.readAttributes(filePath, BasicFileAttributes.class); Assert.assertEquals(String.valueOf(fileAttributes.creationTime().toMillis()), String.valueOf(basicHeader[0].getValue())); Assert.assertEquals(String.valueOf(fileAttributes.lastModifiedTime().toMillis()), String.valueOf(basicHeader[2].getValue())); }
From source file:org.envirocar.app.network.RestClient.java
/** * @deprecated Use {@link DAOProvider#getSensorDAO()} / {@link SensorDAO#saveSensor(org.envirocar.app.model.Car, User)} * instead.// w ww . ja va 2 s . c o m */ @Deprecated public static boolean createSensor(String jsonObj, String user, String token, AsyncHttpResponseHandler handler) { client.addHeader("Content-Type", "application/json"); setHeaders(user, token); try { StringEntity se = new StringEntity(jsonObj); se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); client.post(null, ECApplication.BASE_URL + "/sensors", se, "application/json", handler); } catch (UnsupportedEncodingException e) { logger.warn(e.getMessage(), e); return false; } return true; }
From source file:com.thoughtworks.go.agent.common.util.HeaderUtilTest.java
private void assertExtraPropertiesWithoutBase64(String actualHeaderValue, Map<String, String> expectedProperties) { Map<String, String> actualResult = HeaderUtil .parseExtraProperties(new BasicHeader("some-key", actualHeaderValue)); assertThat(actualResult, is(expectedProperties)); }
From source file:com.kolich.havalo.client.api.PutTest.java
@Test public void put() throws Exception { // PUT a sample object final Either<HttpFailure, FileObject> put = client_.putObject(getBytesUtf8(SAMPLE_JSON_OBJECT), new Header[] { new BasicHeader(CONTENT_TYPE, "application/json") }, "test", "jsonObject/hmm"); assertTrue("Failed to PUT sample object.", put.success()); // GET the object to make sure it actually worked. final ByteArrayOutputStream os = new ByteArrayOutputStream(); final Either<HttpFailure, List<Header>> get = client_.getObject(os, "test", "jsonObject/hmm"); assertTrue("Failed to GET sample object after PUT.", get.success()); assertTrue("Failed to GET sample object after PUT -- no headers!?", get.right().size() > 0L); final String receivedString = newStringUtf8(os.toByteArray()); assertTrue("Object received on GET did not match object " + "sent on PUT (sent=" + SAMPLE_JSON_OBJECT + ", received=" + receivedString + ")", receivedString.equals(SAMPLE_JSON_OBJECT)); // Tear down/*from ww w. j a v a 2s. c o m*/ final Either<HttpFailure, Integer> delete = client_.deleteObject("test", "jsonObject/hmm"); assertTrue("Failed to DELETE sample object.", delete.success()); }
From source file:org.exoplatform.social.client.api.util.SocialHttpClientSupport.java
/** * Invokes the social rest service via Get method * @param targetURL /*from w ww.j a va 2s .c o m*/ * @param authPolicy POLICY.NO_AUTH/POLICY.BASIC_AUTH * @param params HttpParams for Request * @return * @throws IOException * @throws ClientProtocolException */ public static HttpResponse executeGet(String targetURL, POLICY authPolicy, HttpParams params) throws SocialHttpClientException { SocialHttpClient httpClient = SocialHttpClientImpl.newInstance(); if (POLICY.BASIC_AUTH == authPolicy) { try { httpClient.setBasicAuthenticateToRequest(); } catch (SocialClientLibException e) { throw new SocialHttpClientException(e.getMessage(), e); } } HttpGet httpGet = new HttpGet(targetURL); Header header = new BasicHeader("Content-Type", "application/json"); httpGet.setHeader(header); HttpHost targetHost = new HttpHost(SocialClientContext.getHost(), SocialClientContext.getPort(), SocialClientContext.getProtocol()); //Get method with the HttpParams if (params != null) { httpGet.setParams(params); } try { HttpResponse response = httpClient.execute(targetHost, httpGet); //handleError(response); //Debugging in the devlopment mode if (SocialClientContext.isDeveloping()) { dumpHttpResponsetHeader(response); dumpContent(response); } return response; } catch (ClientProtocolException cpex) { throw new SocialHttpClientException(cpex.toString(), cpex); } catch (IOException ioex) { throw new SocialHttpClientException(ioex.toString(), ioex); } }