Refine search
LOG.trace("enter HttpMethodBase.recycle()"); releaseConnection(); doAuthentication = true; queryString = null; getRequestHeaderGroup().clear(); getResponseHeaderGroup().clear(); getResponseTrailerHeaderGroup().clear(); statusLine = null; effectiveVersion = null; aborted = false; used = false; params = new HttpMethodParams(); responseBody = null; recoverableExceptionCount = 0;
InputStream instream = getResponseBodyAsStream(); if (instream != null) { long contentLength = getResponseContentLength(); if (contentLength > Integer.MAX_VALUE) { //guard below cast from overflow throw new IOException("Content too large to be buffered: "+ contentLength +" bytes"); int limit = getParams().getIntParameter(HttpMethodParams.BUFFER_WARN_TRIGGER_LIMIT, 1024*1024); if ((contentLength == -1) || (contentLength > limit)) { LOG.warn("Going to buffer response body of large or unknown size. " setResponseStream(null); this.responseBody = outstream.toByteArray();
/** * Returns the character encoding of the response from the <tt>Content-Type</tt> header. * * @return String The character set. */ public String getResponseCharSet() { return getContentCharSet(getResponseHeader("Content-Type")); }
/** * Returns the request line. * * @param conn the {@link HttpConnection connection} used to execute * this HTTP method * * @return The request line. */ private String getRequestLine(HttpConnection conn) { return HttpMethodBase.generateRequestLine(conn, getName(), getPath(), getQueryString(), this.effectiveVersion.toString()); }
/** * Generates default <tt>User-Agent</tt> request header, as long as no * <tt>User-Agent</tt> request header already exists. * * @param state the {@link HttpState state} information associated with this method * @param conn the {@link HttpConnection connection} used to execute * this HTTP method * * @throws IOException if an I/O (transport) error occurs. Some transport exceptions * can be recovered from. * @throws HttpException if a protocol exception occurs. Usually protocol exceptions * cannot be recovered from. */ protected void addUserAgentRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { LOG.trace("enter HttpMethodBase.addUserAgentRequestHeaders(HttpState, " + "HttpConnection)"); if (getRequestHeader("User-Agent") == null) { String agent = (String)getParams().getParameter(HttpMethodParams.USER_AGENT); if (agent == null) { agent = "Jakarta Commons-HttpClient"; } setRequestHeader("User-Agent", agent); } }
private SimpleResponse executeSimpleRequest(final HttpMethodBase request) throws IOException { int status = getClient().executeMethod(request); return parseSimpleResponse(status, request.getStatusText(), request.getResponseBodyAsStream(), request.getResponseCharSet()); }
private Transferable initBasicResponseTransferable(HttpMethodBase method) throws IOException, HttpException { m_client.executeMethod(method); Header contentTypeHeader = method.getResponseHeader("Content-Type"); String contentType = contentTypeHeader != null ? contentTypeHeader.getValue() : ""; Transferable trans = TransferableFactory.getInstance().createStreamTransferable(contentType, method.getResponseBodyAsStream(), method.getResponseCharSet()); return trans; }
protected void executeMethod(final HttpMethodBase method) throws BigSwitchBcfApiException { try { _client.executeMethod(method); if (method.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { method.releaseConnection(); } } catch (HttpException e) { S_LOGGER.error("HttpException caught while trying to connect to the BigSwitch Controller", e); method.releaseConnection(); throw new BigSwitchBcfApiException("API call to BigSwitch Controller Failed", e); } catch (IOException e) { S_LOGGER.error("IOException caught while trying to connect to the BigSwitch Controller", e); method.releaseConnection(); throw new BigSwitchBcfApiException("API call to BigSwitch Controller Failed", e); } }
private DownloadResponse executeDownloadRequest(final HttpMethodBase request, final File outputFile) throws IOException { int status = getClient().executeMethod(request); return parseDownloadResponse(status, request.getStatusText(), request.getResponseBodyAsStream(), outputFile); }
public void executeMethod(final HttpMethodBase method) throws NeutronRestApiException { try { client.executeMethod(method); } catch (HttpException e) { s_logger.error("HttpException caught while trying to connect to the Neutron Controller", e); method.releaseConnection(); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } catch (IOException e) { s_logger.error("IOException caught while trying to connect to the Neutron Controller", e); method.releaseConnection(); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } }
try { if (null != queryString) { httpClientMethod.setQueryString(queryString); httpClientMethod.addRequestHeader(entry.getKey(), entry.getValue()); this.statusCode = client.executeMethod(httpClientMethod); } catch (IOException e) { throw new TestException(e);
@Override public ClientHttpResponse executeInternal(HttpHeaders headers, byte[] output) throws IOException { for (Map.Entry<String, List<String>> entry : headers.entrySet()) { String headerName = entry.getKey(); for (String headerValue : entry.getValue()) { httpMethod.addRequestHeader(headerName, headerValue); } } if (this.httpMethod instanceof EntityEnclosingMethod) { EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) this.httpMethod; RequestEntity requestEntity = new ByteArrayRequestEntity(output); entityEnclosingMethod.setRequestEntity(requestEntity); } this.httpClient.executeMethod(this.httpMethod); return new CommonsClientHttpResponse(this.httpMethod); }
/** * @see HTTPResponse#getResponseHeader() */ public String getResponseHeader(String headerName) { Header header = method.getResponseHeader(headerName); String headerValue = null; if (header != null) { headerValue = header.getValue(); } return headerValue; }
LOG.trace( "enter HttpMethodBase.writeRequest(HttpState, HttpConnection)"); writeRequestLine(state, conn); writeRequestHeaders(state, conn); conn.writeLine(); // close head if (Wire.HEADER_WIRE.enabled()) { Wire.HEADER_WIRE.output("\r\n"); HttpVersion ver = getParams().getVersion(); Header expectheader = getRequestHeader("Expect"); String expectvalue = null; if (expectheader != null) { expectvalue = expectheader.getValue(); int readTimeout = conn.getParams().getSoTimeout(); try { conn.setSocketTimeout(RESPONSE_WAIT_TIME_MS); readStatusLine(state, conn); processStatusLine(state, conn); readResponseHeaders(state, conn); processResponseHeaders(state, conn); removeRequestHeader("Expect"); LOG.info("100 (continue) read timeout. Resume sending the request"); } finally { removeRequestHeader("Expect"); LOG.info("'Expect: 100-continue' handshake is only supported by " + "HTTP/1.1 or higher");
private String responseToErrorMessage(final HttpMethodBase method) { assert method.isRequestSent() : "no use getting an error message unless the request is sent"; if ("text/html".equals(method.getResponseHeader(CONTENT_TYPE).getValue())) { // The error message is the response content // Safety margin of 2048 characters, anything longer is probably useless // and will clutter the logs try { return method.getResponseBodyAsString(2048); } catch (IOException e) { S_LOGGER.debug("Error while loading response body", e); } } // The default return method.getStatusText(); }
InputStream is = conn.getResponseInputStream(); if (Wire.CONTENT_WIRE.enabled()) { is = new WireLogInputStream(is, Wire.CONTENT_WIRE); boolean canHaveBody = canResponseHaveBody(statusLine.getStatusCode()); InputStream result = null; Header transferEncodingHeader = responseHeaders.getFirstHeader("Transfer-Encoding"); HeaderElement[] encodings = transferEncodingHeader.getElements(); if ((len > 0) && ("chunked".equalsIgnoreCase(encodings[len - 1].getName()))) { if (conn.isResponseAvailable(conn.getParams().getSoTimeout())) { result = new ChunkedInputStream(is, this); } else { if (getParams().isParameterTrue(HttpMethodParams.STRICT_TRANSFER_ENCODING)) { throw new ProtocolException("Chunk-encoded body declared but not sent"); } else { setConnectionCloseForced(true); result = is; long expectedLength = getResponseContentLength(); if (expectedLength == -1) { if (canHaveBody && this.effectiveVersion.greaterEquals(HttpVersion.HTTP_1_1)) { setConnectionCloseForced(true);
@Override public void addAuthentication(final HttpClient httpClient, final HttpMethodBase method) throws ProponoException { httpClient.getParams().setAuthenticationPreemptive(true); final String header = "Basic " + credentials; method.setRequestHeader("Authorization", header); } }
private String checkResponse(final HttpMethodBase m, final String errorMessageBase) throws BigSwitchBcfApiException, IllegalArgumentException{ String customErrorMsg = null; if (m.getStatusCode() == HttpStatus.SC_OK) { String hash = ""; if (m.getResponseHeader(HASH_MATCH) != null) { hash = m.getResponseHeader(HASH_MATCH).getValue(); set_hash(hash); if (m.getStatusCode() == HttpStatus.SC_CONFLICT) { if(m instanceof GetMethod) { return HASH_CONFLICT; if (m.getStatusCode() == HttpStatus.SC_SEE_OTHER) { isMaster = false; set_hash(HASH_IGNORE); return HASH_IGNORE; if (m.getStatusCode() == HttpStatus.SC_NOT_FOUND) { if (m instanceof DeleteMethod){ return ""; if (m.getStatusCode() == HttpStatus.SC_BAD_REQUEST) { customErrorMsg = " Invalid data in BCF request"; throw new IllegalArgumentException(customErrorMsg); m.releaseConnection(); S_LOGGER.error(errorMessageBase + errorMessage); throw new BigSwitchBcfApiException(errorMessageBase + errorMessage + customErrorMsg);
/** * Adds the specified request header, NOT overwriting any previous value. * Note that header-name matching is case insensitive. * * @param headerName the header's name * @param headerValue the header's value */ public void addRequestHeader(String headerName, String headerValue) { addRequestHeader(new Header(headerName, headerValue)); }
private void prepareResponseProxyHeaders(HttpMethodBase method, HttpServletResponse response) { /* Copied from j2ep */ Header originalVia = method.getResponseHeader("via"); StringBuffer via = new StringBuffer(""); if (originalVia != null) { via.append(originalVia.getValue()).append(", "); } via.append(method.getStatusLine().getHttpVersion()).append(" ").append(SERVER_HOST_NAME); response.setHeader("via", via.toString()); }