List of usage examples for org.apache.http.client.methods HttpUriRequest setHeader
void setHeader(String str, String str2);
From source file:com.fujitsu.dc.test.jersey.DcRestAdapter.java
/** * ??? PUT.//from w ww.j a v a 2s . c o m * @param url URL * @param data ?? * @param headers ?? * @return DcResponse * @throws DcException DAO */ public final DcResponse put(final String url, final String data, final HashMap<String, String> headers) throws DcException { String contentType = headers.get(HttpHeaders.CONTENT_TYPE); HttpUriRequest req = makePutRequest(url, data, contentType); for (Map.Entry<String, String> entry : headers.entrySet()) { req.setHeader(entry.getKey(), entry.getValue()); } req.addHeader("X-Dc-Version", DcCoreTestConfig.getCoreVersion()); debugHttpRequest(req, data); DcResponse res = request(req); return res; }
From source file:com.sf.httpclient.core.HttpHandler.java
private void makeRequestWithRetries(HttpUriRequest request) throws IOException { if (isResume && targetUrl != null) { File downloadFile = new File(targetUrl); long fileLen = 0; if (downloadFile.isFile() && downloadFile.exists()) { fileLen = downloadFile.length(); }/*from w w w .ja v a2 s . c o m*/ if (fileLen > 0) request.setHeader("RANGE", "bytes=" + fileLen + "-"); } boolean retry = true; IOException cause = null; HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (retry) { try { if (!isCancelled()) { HttpResponse response = client.execute(request, context); if (!isCancelled()) { handleResponse(response); } } return; } catch (UnknownHostException e) { publishProgress(UPDATE_FAILURE, e, 0, "unknownHostExceptioncan't resolve host"); return; } catch (IOException e) { cause = e; retry = retryHandler.retryRequest(cause, ++executionCount, context); } catch (NullPointerException e) { cause = new IOException("NPE in HttpClient" + e.getMessage()); retry = retryHandler.retryRequest(cause, ++executionCount, context); } catch (Exception e) { cause = new IOException("Exception" + e.getMessage()); retry = retryHandler.retryRequest(cause, ++executionCount, context); } } if (cause != null) throw cause; else throw new IOException(""); }
From source file:com.fujitsu.dc.test.jersey.DcRestAdapter.java
/** * ??? POST.//from w ww . ja v a 2s.com * @param url URL * @param data ?? * @param headers ?? * @return DcResponse * @throws DcException DAO */ public final DcResponse post(final String url, final String data, final HashMap<String, String> headers) throws DcException { String contentType = headers.get(HttpHeaders.CONTENT_TYPE); HttpUriRequest req = makePostRequest(url, data, contentType); for (Map.Entry<String, String> entry : headers.entrySet()) { req.setHeader(entry.getKey(), entry.getValue()); } req.addHeader("X-Dc-Version", DcCoreTestConfig.getCoreVersion()); debugHttpRequest(req, data); DcResponse res = request(req); return res; }
From source file:io.personium.test.jersey.PersoniumRestAdapter.java
/** * ??? PUT.// ww w. ja v a 2 s .c o m * @param url URL * @param data ?? * @param headers ?? * @return DcResponse * @throws PersoniumException DAO */ public final PersoniumResponse put(final String url, final String data, final HashMap<String, String> headers) throws PersoniumException { String contentType = headers.get(HttpHeaders.CONTENT_TYPE); HttpUriRequest req = makePutRequest(url, data, contentType); for (Map.Entry<String, String> entry : headers.entrySet()) { req.setHeader(entry.getKey(), entry.getValue()); } req.addHeader("X-Personium-Version", PersoniumCoreTestConfig.getCoreVersion()); debugHttpRequest(req, data); PersoniumResponse res = request(req); return res; }
From source file:com.haoqee.chat.global.VoiceTask.java
private void makeRequestWithRetries(HttpUriRequest request) throws IOException { if (isResume && targetUrl != null) { File downloadFile = new File(targetUrl); long fileLen = 0; if (downloadFile.isFile() && downloadFile.exists()) { fileLen = downloadFile.length(); }/*w w w. j a va2 s . c om*/ if (fileLen > 0) request.setHeader("RANGE", "bytes=" + fileLen + "-"); } boolean retry = true; IOException cause = null; HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (retry) { try { if (!isCancelled()) { HttpResponse response = client.execute(request, context); if (!isCancelled()) { handleResponse(response); } } return; } catch (UnknownHostException e) { publishProgress(UPDATE_FAILURE, e, "unknownHostExceptioncan't resolve host"); return; } catch (IOException e) { cause = e; retry = retryHandler.retryRequest(cause, ++executionCount, context); } catch (NullPointerException e) { // HttpClient 4.0.x ?bug // http://code.google.com/p/android/issues/detail?id=5255 cause = new IOException("NPE in HttpClient" + e.getMessage()); retry = retryHandler.retryRequest(cause, ++executionCount, context); } catch (Exception e) { cause = new IOException("Exception" + e.getMessage()); retry = retryHandler.retryRequest(cause, ++executionCount, context); } } if (cause != null) throw cause; else throw new IOException(""); }
From source file:io.personium.test.jersey.PersoniumRestAdapter.java
/** * ??? POST.//from www. j av a 2s.c om * @param url URL * @param data ?? * @param headers ?? * @return DcResponse * @throws PersoniumException DAO */ public final PersoniumResponse post(final String url, final String data, final HashMap<String, String> headers) throws PersoniumException { String contentType = headers.get(HttpHeaders.CONTENT_TYPE); HttpUriRequest req = makePostRequest(url, data, contentType); for (Map.Entry<String, String> entry : headers.entrySet()) { req.setHeader(entry.getKey(), entry.getValue()); } req.addHeader("X-Personium-Version", PersoniumCoreTestConfig.getCoreVersion()); debugHttpRequest(req, data); PersoniumResponse res = request(req); return res; }
From source file:cn.com.dfc.pl.afinal.http.HttpHandler.java
private void makeRequestWithRetries(HttpUriRequest request) throws IOException { if (isResume && targetUrl != null) { File downloadFile = new File(targetUrl); long fileLen = 0; if (downloadFile.isFile() && downloadFile.exists()) { fileLen = downloadFile.length(); }//from w ww . ja v a 2 s. c om if (fileLen > 0) request.setHeader("RANGE", "bytes=" + fileLen + "-"); } boolean retry = true; IOException cause = null; HttpRequestRetryHandler retryHandler = client.getHttpRequestRetryHandler(); while (retry) { try { if (!isCancelled()) { HttpResponse response = client.execute(request, context); if (!isCancelled()) { handleResponse(response); } } return; } catch (UnknownHostException e) { publishProgress(UPDATE_FAILURE, e, 0, "unknownHostExceptioncan't resolve host"); return; } catch (IOException e) { cause = e; retry = retryHandler.retryRequest(cause, ++executionCount, context); } catch (NullPointerException e) { // HttpClient 4.0.x ?bug // http://code.google.com/p/android/issues/detail?id=5255 cause = new IOException("NPE in HttpClient" + e.getMessage()); retry = retryHandler.retryRequest(cause, ++executionCount, context); } catch (Exception e) { cause = new IOException("Exception" + e.getMessage()); retry = retryHandler.retryRequest(cause, ++executionCount, context); } } if (cause != null) throw cause; else throw new IOException(""); }
From source file:com.fujitsu.dc.test.jersey.DcRestAdapter.java
/** * Stream?PUT./*from w w w.java 2s .co m*/ * @param url PUT?URL * @param headers ?? * @param is PUT? * @return DcResponse * @throws DcException DAO */ public final DcResponse put(final String url, final HashMap<String, String> headers, final InputStream is) throws DcException { String contentType = headers.get(HttpHeaders.CONTENT_TYPE); HttpUriRequest req = makePutRequestByStream(url, contentType, is); for (Map.Entry<String, String> entry : headers.entrySet()) { req.setHeader(entry.getKey(), entry.getValue()); } req.addHeader("X-Dc-Version", DcCoreTestConfig.getCoreVersion()); debugHttpRequest(req, "body is InputStream..."); DcResponse res = request(req); return res; }
From source file:io.personium.test.jersey.PersoniumRestAdapter.java
/** * Stream?PUT./* w w w. j av a2 s .c om*/ * @param url PUT?URL * @param headers ?? * @param is PUT? * @return DcResponse * @throws PersoniumException DAO */ public final PersoniumResponse put(final String url, final HashMap<String, String> headers, final InputStream is) throws PersoniumException { String contentType = headers.get(HttpHeaders.CONTENT_TYPE); HttpUriRequest req = makePutRequestByStream(url, contentType, is); for (Map.Entry<String, String> entry : headers.entrySet()) { req.setHeader(entry.getKey(), entry.getValue()); } req.addHeader("X-Personium-Version", PersoniumCoreTestConfig.getCoreVersion()); debugHttpRequest(req, "body is InputStream..."); PersoniumResponse res = request(req); return res; }
From source file:com.hp.mqm.client.AbstractMqmRestClient.java
private void addRequestHeaders(HttpUriRequest request) { request.setHeader(HEADER_CLIENT_TYPE, clientType); }