List of usage examples for com.squareup.okhttp Headers of
public static Headers of(Map<String, String> headers)
From source file:cn.finalteam.okhttpfinal.HttpTask.java
License:Apache License
@Override protected void onPreExecute() { super.onPreExecute(); if (params.headerMap != null) { headers = Headers.of(params.headerMap); }//w w w. j a v a 2s.c o m if (callback != null) { callback.onStart(); } }
From source file:com.frostwire.http.HttpClient.java
License:Open Source License
private com.squareup.okhttp.Request buildReq(Request request) { return new com.squareup.okhttp.Request.Builder().method(request.method().toString(), buildReqBody(request)) .headers(Headers.of(request.headers())).url(request.url()).build(); }
From source file:com.ibm.watson.developer_cloud.service.WatsonService.java
License:Open Source License
/** * Set the default headers to be used on every HTTP request. * //from w w w .ja v a 2s. c om * @param headers name value pairs of headers */ public void setDefaultHeaders(Map<String, String> headers) { defaultHeaders = Headers.of(headers); }
From source file:com.magnet.max.android.rest.qos.internal.CachedRequest.java
License:Apache License
public Request toRequest() { Headers responseHeaders = Headers.of(headers); String contentType = responseHeaders.get("Content-Type"); return new Request.Builder().url(url).method(method, RequestBody.create(MediaType.parse(contentType), body)) .headers(responseHeaders).build(); }
From source file:com.magnet.max.android.rest.qos.internal.CachedResponse.java
License:Apache License
public Response toResponse(Request request) { Headers responseHeaders = Headers.of(headers); String contentType = responseHeaders.get("Content-Type"); Response cachedResponse = new Response.Builder().code(code).protocol(getProtocolEnum()).message(message) .headers(responseHeaders).request(request).build(); return cachedResponse.newBuilder().body(ResponseBody.create(MediaType.parse(contentType), body)) .cacheResponse(cachedResponse).build(); }
From source file:lumbermill.internal.elasticsearch.ElasticSearchOkHttpClientImpl.java
License:Apache License
protected void doOkHttpPost(RequestContext requestCtx) { RequestBody body = RequestBody.create(TEXT, requestCtx.signableRequest.payload().get()); Request request = new Request.Builder().url(url).post(body) .headers(Headers.of(requestCtx.signableRequest.headers())).build(); // Add some sanity logging to be able to figure out the load if (LOGGER.isDebugEnabled()) { int requestsInQueue = client.getDispatcher().getQueuedCallCount(); int requestsInProgress = client.getDispatcher().getRunningCallCount(); if (requestsInQueue > 0) { LOGGER.debug("There are {} requests waiting to be processed", requestsInQueue); }/*from w ww . ja va 2 s.c o m*/ if (requestsInProgress > 0) { LOGGER.debug("There are {} requests currently executing", requestsInProgress); } } client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { requestCtx.error(IndexFailedException.ofIOException(e)); } @Override public void onResponse(Response response) throws IOException { handleResponse(requestCtx, response); } }); }
From source file:org.graylog2.inputs.transports.HttpPollTransport.java
License:Open Source License
@Override public void doLaunch(final MessageInput input) throws MisfireException { serverStatus.awaitRunning(new Runnable() { @Override//from w w w . ja v a2 s. c o m public void run() { lifecycleStateChange(Lifecycle.RUNNING); } }); // listen for lifecycle changes serverEventBus.register(this); final Map<String, String> headers = parseHeaders(configuration.getString(CK_HEADERS)); // figure out a reasonable remote address final String url = configuration.getString(CK_URL); final InetSocketAddress remoteAddress; InetSocketAddress remoteAddress1; try { final URL url1 = new URL(url); final int port = url1.getPort(); remoteAddress1 = new InetSocketAddress(url1.getHost(), port != -1 ? port : 80); } catch (MalformedURLException e) { remoteAddress1 = null; } remoteAddress = remoteAddress1; final Runnable task = new Runnable() { @Override public void run() { if (paused) { LOG.debug("Message processing paused, not polling HTTP resource {}.", url); return; } if (isThrottled()) { // this transport won't block, but we can simply skip this iteration LOG.debug("Not polling HTTP resource {} because we are throttled.", url); } final Request.Builder requestBuilder = new Request.Builder().get().url(url) .headers(Headers.of(headers)); try { final Response r = httpClient.newCall(requestBuilder.build()).execute(); if (!r.isSuccessful()) { throw new RuntimeException("Expected successful HTTP status code [2xx], got " + r.code()); } input.processRawMessage(new RawMessage(r.body().bytes(), remoteAddress)); } catch (IOException e) { LOG.error("Could not fetch HTTP resource at " + url, e); } } }; scheduledFuture = scheduler.scheduleAtFixedRate(task, 0, configuration.getInt(CK_INTERVAL), TimeUnit.valueOf(configuration.getString(CK_TIMEUNIT))); }