List of usage examples for org.apache.commons.httpclient HttpMethod getStatusCode
public abstract int getStatusCode();
From source file:com.thoughtworks.go.helpers.HttpClientHelper.java
public int httpRequestForHeaders(final String path, RequestMethod methodRequired) throws Exception { HttpMethod method = doRequest(path, methodRequired, ""); return method.getStatusCode(); }
From source file:com.cordys.coe.ac.httpconnector.samples.JIRACreateProjectResponseHandler.java
/** * @see com.cordys.coe.ac.httpconnector.samples.JIRAResponseHandler#buildXMLResponse(int,org.w3c.dom.Document, * com.eibus.xml.nom.Document)//from w ww. ja va2s . c om */ @Override protected void buildXMLResponse(int resNode, HttpMethod httpMethod, Document document, com.eibus.xml.nom.Document doc) throws Exception { if (httpMethod.getStatusCode() == 302) { // It's a redirect to the details screen for the newly created // project. We'll follow // the redirect. Header location = httpMethod.getResponseHeader("Location"); if (location != null) { String loc = location.getValue(); // Get the PID via a regex Matcher m = PATTERN_PID.matcher(loc); if (m.find()) { loc = m.group(1); // Now we need to get the project ID from the URL. int tuple = doc.createElementWithParentNS("tuple", null, resNode); int old = doc.createElementWithParentNS("old", null, tuple); int project = doc.createElementWithParentNS("project", null, old); doc.createElementWithParentNS("projectid", loc, project); } } } }
From source file:com.hp.alm.ali.rest.client.filter.IssueTicketFilter.java
@Override public Filter applyFilter(Filter filter, HttpMethod method, ResultInfo resultInfo) { Header contentType = method.getResponseHeader("Content-type"); if (method.getStatusCode() == 500 && contentType != null && contentType.getValue().contains("text/html")) { return new MyFilter(filter, resultInfo); } else {//from ww w.j a va 2 s . c o m return filter; } }
From source file:com.zimbra.qa.unittest.TestWsdlServlet.java
String doWsdlServletRequest(String wsdlUrl, boolean admin, int expectedCode) throws Exception { Server localServer = Provisioning.getInstance().getLocalServer(); String protoHostPort;/*from w ww . java 2s . co m*/ if (admin) protoHostPort = "https://localhost:" + localServer.getIntAttr(Provisioning.A_zimbraAdminPort, 0); else protoHostPort = "http://localhost:" + localServer.getIntAttr(Provisioning.A_zimbraMailPort, 0); String url = protoHostPort + wsdlUrl; HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(url); try { int respCode = HttpClientUtil.executeMethod(client, method); int statusCode = method.getStatusCode(); String statusLine = method.getStatusLine().toString(); ZimbraLog.test.debug("respCode=" + respCode); ZimbraLog.test.debug("statusCode=" + statusCode); ZimbraLog.test.debug("statusLine=" + statusLine); assertTrue("Response code", respCode == expectedCode); assertTrue("Status code", statusCode == expectedCode); Header[] respHeaders = method.getResponseHeaders(); for (int i = 0; i < respHeaders.length; i++) { String header = respHeaders[i].toString(); ZimbraLog.test.debug("ResponseHeader:" + header); } String respBody = method.getResponseBodyAsString(); // ZimbraLog.test.debug("Response Body:" + respBody); return respBody; } catch (HttpException e) { fail("Unexpected HttpException" + e); throw e; } catch (IOException e) { fail("Unexpected IOException" + e); throw e; } finally { method.releaseConnection(); } }
From source file:fr.unix_experience.owncloud_sms.engine.OCHttpClient.java
private int followRedirections(HttpMethod httpMethod) throws IOException { int redirectionsCount = 0; int status = httpMethod.getStatusCode(); while (redirectionsCount < 3 && (status == HttpStatus.SC_MOVED_PERMANENTLY || status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_TEMPORARY_REDIRECT)) { Header location = httpMethod.getResponseHeader("Location"); if (location == null) { location = httpMethod.getResponseHeader("location"); }//from w ww . j a v a 2s .c o m if (location == null) { Log.e(TAG, "No valid location header found when redirecting."); return 500; } try { httpMethod.setURI(new URI(location.getValue())); } catch (URIException e) { Log.e(TAG, "Invalid URI in 302 FOUND response"); return 500; } status = executeMethod(httpMethod); redirectionsCount++; } if (redirectionsCount >= 3 && status == HttpStatus.SC_MOVED_PERMANENTLY || status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_TEMPORARY_REDIRECT) { Log.e(TAG, "Too many redirection done. Aborting, please ensure your server is " + "correctly configured"); return 400; } return status; }
From source file:eionet.eea.template.RefreshTemplateServlet.java
/** * Reads the URL and returns the content. * Pair id - HTTP status code, Pair value - response body. * * @param url url to check./*from w w w . ja v a2 s . c o m*/ * @return */ private Pair<Integer, String> readContentFromUrl(String url) { Pair<Integer, String> result = null; if (StringUtils.isNotBlank(url)) { try { HttpClient client = new HttpClient(); HttpMethod get = new GetMethod(url); client.executeMethod(get); result = new Pair<Integer, String>(); result.setId(get.getStatusCode()); if (get.getStatusCode() != 404) { result.setValue(get.getResponseBodyAsString()); } } catch (Exception e) { e.printStackTrace(); } } return result; }
From source file:ccc.api.http.SiteBrowserImpl.java
private String invoke(final HttpMethod m) { try {//from www.j a va 2s. c o m _httpClient.executeMethod(m); final int status = m.getStatusCode(); if (OK == status) { return m.getResponseBodyAsString(); } throw new RuntimeException(status + ": " + m.getResponseBodyAsString()); } catch (final HttpException e) { throw new InternalError(); // FIXME: Report error. } catch (final IOException e) { throw new InternalError(); // FIXME: Report error. } finally { m.releaseConnection(); } }
From source file:edu.ucsd.xmlrpc.xmlrpc.client.XmlRpcCommonsTransport.java
/** * Check the status of the HTTP request and throw an XmlRpcHttpTransportException if it * indicates that there is an error./* ww w . j av a 2 s . c om*/ * @param pMethod the method that has been executed * @throws XmlRpcHttpTransportException if the status of the method indicates that there is an error. */ private void checkStatus(HttpMethod pMethod) throws XmlRpcHttpTransportException { final int status = pMethod.getStatusCode(); // All status codes except SC_OK are handled as errors. Perhaps some should require special handling (e.g., SC_UNAUTHORIZED) if (status < 200 || status > 299) { throw new XmlRpcHttpTransportException(status, pMethod.getStatusText()); } }
From source file:com.marvelution.hudson.plugins.apiv2.client.connectors.HttpClient3Connector.java
/** * Internal method to convert a {@link HttpMethod} into a {@link ConnectorResponse} * //from w w w . j a va 2s.c o m * @param method the {@link HttpMethod} to convert * @return the {@link ConnectorResponse} * @throws ConnectionException in case of errors while creating the {@link ConnectorResponse} */ private ConnectorResponse getConnectorResponseFromMethod(HttpMethod method) throws ConnectionException { ConnectorResponse response = new ConnectorResponse(); response.setStatusCode(method.getStatusCode()); response.setReasonPhrase(method.getStatusText()); try { response.setResponseAsStream(method.getResponseBodyAsStream()); } catch (IOException e) { throw new ConnectionException("Failed to copy the response stream", e); } return response; }
From source file:ar.com.zauber.commons.web.proxy.HttpClientRequestProxy.java
/** * Mtodo ideado para overriding en caso de necesitar realizar logs, o modificar * el response code. Para transformaciones del body, agregar un transformer. * // w ww . j a va 2 s . c om * @param request * @param response * @param method * @throws IOException . */ // CHECKSTYLE:DESIGN:OFF protected void updateResponseCode(final HttpServletRequest request, final HttpServletResponse response, final HttpMethod method) throws IOException { response.setStatus(method.getStatusCode()); }