List of usage examples for org.apache.commons.httpclient HttpMethod getRequestHeader
public abstract Header getRequestHeader(String paramString);
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 ww w . j av a2 s.com 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 w ww. ja va2s. 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:fr.cls.atoll.motu.library.cas.HttpClientCAS.java
/** * Adds the cas ticket from tgt./*from ww w. j av a 2 s . c o m*/ * * @param method the method * @return true, if successful * @throws MotuCasException the motu cas exception * @throws URIException the uRI exception * @throws IOException Signals that an I/O exception has occurred. */ public static boolean addCASTicketFromTGT(HttpMethod method) throws MotuCasException, URIException, IOException { if (LOG.isDebugEnabled()) { LOG.debug("addCASTicketFromTGT(HttpMethod) - entering : debugHttpMethod BEFORE " + HttpClientCAS.debugHttpMethod(method)); } Header headerTgt = method.getRequestHeader(HttpClientCAS.TGT_PARAM); Header headerCasRestUrl = method.getRequestHeader(HttpClientCAS.CAS_REST_URL_PARAM); if ((headerTgt == null) || (headerCasRestUrl == null)) { return false; } String ticketGrantingTicket = headerTgt.getValue(); String casRestUrl = headerCasRestUrl.getValue(); if ((RestUtil.isNullOrEmpty(ticketGrantingTicket)) || (RestUtil.isNullOrEmpty(casRestUrl))) { return false; } String ticket = RestUtil.loginToCASWithTGT(casRestUrl, ticketGrantingTicket, method.getURI().getEscapedURI()); String newURIAsString = AssertionUtils.addCASTicket(ticket, method.getURI().getEscapedURI()); if (!AssertionUtils.hasCASTicket(newURIAsString)) { throw new MotuCasException(String.format( "Unable to access resource '%s'. This resource has been declared as CASified, but the Motu application/API can't retrieve any ticket from CAS via REST. \nFor information, current TGT is:'%s', CAS REST url is:'%s'", method.getURI().getEscapedURI(), ticketGrantingTicket, casRestUrl)); } URI newURI = new URI(newURIAsString, true); // method.setURI(newURI); method.setPath(newURI.getPath()); method.setQueryString(newURI.getQuery()); // System.out.println(newURI.getPathQuery()); if (LOG.isDebugEnabled()) { LOG.debug("addCASTicketFromTGT(HttpMethod) - exiting : debugHttpMethod AFTER " + HttpClientCAS.debugHttpMethod(method)); } return true; }
From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClient3CookieExtractor.java
@Override public String getCookie(HttpMethod httpMethod) { final org.apache.commons.httpclient.Header cookie = httpMethod.getRequestHeader("Cookie"); if (cookie != null) { final String value = cookie.getValue(); if (StringUtils.hasLength(value)) { return value; }//from w w w . jav a2 s .c om } return null; }
From source file:com.cyberway.issue.httpclient.HttpRecorderMethod.java
/** * If a 'Proxy-Connection' header has been added to the request, * it'll be of a 'keep-alive' type. Until we support 'keep-alives', * override the Proxy-Connection setting and instead pass a 'close' * (Otherwise every request has to timeout before we notice * end-of-document)./*from w ww. j a v a 2 s.c o m*/ * @param method Method to find proxy-connection header in. */ public void handleAddProxyConnectionHeader(HttpMethod method) { Header h = method.getRequestHeader("Proxy-Connection"); if (h != null) { h.setValue("close"); method.setRequestHeader(h); } }
From source file:davmail.http.DavGatewayHttpClientFacade.java
/** * Build Http Exception from methode status * * @param method Http Method// ww w . j a va 2 s .c o m * @return Http Exception */ public static HttpException buildHttpException(HttpMethod method) { int status = method.getStatusCode(); StringBuilder message = new StringBuilder(); message.append(status).append(' ').append(method.getStatusText()); try { message.append(" at ").append(method.getURI().getURI()); if (method instanceof CopyMethod || method instanceof MoveMethod) { message.append(" to ").append(method.getRequestHeader("Destination")); } } catch (URIException e) { message.append(method.getPath()); } // 440 means forbidden on Exchange if (status == 440) { return new LoginTimeoutException(message.toString()); } else if (status == HttpStatus.SC_FORBIDDEN) { return new HttpForbiddenException(message.toString()); } else if (status == HttpStatus.SC_NOT_FOUND) { return new HttpNotFoundException(message.toString()); } else if (status == HttpStatus.SC_PRECONDITION_FAILED) { return new HttpPreconditionFailedException(message.toString()); } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) { return new HttpServerErrorException(message.toString()); } else { return new HttpException(message.toString()); } }
From source file:com.utest.webservice.client.rest.RestClient.java
private void processResponse(HttpMethod method) throws IOException { method.getRequestHeader("Accept"); responseStream = method.getResponseBodyAsStream(); }
From source file:com.baidu.oped.apm.profiler.modifier.connector.httpclient3.interceptor.ExecuteInterceptor.java
private void recordCookie(HttpMethod httpMethod, Trace trace) { org.apache.commons.httpclient.Header cookie = httpMethod.getRequestHeader("Cookie"); if (cookie == null) { return;//from w ww . ja va 2s .co m } final String value = cookie.getValue(); if (value != null && !value.isEmpty()) { if (cookieSampler.isSampling()) { trace.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.drop(value, MAX_READ_SIZE)); } } }
From source file:com.navercorp.pinpoint.plugin.httpclient3.interceptor.ExecuteInterceptor.java
private void recordCookie(HttpMethod httpMethod, Trace trace) { org.apache.commons.httpclient.Header cookie = httpMethod.getRequestHeader("Cookie"); if (cookie == null) { return;//from ww w . jav a2s . c om } final String value = cookie.getValue(); if (value != null && !value.isEmpty()) { if (cookieSampler.isSampling()) { trace.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.drop(value, MAX_READ_SIZE)); } } }
From source file:com.yahoo.flowetl.services.http.BaseHttpGenerator.java
/** * Applies any common properties to the http method based on properties of * the http params given.//from w w w.ja va2 s.c om */ protected void applyCommonProperties(HttpParams in, HttpMethod toCall) { // common ops if (in.headers != null) { for (Entry<String, String> e : in.headers.entrySet()) { toCall.addRequestHeader(e.getKey(), e.getValue()); } } // we handle our own retries toCall.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); if (StringUtils.isBlank(in.userAgent) == false && toCall.getRequestHeader(USER_AGENT_HEADER) == null) { toCall.setRequestHeader(USER_AGENT_HEADER, in.userAgent); } else if (toCall.getRequestHeader(USER_AGENT_HEADER) == null) { toCall.setRequestHeader(USER_AGENT_HEADER, userAgent); } }