@Test public void implementationOfDefaultTextFormatSetter() { String testKey = "testKey"; String testValue = "testValue"; TextFormat.Setter<HttpHeaders> setter = CensusHttpModule.DefaultPropagationTextFormatSetter.INSTANCE; setter.put(httpRequest.getHeaders(), testKey, testValue); assertThat(httpRequest.getHeaders().get(testKey)).isEqualTo(testValue); }
private static void appendResponse(HttpResponseException exception, StringBuilder b) { b.append(exception.getStatusCode()).append(" with "); Long contentLength = exception.getHeaders().getContentLength(); b.append(contentLength != null ? contentLength : Long.valueOf(0)); b.append(" bytes of content"); HttpHeaders headers = exception.getHeaders(); for (String name : headers.keySet()) { b.append('\n').append(name).append(": ").append(headers.get(name)); } b.append('\n').append(exception.getContent()).append('\n'); }
@Test public void testSetHeaders() { HttpHeaders headers = new HttpHeaders(); Map<String, String> headersMap = ImmutableMap.of( "Custom-Header", "CustomHeader", "accept", "Accept", "Content-Length", "123"); assertEquals(headers, HttpHeadersUtils.setHeaders(headers, headersMap)); assertEquals("CustomHeader", headers.get("Custom-Header")); assertEquals("Accept", headers.getAccept()); assertEquals(Long.valueOf(123L), headers.getContentLength()); }
HttpHeadersUtils.setHeader(headers, "Age", "456"); assertEquals("CustomHeader", headers.get("Custom-Header")); assertEquals("CustomHeader", headers.get("custom-header")); assertEquals("Accept", headers.getAccept()); assertEquals("AcceptEncoding", headers.getAcceptEncoding()); assertEquals("RetryAfter", headers.getRetryAfter()); assertEquals("UserAgent", headers.getUserAgent()); assertEquals(ImmutableList.of("UserAgent"), headers.get("User-Agent")); assertEquals(ImmutableList.of("UserAgent"), headers.get("user-agent")); assertEquals("Authenticate", headers.getAuthenticate()); assertEquals(Long.valueOf(456L), headers.getAge());
ENDPOINT_URL, new AwqlReportBodyProvider("select 1", "csv").getHttpContent()); HttpHeaders headers = request.getHeaders(); assertEquals("foodevtoken", headers.get("developerToken")); assertEquals("fooauthheader", headers.getAuthorization()); assertEquals("fooclientcustomerid", headers.get("clientCustomerId")); assertTrue((headers.getUserAgent()).contains("foouseragent")); "skipReportHeader not equal to the reporting config setting", toStringBoolean(reportingConfiguration.isSkipReportHeader()), headers.get("skipReportHeader")); assertEquals( "skipColumnHeader not equal to the reporting config setting", toStringBoolean(reportingConfiguration.isSkipColumnHeader()), headers.get("skipColumnHeader")); assertEquals( "skipReportSummary not equal to the reporting config setting", toStringBoolean(reportingConfiguration.isSkipReportSummary()), headers.get("skipReportSummary")); assertEquals( "includeZeroImpressions not equal to the reporting config setting", toStringBoolean(reportingConfiguration.isIncludeZeroImpressions()), headers.get("includeZeroImpressions")); assertEquals( "useRawEnumValues not equal to the reporting config setting", toStringBoolean(reportingConfiguration.isUseRawEnumValues()), headers.get("useRawEnumValues"));
@Test public void censusHttpExecuteInterceptorShouldInjectHeader() throws IOException { Random random = new Random(); SpanContext spanContext = SpanContext.create( TraceId.generateRandomId(random), SpanId.generateRandomId(random), TraceOptions.DEFAULT); Span mockSpan = createMockBuilder(Span.class) .withConstructor(SpanContext.class, EnumSet.class) .withArgs(spanContext, null) .createMock(); Scope scope = tracer.withSpan(mockSpan); try { HttpExecuteInterceptor interceptor = censusHttpModule.new CensusHttpExecuteInterceptor(null); interceptor.intercept(httpRequest); assertThat(httpRequest.getHeaders().get("X-Cloud-Trace-Context")).isNotNull(); } finally { scope.close(); } }
/** * Returns whether the headers contain the specified value as one of the entries in the * specified header. */ static boolean headersContainValue(HttpHeaders headers, String headerName, String value) { Object values = headers.get(headerName); if (values instanceof Collection) { @SuppressWarnings("unchecked") Collection<Object> valuesCollection = (Collection<Object>) values; return valuesCollection.contains(value); } return false; }
static boolean headersContainValue(HttpHeaders headers, String headerName, String value) { Object values = headers.get(headerName); if (values instanceof Collection) { @SuppressWarnings("unchecked") Collection<Object> valuesList = (Collection<Object>) values; for (Object headerValue : valuesList) { if (headerValue instanceof String && ((String) headerValue).equals(value)) { return true; } } } return false; }
/** * Returns whether the headers contain the specified value as one of the entries in the * specified header. */ static boolean headersContainValue(HttpHeaders headers, String headerName, String value) { Object values = headers.get(headerName); if (values instanceof Collection) { @SuppressWarnings("unchecked") Collection<Object> valuesCollection = (Collection<Object>) values; return valuesCollection.contains(value); } return false; }
String headerkey = iter.next(); if (!headerkey.trim().equalsIgnoreCase("Authorization")) { String headervalue = ""+headers.get(headerkey); prettyString = prettyString + "\n" + headerkey + ": " + headervalue;
String headerkey = iter.next(); if (!headerkey.trim().equalsIgnoreCase("Authorization")) { String headervalue = ""+headers.get(headerkey); prettyRequest = prettyRequest + "\n" + headerkey + ": " + headervalue; }else { String headervalue = ""+headers.get(headerkey); String arr[] = headervalue.split(" ", 2); String prefix = arr[0]; // Basic, Bearer
protected JdcloudResponse handlerHttpResponse(HttpResponse httpResponse) throws IOException,IllegalAccessException,InstantiationException, JAXBException{ String contentType = httpResponse.getContentType(); if(httpResponse.getContent() != null && httpResponse.getStatusCode() != 204 && httpResponse.getStatusCode() != 304) { JdcloudResponse response; if(ContentType.TEXT_XML.toString().equals(contentType)) { response = (JdcloudResponse) getUnmarshaller().unmarshall(ConvertUtils.xmlToJson(httpResponse.getContent())); } else { response = (JdcloudResponse) getUnmarshaller().unmarshall(jdcloudClient.readValue(httpResponse.getContent())); } if (null == response){ throw new JdcloudSdkException("Illegal Content"); } response.setOriginalResponse(httpResponse); return response; } Object o = httpResponse.getHeaders().get("x-jdcloud-request-id"); if(o instanceof ArrayList) { String reqId = (String)((ArrayList) o).get(0); JdcloudResponse ret = returnType().newInstance(); ret.setRequestId(reqId); ret.setOriginalResponse(httpResponse); return ret; } return returnType().newInstance(); }