List of usage examples for org.apache.commons.httpclient HttpMethod hasBeenUsed
public abstract boolean hasBeenUsed();
From source file:com.intellij.tasks.impl.httpclient.TaskResponseUtil.java
public static void prettyFormatResponseToLog(@Nonnull Logger logger, @Nonnull HttpMethod response) { if (logger.isDebugEnabled() && response.hasBeenUsed()) { try {/*from w w w . j a va 2 s. c o m*/ String content = TaskResponseUtil.getResponseContentAsString(response); org.apache.commons.httpclient.Header header = response.getRequestHeader(HTTP.CONTENT_TYPE); String contentType = header == null ? "text/plain" : header.getElements()[0].getName().toLowerCase(Locale.ENGLISH); if (contentType.contains("xml")) { TaskUtil.prettyFormatXmlToLog(logger, content); } else if (contentType.contains("json")) { TaskUtil.prettyFormatJsonToLog(logger, content); } else { logger.debug(content); } } catch (IOException e) { logger.error(e); } } }
From source file:com.intellij.tasks.impl.TaskUtil.java
public static void prettyFormatResponseToLog(@Nonnull Logger logger, @Nonnull HttpMethod response) { if (logger.isDebugEnabled() && response.hasBeenUsed()) { try {//from ww w . ja v a 2 s .c o m String content = ResponseUtil.getResponseContentAsString(response); Header header = response.getRequestHeader(HTTP.CONTENT_TYPE); String contentType = header == null ? "text/plain" : header.getElements()[0].getName().toLowerCase(Locale.ENGLISH); if (contentType.contains("xml")) { prettyFormatXmlToLog(logger, content); } else if (contentType.contains("json")) { prettyFormatJsonToLog(logger, content); } else { logger.debug(content); } } catch (IOException e) { logger.error(e); } } }
From source file:edu.utah.further.core.ws.HttpUtil.java
/** * Static method for retrieving the response from an already executed method. This * method does not responsible for closing the inputstream unless an exception occurs * during retrieval of the response.//from w ww. j av a 2 s . c o m * * @param method * @return */ public static InputStream getHttpResponseStream(final HttpMethod method) { isTrue(method.hasBeenUsed()); Exception exception = null; try { return method.getResponseBodyAsStream(); } catch (final IOException e) { exception = e; throw new ApplicationException("An exception occured while retrieving the response", e); } finally { if (exception != null) { method.releaseConnection(); } } }
From source file:org.parosproxy.paros.network.HttpMethodHelper.java
public static void updateHttpRequestHeaderSent(HttpRequestHeader req, HttpMethod httpMethodSent) { // Not used yet, no need to update request. if (!httpMethodSent.hasBeenUsed()) { return;//from w ww. ja v a 2 s . co m } StringBuilder sb = new StringBuilder(200); String name = null; String value = null; // add status line sb.append(req.getPrimeHeader()).append(CRLF); Header[] header = httpMethodSent.getRequestHeaders(); for (int i = 0; i < header.length; i++) { name = header[i].getName(); value = header[i].getValue(); sb.append(name).append(": ").append(value).append(CRLF); } sb.append(CRLF); try { req.setMessage(sb.toString()); } catch (HttpMalformedHeaderException e) { logger.error(e.getMessage(), e); } }