use of com.google.api.client.http.HttpHeaders in project feign by OpenFeign.
the class GoogleHttpClient method convertResponse.
private final Response convertResponse(final Request inputRequest, final HttpResponse inputResponse) throws IOException {
final HttpHeaders headers = inputResponse.getHeaders();
Integer contentLength = null;
if (headers.getContentLength() != null && headers.getContentLength() <= Integer.MAX_VALUE) {
contentLength = inputResponse.getHeaders().getContentLength().intValue();
}
return Response.builder().body(inputResponse.getContent(), contentLength).status(inputResponse.getStatusCode()).reason(inputResponse.getStatusMessage()).headers(toMap(inputResponse.getHeaders())).request(inputRequest).build();
}
use of com.google.api.client.http.HttpHeaders in project feign by OpenFeign.
the class GoogleHttpClient method convertRequest.
private final HttpRequest convertRequest(final Request inputRequest, final Request.Options options) throws IOException {
// Setup the request body
HttpContent content = null;
if (inputRequest.length() > 0) {
final Collection<String> contentTypeValues = inputRequest.headers().get("Content-Type");
String contentType = null;
if (contentTypeValues != null && contentTypeValues.size() > 0) {
contentType = contentTypeValues.iterator().next();
} else {
contentType = "application/octet-stream";
}
content = new ByteArrayContent(contentType, inputRequest.body());
}
// Build the request
final HttpRequest request = requestFactory.buildRequest(inputRequest.httpMethod().name(), new GenericUrl(inputRequest.url()), content);
// Setup headers
final HttpHeaders headers = new HttpHeaders();
for (final Map.Entry<String, Collection<String>> header : inputRequest.headers().entrySet()) {
headers.set(header.getKey(), header.getValue());
}
// Some servers don't do well with no Accept header
if (inputRequest.headers().get("Accept") == null) {
headers.setAccept("*/*");
}
request.setHeaders(headers);
// Setup request options
request.setReadTimeout(options.readTimeoutMillis()).setConnectTimeout(options.connectTimeoutMillis()).setFollowRedirects(options.isFollowRedirects()).setThrowExceptionOnExecuteError(false);
return request;
}
use of com.google.api.client.http.HttpHeaders in project scout.rt by eclipse.
the class HttpServiceTunnel method executeRequest.
/**
* Execute a {@link ServiceTunnelRequest}, returns the plain {@link HttpResponse} - (executed and) ready to be
* processed to create a {@link ServiceTunnelResponse}.
*
* @param call
* the original call
* @param callData
* the data created by the {@link IServiceTunnelContentHandler} used by this tunnel Create url connection and
* write post data (if required)
* @throws IOException
* override this method to customize the creation of the {@link HttpResponse} see
* {@link #addCustomHeaders(HttpRequest, ServiceTunnelRequest, byte[])}
*/
protected HttpResponse executeRequest(ServiceTunnelRequest call, byte[] callData) throws IOException {
// fast check of wrong URL's for this tunnel
if (!"http".equalsIgnoreCase(getServerUrl().getProtocol()) && !"https".equalsIgnoreCase(getServerUrl().getProtocol())) {
throw new IOException("URL '" + getServerUrl().toString() + "' is not supported by this tunnel ('" + getClass().getName() + "').");
}
if (!isActive()) {
String key = BEANS.get(ServiceTunnelTargetUrlProperty.class).getKey();
throw new IllegalArgumentException("No target URL configured. Please specify a target URL in the config.properties using property '" + key + "'.");
}
HttpRequestFactory requestFactory = getHttpTransportManager().getHttpRequestFactory();
HttpRequest request = requestFactory.buildPostRequest(getGenericUrl(), new ByteArrayContent(null, callData));
HttpHeaders headers = request.getHeaders();
headers.setCacheControl("no-cache");
headers.setContentType("text/xml");
headers.put("Pragma", "no-cache");
addCustomHeaders(request, call, callData);
return request.execute();
}
use of com.google.api.client.http.HttpHeaders in project scout.rt by eclipse.
the class HttpProxy method writeRequestHeaders.
protected void writeRequestHeaders(HttpServletRequest req, HttpRequest httpReq) {
Enumeration<String> headerNames = req.getHeaderNames();
while (headerNames.hasMoreElements()) {
String name = headerNames.nextElement();
String value = req.getHeader(name);
for (IHttpHeaderFilter filter : getRequestHeaderFilters()) {
value = filter.filter(name, value);
}
if (value != null) {
HttpHeaders headers = httpReq.getHeaders();
headers.set(name, Collections.singletonList(value));
LOG.trace("Wrote request header: {}: {}", name, value);
} else {
LOG.trace("Removed request header: {} (original value: {})", name, req.getHeader(name));
}
}
}
use of com.google.api.client.http.HttpHeaders in project providence by morimekta.
the class SetHeadersInitializer method initialize.
@Override
public void initialize(HttpRequest request) {
request.setConnectTimeout(connect_timeout);
request.setReadTimeout(read_timeout);
// With the interceptor will overwrite headers set by the Http client.
request.setInterceptor(rq -> {
HttpHeaders http = rq.getHeaders();
for (Map.Entry<String, String> entry : headers.entrySet()) {
String value = entry.getValue();
switch(entry.getKey().toLowerCase()) {
case "accept":
http.setAccept(value);
break;
case "accept-encoding":
http.setAcceptEncoding(value);
break;
case "authorization":
http.setAuthorization(value);
break;
case "content-encoding":
http.setContentEncoding(value);
break;
case "content-type":
http.setContentType(value);
break;
case "user-agent":
http.setUserAgent(value);
break;
default:
try {
http.set(entry.getKey(), value);
} catch (Exception e) {
// special method.
throw new IOException("Unable to set header " + entry.getKey() + ": " + e.getMessage(), e);
}
break;
}
}
});
}
Aggregations