org.apache.hc.core5.http.Header Java Examples
The following examples show how to use
org.apache.hc.core5.http.Header.
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: TestUtil.java From spotify-web-api-java with MIT License | 6 votes |
public static IHttpManager returningJson(String jsonFixtureFileName) throws Exception { // Mocked HTTP Manager to get predictable responses final IHttpManager mockedHttpManager = mock(IHttpManager.class); String fixture = null; if (jsonFixtureFileName != null) { fixture = readTestData(jsonFixtureFileName); } when(mockedHttpManager.get(any(URI.class), any(Header[].class))).thenReturn(fixture); when(mockedHttpManager.post(any(URI.class), any(Header[].class), any(HttpEntity.class))).thenReturn(fixture); when(mockedHttpManager.put(any(URI.class), any(Header[].class), any(HttpEntity.class))).thenReturn(fixture); when(mockedHttpManager.delete(any(URI.class), any(Header[].class), any(HttpEntity.class))).thenReturn(fixture); return mockedHttpManager; }
Example #2
Source File: Http5FileProvider.java From commons-vfs with Apache License 2.0 | 6 votes |
/** * Create an {@link HttpClientBuilder} object. Invoked by {@link #createHttpClient(Http5FileSystemConfigBuilder, GenericFileName, FileSystemOptions)}. * * @param builder Configuration options builder for HTTP4 provider * @param rootName The root path * @param fileSystemOptions The FileSystem options * @return an {@link HttpClientBuilder} object * @throws FileSystemException if an error occurs */ protected HttpClientBuilder createHttpClientBuilder(final Http5FileSystemConfigBuilder builder, final GenericFileName rootName, final FileSystemOptions fileSystemOptions) throws FileSystemException { final List<Header> defaultHeaders = new ArrayList<>(); defaultHeaders.add(new BasicHeader(HttpHeaders.USER_AGENT, builder.getUserAgent(fileSystemOptions))); final ConnectionReuseStrategy connectionReuseStrategy = builder.isKeepAlive(fileSystemOptions) ? DefaultConnectionReuseStrategy.INSTANCE : (request, response, context) -> false; final HttpClientBuilder httpClientBuilder = HttpClients.custom() .setRoutePlanner(createHttpRoutePlanner(builder, fileSystemOptions)) .setConnectionManager(createConnectionManager(builder, fileSystemOptions)) .setConnectionReuseStrategy(connectionReuseStrategy) .setDefaultRequestConfig(createDefaultRequestConfig(builder, fileSystemOptions)) .setDefaultHeaders(defaultHeaders) .setDefaultCookieStore(createDefaultCookieStore(builder, fileSystemOptions)); if (!builder.getFollowRedirect(fileSystemOptions)) { httpClientBuilder.disableRedirectHandling(); } return httpClientBuilder; }
Example #3
Source File: Http5FileContentInfoFactory.java From commons-vfs with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public FileContentInfo create(final FileContent fileContent) throws FileSystemException { String contentMimeType = null; String contentCharset = null; try (final Http5FileObject<Http5FileSystem> http4File = (Http5FileObject<Http5FileSystem>) FileObjectUtils .getAbstractFileObject(fileContent.getFile())) { final HttpResponse lastHeadResponse = http4File.getLastHeadResponse(); final Header header = lastHeadResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE); if (header != null) { final ContentType contentType = ContentType.parse(header.getValue()); contentMimeType = contentType.getMimeType(); if (contentType.getCharset() != null) { contentCharset = contentType.getCharset().name(); } } return new DefaultFileContentInfo(contentMimeType, contentCharset); } catch (final IOException e) { throw new FileSystemException(e); } }
Example #4
Source File: StructurizrClient.java From java with Apache License 2.0 | 5 votes |
private void debugRequest(HttpUriRequestBase httpRequest, String content) { if (log.isDebugEnabled()) { log.debug(httpRequest.getMethod() + " " + httpRequest.getPath()); Header[] headers = httpRequest.getHeaders(); for (Header header : headers) { log.debug(header.getName() + ": " + header.getValue()); } if (content != null) { log.debug(content); } } }
Example #5
Source File: Assertions.java From spotify-web-api-java with MIT License | 5 votes |
public static <RT, T> void assertHasHeader(IRequest<RT> request, String name, T value) { List<Header> headers = request.getHeaders(); for (Header header : headers) { if (header.getName().equals(name) && header.getValue().equals(String.valueOf(value))) { return; } } fail(String.format("Request \"%s\" does not contain form parameter \"%s\" with value \"%s\"", request.getClass().getSimpleName(), name, value)); }
Example #6
Source File: TraceeHttpResponseInterceptor.java From tracee with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public final void process(HttpResponse response, HttpContext context) { final TraceeFilterConfiguration filterConfiguration = backend.getConfiguration(profile); final Iterator<Header> headerIterator = response.headerIterator(TraceeConstants.TPIC_HEADER); if (headerIterator != null && headerIterator.hasNext() && filterConfiguration.shouldProcessContext(IncomingResponse)) { final List<String> stringTraceeHeaders = new ArrayList<>(); while (headerIterator.hasNext()) { stringTraceeHeaders.add(headerIterator.next().getValue()); } backend.putAll(filterConfiguration.filterDeniedParams(transportSerialization.parse(stringTraceeHeaders), IncomingResponse)); } }
Example #7
Source File: Http5FileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
@Override protected long doGetContentSize() throws Exception { if (lastHeadResponse == null) { return 0L; } final Header header = lastHeadResponse.getFirstHeader(HttpHeaders.CONTENT_LENGTH); if (header == null) { // Assume 0 content-length return 0; } return Long.parseLong(header.getValue()); }
Example #8
Source File: AsyncApacheHttp5Client.java From feign with Apache License 2.0 | 5 votes |
Response toFeignResponse(SimpleHttpResponse httpResponse, Request request) { final int statusCode = httpResponse.getCode(); final String reason = httpResponse.getReasonPhrase(); final Map<String, Collection<String>> headers = new HashMap<String, Collection<String>>(); for (final Header header : httpResponse.getHeaders()) { final String name = header.getName(); final String value = header.getValue(); Collection<String> headerValues = headers.get(name); if (headerValues == null) { headerValues = new ArrayList<String>(); headers.put(name, headerValues); } headerValues.add(value); } return Response.builder() .status(statusCode) .reason(reason) .headers(headers) .request(request) .body(httpResponse .getBodyBytes()) .build(); }
Example #9
Source File: ApacheDockerHttpClientImpl.java From docker-java with Apache License 2.0 | 4 votes |
@Override public String getHeader(String name) { Header firstHeader = response.getFirstHeader(name); return firstHeader != null ? firstHeader.getValue() : null; }
Example #10
Source File: Http5FileObject.java From commons-vfs with Apache License 2.0 | 3 votes |
@Override protected long doGetLastModifiedTime() throws Exception { FileSystemException.requireNonNull(lastHeadResponse, "vfs.provider.http/last-modified.error", getName()); final Header header = lastHeadResponse.getFirstHeader("Last-Modified"); FileSystemException.requireNonNull(header, "vfs.provider.http/last-modified.error", getName()); return DateUtils.parseDate(header.getValue()).getTime(); }
Example #11
Source File: IHttpManager.java From spotify-web-api-java with MIT License | 2 votes |
/** * Perform an HTTP GET request to the specified URL. * * @param uri The GET request's {@link URI}. * @param headers The GET request's {@link Header}s. * @return A string containing the GET request's response body. * @throws IOException In case of networking issues. * @throws SpotifyWebApiException The Web API returned an error further specified in this exception's root cause. * @throws ParseException The response could not be parsed as a string. */ String get(URI uri, Header[] headers) throws IOException, SpotifyWebApiException, ParseException;
Example #12
Source File: IHttpManager.java From spotify-web-api-java with MIT License | 2 votes |
/** * Perform an HTTP POST request to the specified URL. * * @param uri The POST request's {@link URI}. * @param headers The POST request's {@link Header}s. * @param body The PUT request's body as a {@link HttpEntity}. * @return A string containing the POST request's response body. * @throws IOException In case of networking issues. * @throws SpotifyWebApiException The Web API returned an error further specified in this exception's root cause. * @throws ParseException The response could not be parsed as a string. */ String post(URI uri, Header[] headers, HttpEntity body) throws IOException, SpotifyWebApiException, ParseException;
Example #13
Source File: IHttpManager.java From spotify-web-api-java with MIT License | 2 votes |
/** * Perform an HTTP PUT request to the specified URL. * * @param uri The PUT request's {@link URI}. * @param headers The PUT request's {@link Header}s. * @param body The PUT request's body as a {@link HttpEntity}. * @return A string containing the PUT request's response body. * @throws IOException In case of networking issues. * @throws SpotifyWebApiException The Web API returned an error further specified in this exception's root cause. * @throws ParseException The response could not be parsed as a string. */ String put(URI uri, Header[] headers, HttpEntity body) throws IOException, SpotifyWebApiException, ParseException;
Example #14
Source File: IHttpManager.java From spotify-web-api-java with MIT License | 2 votes |
/** * Perform an HTTP DELETE request to the specified URL. * * @param uri The DELETE request's {@link URI}. * @param headers The DELETE request's {@link Header}s. * @param body The DELETE request's body as a {@link HttpEntity}. * @return A string containing the DELETE request's response body. * @throws IOException In case of networking issues. * @throws SpotifyWebApiException The Web API returned an error further specified in this exception's root cause. * @throws ParseException The response could not be parsed as a string. */ String delete(URI uri, Header[] headers, HttpEntity body) throws IOException, SpotifyWebApiException, ParseException;