List of usage examples for org.apache.commons.httpclient HttpMethodBase getResponseHeader
@Override
public Header getResponseHeader(String headerName)
From source file:com.google.gsa.valve.modules.utils.HTTPAuthZProcessor.java
/** * Processes the HTTP response to check the content type and parsers then * the document depending on the kind of content. * //from w w w .j a v a 2s . c om * @param response HTTP response * @param method HTTP method * @param url document url * @param loginUrl login url */ public static void processResponse(HttpServletResponse response, HttpMethodBase method, String url, String loginUrl) { logger.debug("Processing Response"); String contentType = method.getResponseHeader("Content-Type").getValue(); logger.debug("Content Type is... " + contentType); if (contentType != null) { if (contentType.startsWith("text/html")) { //content Type is HTML //Check if HTML has to be processed (URLs rewritten) boolean processHTML = AuthorizationUtils.isProcessHTML(); if (processHTML) { logger.debug("It's an HTML doc that is going to be processed (URLs rewritten)"); try { //process HTML document logger.debug("Document is HTML. Processing"); processHTML(response, method, url, loginUrl, contentType); } catch (IOException e) { logger.error("I/O Error processing HTML document: " + e.getMessage(), e); } catch (ParserException e) { logger.error("Parsering Error processing HTML document: " + e.getMessage(), e); } catch (Exception e) { logger.error("Error processing HTML document: " + e.getMessage(), e); } } else { logger.debug("It's an HTML doc that is NOT going to be processed (return content as is)"); try { returnHTML(response, method, url, loginUrl, contentType); } catch (IOException e) { logger.error("I/O Error returning HTML document: " + e.getMessage(), e); } catch (Exception e) { logger.error("Error returning HTML document: " + e.getMessage(), e); } } } else { //non html document type //content Type is NOT HTML try { logger.debug("Document is not HTML. Processing"); //Set document's name setDocumentName(response, method, contentType); //process non HTML document processNonHTML(response, method); } catch (IOException e) { logger.error("I/O Error processing NON HTML document: " + e.getMessage(), e); } catch (Exception e) { logger.error("Error processing NON HTML document: " + e.getMessage(), e); } } } // End contenttype check not null }
From source file:com.jaspersoft.ireport.jasperserver.ws.CommonsHTTPSender.java
private static String getHeader(HttpMethodBase method, String headerName) { Header header = method.getResponseHeader(headerName); return (header == null) ? null : header.getValue().trim(); }
From source file:com.honnix.cheater.validator.ContentValidator.java
public boolean isLoginValid(HttpClient httpClient, HttpMethodBase method) { boolean result = false; Header header = method.getResponseHeader("location"); if (header != null && CheaterConstant.AFTER_LOGIN_URL.equals(header.getValue())) { result = true;/*from w w w. j av a 2s. c o m*/ } return result; }
From source file:com.cyberway.issue.crawler.processor.recrawl.FetchHistoryProcessor.java
/** * Save a header from the given HTTP operation into the AList. * // w w w . ja v a2s . c o m * @param name header name to save into history AList * @param method http operation containing headers * @param latestFetch AList to get header */ protected void saveHeader(String name, HttpMethodBase method, AList latestFetch) { Header header = method.getResponseHeader(name); if (header != null) { latestFetch.putString(name, header.getValue()); } }
From source file:JiraWebSessionCallback.java
protected boolean expectRedirect(HttpMethodBase method, String page, boolean fullMatch) throws JiraException { if (method.getStatusCode() != HttpStatus.SC_MOVED_TEMPORARILY) { return false; }// www. j a v a 2 s.c o m Header locationHeader = method.getResponseHeader("location"); //$NON-NLS-1$ if (locationHeader == null) { throw new JiraRedirectException(); } String url = locationHeader.getValue(); if (fullMatch) { // only if followRedirects is enabled the baseUrl is guaranteed to match the redirect url, otherwise the repository might be sending back a different url if ((followRedirects && !url.startsWith(baseUrl + page)) || (!followRedirects && !url.endsWith(page))) { throw new JiraRedirectException(url); } } else { // the client does not know exactly where the repository will redirect to if (!url.contains(page)) { throw new JiraRedirectException(url); } } return true; }
From source file:net.praqma.jenkins.rqm.request.RQMHttpClient.java
public void followRedirects(HttpMethodBase method, int responseCode) throws HttpException, IOException { Header location = method.getResponseHeader("Location"); while (location != null && responseCode == HttpURLConnection.HTTP_MOVED_TEMP) { GetMethod get3 = new GetMethod(location.getValue()); responseCode = executeMethod(get3); if (responseCode != HttpURLConnection.HTTP_OK) { log.fine(String.format("Follow redirects returned code %s", responseCode)); }/* w w w . j a v a 2s. c om*/ location = get3.getResponseHeader("Location"); } }
From source file:com.google.enterprise.connector.sharepoint.wsclient.soap.SPClientFactory.java
public String getResponseHeader(HttpMethodBase method, String headerName) { String headerValue = null;// w ww.jav a 2s. c o m final Header header = method.getResponseHeader(headerName); if (null != header) { headerValue = header.getValue(); } return headerValue; }
From source file:com.cloud.network.bigswitch.BigSwitchVnsApi.java
private String responseToErrorMessage(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 1024 characters, anything longer is probably useless // and will clutter the logs try {/*from w w w.ja v a2 s.c o m*/ return method.getResponseBodyAsString(1024); } catch (IOException e) { s_logger.debug("Error while loading response body", e); } } // The default return method.getStatusText(); }
From source file:edu.cmu.cs.diamond.pathfind.DjangoAnnotationStore.java
private int maybeAuthenticate(HttpMethodBase method, int code) throws MalformedChallengeException, IOException, HttpException { while (code == 401) { // let's authenticate Header header = method.getResponseHeader("WWW-Authenticate"); System.out.println(header); String scheme = AuthChallengeParser.extractScheme(header.getValue()); Map<?, ?> params = AuthChallengeParser.extractParams(header.getValue()); if (!scheme.equals("login")) { throw new IOException("Authentication requested but of unknown scheme: " + scheme); }/*from w w w .ja v a 2s. c om*/ // get the login form String loginuri = (String) params.get("realm"); login(loginuri); // try again code = httpClient.executeMethod(method); } return code; }
From source file:com.sittinglittleduck.DirBuster.Worker.java
private void parseHtml(HttpMethodBase httpMethod, String response) { // parse the html of what we have found Header contentType = httpMethod.getResponseHeader("Content-Type"); if (contentType != null) { if (contentType.getValue().startsWith("text")) { manager.addHTMLToParseQueue(new HTMLparseWorkUnit(response, work)); }/*from w w w . ja v a2 s . c o m*/ } }