List of usage examples for org.apache.http.protocol HTTP CONTENT_LEN
String CONTENT_LEN
To view the source code for org.apache.http.protocol HTTP CONTENT_LEN.
Click Source Link
From source file:com.microsoft.exchange.impl.SoapHttpRequestHeaderInterceptor.java
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { if (request.containsHeader(HTTP.TRANSFER_ENCODING)) { request.removeHeaders(HTTP.TRANSFER_ENCODING); }// ww w . ja v a 2 s . c o m if (request.containsHeader(HTTP.CONTENT_LEN)) { request.removeHeaders(HTTP.CONTENT_LEN); } }
From source file:org.muhia.app.psi.integ.config.interceptors.RemoveHttpHeadersInterceptor.java
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { if (request instanceof HttpEntityEnclosingRequest) { if (request.containsHeader(HTTP.TRANSFER_ENCODING)) { request.removeHeaders(HTTP.TRANSFER_ENCODING); }//from w w w . j a v a 2 s. c o m if (request.containsHeader(HTTP.CONTENT_LEN)) { request.removeHeaders(HTTP.CONTENT_LEN); } } }
From source file:com.subgraph.vega.internal.http.proxy.ResponseContentCustom.java
public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); }// www. j av a2 s. c om ProtocolVersion ver = response.getStatusLine().getProtocolVersion(); HttpEntity entity = response.getEntity(); if (entity != null) { long len = entity.getContentLength(); if (entity.isChunked() && !ver.lessEquals(HttpVersion.HTTP_1_0)) { response.removeHeaders(HTTP.CONTENT_LEN); response.setHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING); } else if (len >= 0) { response.removeHeaders(HTTP.TRANSFER_ENCODING); response.setHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength())); } // Specify a content type if known if (entity.getContentType() != null && !response.containsHeader(HTTP.CONTENT_TYPE)) { response.addHeader(entity.getContentType()); } // Specify a content encoding if known if (entity.getContentEncoding() != null && !response.containsHeader(HTTP.CONTENT_ENCODING)) { response.addHeader(entity.getContentEncoding()); } } else { int status = response.getStatusLine().getStatusCode(); if (status != HttpStatus.SC_NO_CONTENT && status != HttpStatus.SC_NOT_MODIFIED && status != HttpStatus.SC_RESET_CONTENT) { response.setHeader(HTTP.CONTENT_LEN, "0"); } } }
From source file:com.example.jarida.http.AsyncConnection.java
@Override public String doInBackground(String... params) { final String method = params[0]; final String urlString = params[1]; final StringBuilder builder = new StringBuilder(); try {//from w w w . j a v a 2 s .c o m final URL url = new URL(urlString); final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod(method); if (method.equals(METHOD_POST)) { final String urlParams = params[2]; conn.setRequestProperty(HTTP.CONTENT_LEN, "" + Integer.toString(urlParams.getBytes().length)); System.out.println(urlParams); // Send request final DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); wr.writeBytes(urlParams); wr.flush(); wr.close(); } // Get Response final InputStream is = conn.getInputStream(); final BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { builder.append(line); } rd.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return builder.toString(); }
From source file:org.deviceconnect.message.http.impl.factory.HttpResponseMessageFactory.java
@Override public HttpResponse newPackagedMessage(final DConnectMessage message) { mLogger.entering(this.getClass().getName(), "newPackagedMessage", message); mLogger.fine("create http request from dmessage"); HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, EnglishReasonPhraseCatalog.INSTANCE.getReason(HttpStatus.SC_OK, null)); mLogger.fine("put request headers"); for (Header header : createHttpHeader(message)) { response.addHeader(header);/*from w ww .j av a 2 s . c o m*/ } mLogger.fine("put request body"); HttpEntity entity = createHttpEntity(message); response.addHeader(HTTP.CONTENT_LEN, "" + entity.getContentLength()); response.setEntity(entity); mLogger.exiting(this.getClass().getName(), "newPackagedMessage", response); return response; }
From source file:com.grendelscan.commons.http.apache_overrides.client.CustomRequestContent.java
@Override public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); }/*from ww w .j a va2s .c o m*/ if (request instanceof HttpEntityEnclosingRequest) { if (request.containsHeader(HTTP.TRANSFER_ENCODING)) { request.removeHeaders(HTTP.TRANSFER_ENCODING); } if (request.containsHeader(HTTP.CONTENT_LEN)) { request.removeHeaders(HTTP.CONTENT_LEN); } ProtocolVersion ver = request.getRequestLine().getProtocolVersion(); HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); if (entity == null) { request.addHeader(HTTP.CONTENT_LEN, "0"); return; } // Must specify a transfer encoding or a content length if (entity.isChunked() || entity.getContentLength() < 0) { if (ver.lessEquals(HttpVersion.HTTP_1_0)) { throw new ProtocolException("Chunked transfer encoding not allowed for " + ver); } request.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING); } else { request.addHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength())); } // Specify a content type if known if (entity.getContentType() != null && !request.containsHeader(HTTP.CONTENT_TYPE)) { request.addHeader(entity.getContentType()); } // Specify a content encoding if known if (entity.getContentEncoding() != null && !request.containsHeader(HTTP.CONTENT_ENCODING)) { request.addHeader(entity.getContentEncoding()); } } }
From source file:com.huoqiu.framework.rest.HttpComponentsClientHttpRequest.java
@Override public ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException { for (Map.Entry<String, List<String>> entry : headers.entrySet()) { String headerName = entry.getKey(); if (!headerName.equalsIgnoreCase(HTTP.CONTENT_LEN) && !headerName.equalsIgnoreCase(HTTP.TRANSFER_ENCODING)) { for (String headerValue : entry.getValue()) { this.httpRequest.addHeader(headerName, headerValue); }/*from w w w . j a v a 2 s . c o m*/ } } if (this.httpRequest instanceof HttpEntityEnclosingRequest) { HttpEntityEnclosingRequest entityEnclosingReq = (HttpEntityEnclosingRequest) this.httpRequest; HttpEntity requestEntity = new ByteArrayEntity(bufferedOutput); entityEnclosingReq.setEntity(requestEntity); } HttpResponse httpResponse = httpClient.execute(this.httpRequest, this.httpContext); return new HttpComponentsClientHttpResponse(httpResponse); }
From source file:org.deviceconnect.message.http.impl.factory.HttpRequestMessageFactory.java
@Override public HttpRequest newPackagedMessage(final DConnectMessage message) { mLogger.entering(this.getClass().getName(), "newPackagedMessage", message); mLogger.fine("create http request from dmessage"); HttpRequest request;/* w w w . j a v a2s. c om*/ try { request = createHttpRequest(message); } catch (URISyntaxException e) { mLogger.log(Level.INFO, e.toString(), e); mLogger.warning(e.toString()); throw new IllegalArgumentException(e.toString()); } mLogger.fine("put request headers"); for (Header header : createHttpHeader(message)) { request.addHeader(header); } mLogger.fine("put request body"); if (request instanceof HttpEntityEnclosingRequest) { HttpEntity entity = createHttpEntity(message); ((HttpEntityEnclosingRequest) request).setEntity(entity); request.addHeader(HTTP.CONTENT_LEN, "" + entity.getContentLength()); } else { request.addHeader(HTTP.CONTENT_LEN, "0"); } mLogger.exiting(this.getClass().getName(), "newPackagedMessage", request); return request; }
From source file:ch.cyberduck.core.onedrive.OneDriveCommonsHttpRequestExecutor.java
protected Upload doUpload(final URL url, final Set<RequestHeader> headers, final HttpEntityEnclosingRequestBase request) { for (RequestHeader header : headers) { if (header.getKey().equals(HTTP.TRANSFER_ENCODING)) { continue; }/* w w w.j a v a2 s . c om*/ if (header.getKey().equals(HTTP.CONTENT_LEN)) { continue; } request.addHeader(new BasicHeader(header.getKey(), header.getValue())); } final CountDownLatch entry = new CountDownLatch(1); final DelayedHttpEntity entity = new DelayedHttpEntity(entry) { @Override public long getContentLength() { for (RequestHeader header : headers) { if (header.getKey().equals(HTTP.CONTENT_LEN)) { return Long.valueOf(header.getValue()); } } // Content-Encoding: chunked return -1L; } }; request.setEntity(entity); final DefaultThreadPool executor = new DefaultThreadPool(String.format("http-%s", url), 1); final Future<CloseableHttpResponse> future = executor.execute(new Callable<CloseableHttpResponse>() { @Override public CloseableHttpResponse call() throws Exception { return client.execute(request); } }); return new Upload() { @Override public Response getResponse() throws IOException { final CloseableHttpResponse response; try { response = future.get(); } catch (InterruptedException e) { throw new IOException(e); } catch (ExecutionException e) { throw new IOException(e.getCause()); } finally { executor.shutdown(false); } return new CommonsHttpResponse(response); } @Override public OutputStream getOutputStream() { try { // Await execution of HTTP request to make stream available entry.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } return entity.getStream(); } }; }