com.ning.http.client.FluentCaseInsensitiveStringsMap Java Examples

The following examples show how to use com.ning.http.client.FluentCaseInsensitiveStringsMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultipartHttpRequest.java    From slack-client with Apache License 2.0 6 votes vote down vote up
public HttpRequest build() {
  final byte[] body;
  MultipartRequestEntity requestEntity = new TerminatingMultipartRequestEntity(parts, new FluentCaseInsensitiveStringsMap());
  try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
    requestEntity.writeRequest(baos);
    baos.flush();
    body = baos.toByteArray();
  } catch (IOException e) {
    throw new RuntimeException("Error generating body bytes", e);
  }

  builder.addHeader("Content-Type", requestEntity.getContentType());
  builder.setBody(body);

  return builder.build();
}
 
Example #2
Source File: ParsecClientProfilingLogUtilTest.java    From parsec-libraries with Apache License 2.0 6 votes vote down vote up
@BeforeTest
public void setupCommon(){
    req = mock(Request.class);
    when(req.getUri()).thenReturn(Uri.create("http://test.yahoo.com"));
    when(req.getMethod()).thenReturn("POST");
    when(req.getHeaders()).thenReturn(new FluentCaseInsensitiveStringsMap().add(ParsecClientDefine.HEADER_HOST,
            Arrays.asList("dummyhost")));

    resp = mock(Response.class);
    when(resp.getHeader(anyString())).thenReturn("mock resp header");
    when(resp.getHeader("content-length")).thenReturn("100");
    when(resp.getStatusCode()).thenReturn(200);



    reqStatus = "test_status";
    progress = new ParsecAsyncProgress();

}
 
Example #3
Source File: AsyncUtil.java    From httpsig-java with The Unlicense 6 votes vote down vote up
public static void calculateSignature(Signer signer, Request request, RequestBuilderBase<?> requestBuilder) {
    RequestContent.Builder sigBuilder = new RequestContent.Builder();

    sigBuilder.setRequestTarget(request.getMethod(), getRequestPath(request));
    for (FluentCaseInsensitiveStringsMap.Entry<String, List<String>> entry : request.getHeaders().entrySet()) {
        for (String value : entry.getValue()) {
            sigBuilder.addHeader(entry.getKey(), value);
        }
    }

    if (sigBuilder.build().getDate() == null) {
        sigBuilder.addDateNow();
        requestBuilder.addHeader(Constants.HEADER_DATE, sigBuilder.build().getDate());
    }

    Authorization authz = signer.sign(sigBuilder.build());
    if (authz != null) {
        requestBuilder.setHeader(Constants.AUTHORIZATION, authz.getHeaderValue());
    }
}
 
Example #4
Source File: RequestHeaderAdaptorV1.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void setHeader(Request request, String name, String value) {
    final FluentCaseInsensitiveStringsMap httpRequestHeaders = request.getHeaders();
    final List<String> valueList = new ArrayList<String>();
    valueList.add(value);
    httpRequestHeaders.put(name, valueList);
    if (isDebug) {
        logger.debug("Set header {}={}", name, value);
    }
}
 
Example #5
Source File: NingAsyncHttpResponse.java    From junit-servers with MIT License 5 votes vote down vote up
@Override
public Collection<HttpHeader> getHeaders() {
	FluentCaseInsensitiveStringsMap headers = response.getHeaders();

	List<HttpHeader> results = new ArrayList<>(headers.size());
	for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
		results.add(HttpHeader.header(entry.getKey(), entry.getValue()));
	}

	return results;
}
 
Example #6
Source File: TerminatingMultipartRequestEntity.java    From slack-client with Apache License 2.0 4 votes vote down vote up
public TerminatingMultipartRequestEntity(List<Part> parts, FluentCaseInsensitiveStringsMap requestHeaders) {
  super(parts, requestHeaders);
}
 
Example #7
Source File: NingJsonFormatter.java    From parsec-libraries with Apache License 2.0 4 votes vote down vote up
private void fillNode(FluentCaseInsensitiveStringsMap headers, ObjectNode node){
    headers.keySet().forEach(
            k -> node.put(k, headers.getJoinedValue(k, ","))
    );
}
 
Example #8
Source File: ParsecCompletableFutureTest.java    From parsec-libraries with Apache License 2.0 4 votes vote down vote up
@Test
public void testGet() throws Exception {
    FluentCaseInsensitiveStringsMap responseHeaders = new FluentCaseInsensitiveStringsMap();

    responseHeaders.add("header1", "header1_value1");
    responseHeaders.add("header2", "header2_value1");

    List<Cookie> ningCookies = new ArrayList<>();

    ningCookies.add(new Cookie(
        "cookie1_name",
        "cookie1_value",
        false,
        null,
        "cookie1_path",
        1,
        true,
        true
    ));

    ningCookies.add(new Cookie(
        "cookie2_name",
        "cookie2_value",
        false,
        null,
        "cookie2_path",
        2,
        false,
        false
    ));

    when(mockNingResponse.getHeaders()).thenReturn(responseHeaders);
    when(mockNingResponse.getContentType()).thenReturn(MediaType.APPLICATION_JSON);
    when(mockNingResponse.getCookies()).thenReturn(ningCookies);
    when(mockNingResponse.getStatusCode()).thenReturn(200);
    when(mockNingResponse.hasResponseHeaders()).thenReturn(true);

    when(mockNingFuture.get()).thenReturn(mockNingResponse);
    when(mockNingFuture.get(anyLong(), any(TimeUnit.class))).thenReturn(mockNingResponse);

    ParsecCompletableFuture<Response> future = new ParsecCompletableFuture<>(mockNingFuture);
    Response response = future.get();

    assertEquals(response.getContentType(), MediaType.APPLICATION_JSON);
    assertEquals(response.getHeaders().size(), 2);

    response = future.get(3, TimeUnit.SECONDS);

    assertEquals(response.getContentType(), MediaType.APPLICATION_JSON);
    assertEquals(response.getHeaders().size(), 2);
}
 
Example #9
Source File: NingHttpHeaders.java    From writelatex-git-bridge with MIT License 4 votes vote down vote up
private NingHttpHeaders(FluentCaseInsensitiveStringsMap map) {
    this.map = map;
}
 
Example #10
Source File: NingHttpHeaders.java    From writelatex-git-bridge with MIT License 4 votes vote down vote up
@Override
public FluentCaseInsensitiveStringsMap getHeaders() {
    return map;
}
 
Example #11
Source File: NingHttpHeaders.java    From writelatex-git-bridge with MIT License 4 votes vote down vote up
public NingHttpHeaders build() {
    return new NingHttpHeaders(
            new FluentCaseInsensitiveStringsMap(map));
}