List of usage examples for org.apache.commons.httpclient HttpMethodBase getStatusText
@Override
public String getStatusText()
From source file:org.apache.zeppelin.rest.AbstractTestRestApi.java
protected Matcher<HttpMethodBase> responsesWith(final int expectedStatusCode) { return new TypeSafeMatcher<HttpMethodBase>() { WeakReference<HttpMethodBase> method; @Override//from w w w . j av a2s .co m public boolean matchesSafely(HttpMethodBase httpMethodBase) { method = (method == null) ? new WeakReference<HttpMethodBase>(httpMethodBase) : method; return httpMethodBase.getStatusCode() == expectedStatusCode; } @Override public void describeTo(Description description) { description.appendText("HTTP response ").appendValue(expectedStatusCode).appendText(" from ") .appendText(method.get().getPath()); } @Override protected void describeMismatchSafely(HttpMethodBase item, Description description) { description.appendText("got ").appendValue(item.getStatusCode()).appendText(" ") .appendText(item.getStatusText()); } }; }
From source file:org.eclipse.mylyn.internal.provisional.commons.soap.AxisHttpFault.java
public static AxisHttpFault makeFault(HttpMethodBase method) throws IOException { int returnCode = method.getStatusCode(); String statusMessage = method.getStatusText(); AxisHttpFault fault = new AxisHttpFault("HTTP", "(" + returnCode + ")" + statusMessage, returnCode); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ fault.extractDetails(method);//from www . j a va2 s .co m fault.setFaultDetailString(Messages.getMessage("return01", "" + returnCode, //$NON-NLS-1$ //$NON-NLS-2$ method.getResponseBodyAsString())); fault.addFaultDetail(Constants.QNAME_FAULTDETAIL_HTTPERRORCODE, Integer.toString(returnCode)); return fault; }
From source file:org.fao.geonet.csw.common.requests.CatalogRequest.java
private void setupReceivedData(HttpMethodBase httpMethod, byte[] response) { receivedData = httpMethod.getStatusText() + "\r\r"; for (Header h : httpMethod.getResponseHeaders()) receivedData += h;/* ww w . j a va 2s. co m*/ receivedData += "\r\n"; try { if (response != null) receivedData += new String(response, "UTF8"); } catch (UnsupportedEncodingException e) { // TODO what's this ? } }
From source file:org.fao.oaipmh.requests.Transport.java
private void setupReceivedData(HttpMethodBase httpMethod, byte[] response) { receivedData = httpMethod.getStatusText() + "\r\r"; for (Header h : httpMethod.getResponseHeaders()) receivedData += h;/* w ww . j a va2 s. c om*/ receivedData += "\r\n"; try { if (response != null) receivedData += new String(response, "UTF8"); } catch (UnsupportedEncodingException e) { } }
From source file:org.jboss.ejb3.test.clusteredservice.unit.HttpUtils.java
public static HttpMethodBase accessURL(URL url, String realm, int expectedHttpCode, Header[] hdrs, int type) throws Exception { HttpClient httpConn = new HttpClient(); HttpMethodBase request = createMethod(url, type); int hdrCount = hdrs != null ? hdrs.length : 0; for (int n = 0; n < hdrCount; n++) request.addRequestHeader(hdrs[n]); try {/*from w ww .j a v a2 s . co m*/ log.debug("Connecting to: " + url); String userInfo = url.getUserInfo(); if (userInfo != null) { UsernamePasswordCredentials auth = new UsernamePasswordCredentials(userInfo); httpConn.getState().setCredentials(realm, url.getHost(), auth); } log.debug("RequestURI: " + request.getURI()); int responseCode = httpConn.executeMethod(request); String response = request.getStatusText(); log.debug("responseCode=" + responseCode + ", response=" + response); String content = request.getResponseBodyAsString(); log.debug(content); // Validate that we are seeing the requested response code if (responseCode != expectedHttpCode) { throw new IOException("Expected reply code:" + expectedHttpCode + ", actual=" + responseCode); } } catch (IOException e) { throw e; } return request; }
From source file:org.jboss.test.jpa.test.AbstractWebJPATest.java
public String accessURL(String url) throws Exception { HttpClient httpConn = new HttpClient(); HttpMethodBase request = new GetMethod(baseURL + url); log.debug("RequestURI: " + request.getURI()); int responseCode = httpConn.executeMethod(request); String response = request.getStatusText(); log.debug("responseCode=" + responseCode + ", response=" + response); String content = request.getResponseBodyAsString(); log.debug(content);//from www . j a va2 s .c o m assertEquals(HttpURLConnection.HTTP_OK, responseCode); return content; }
From source file:org.jboss.test.util.web.HttpUtils.java
public static HttpMethodBase accessURL(URL url, String realm, int expectedHttpCode, Header[] hdrs, int type) throws Exception { HttpClient httpConn = new HttpClient(); HttpMethodBase request = createMethod(url, type); int hdrCount = hdrs != null ? hdrs.length : 0; for (int n = 0; n < hdrCount; n++) request.addRequestHeader(hdrs[n]); try {//from w ww . jav a 2 s .c o m log.debug("Connecting to: " + url); String userInfo = url.getUserInfo(); if (userInfo != null) { UsernamePasswordCredentials auth = new UsernamePasswordCredentials(userInfo); httpConn.getState().setCredentials(realm, url.getHost(), auth); } log.debug("RequestURI: " + request.getURI()); int responseCode = httpConn.executeMethod(request); String response = request.getStatusText(); log.debug("responseCode=" + responseCode + ", response=" + response); String content = request.getResponseBodyAsString(); log.debug(content); // Validate that we are seeing the requested response code if (responseCode != expectedHttpCode) { throw new IOException("Expected reply code:" + expectedHttpCode + ", actual=" + responseCode); } } catch (IOException e) { throw e; } return request; }
From source file:org.jboss.test.web.test.RemoteClassloadingServiceUnitTestCase.java
/** * JBAS-4540, don't leak installation directory info * through the classloading service.//from www . j ava 2 s .c o m */ public void testHttpRequestRevealInstallationDirectory() throws Exception { URL url = new URL(baseURL + "org.jboss.web.WebServer.class"); HttpMethodBase request = HttpUtils.accessURL(url, null, HttpURLConnection.HTTP_NOT_FOUND); String statusText = request.getStatusText(); if (statusText.indexOf(".jar") > 0) fail("Status text reveals installation directory information: " + statusText); }
From source file:org.sonar.wsclient.connectors.HttpClient3Connector.java
private String executeRequest(HttpMethodBase method) { String json = null;// w w w.j a v a 2s. c o m try { httpClient.executeMethod(method); if (method.getStatusCode() == HttpStatus.SC_OK) { json = getResponseBodyAsString(method); } else if (method.getStatusCode() != HttpStatus.SC_NOT_FOUND) { throw new ConnectionException("HTTP error: " + method.getStatusCode() + ", msg: " + method.getStatusText() + ", query: " + method); } } catch (HttpException e) { throw new ConnectionException("Query: " + method, e); } catch (IOException e) { throw new ConnectionException("Query: " + method, e); } finally { if (method != null) { method.releaseConnection(); } } return json; }
From source file:org.sonarqube.ws.connectors.HttpClient3Connector.java
/** * Reauest execution//from w w w .ja v a 2s . c o m * * @param method * method * @return String result */ private String executeRequest(HttpMethodBase method) throws ConnectionException { String json = null; try { httpClient.executeMethod(method); if (method.getStatusCode() == HttpStatus.SC_OK) { json = getResponseBodyAsString(method); } else if (method.getStatusCode() != HttpStatus.SC_NOT_FOUND) { throw new ConnectionException("HTTP error: " + method.getStatusCode() + ", msg: " + method.getStatusText() + ", query: " + method); } } catch (IOException e) { throw new ConnectionException("Query: " + method, e); } finally { if (method != null) { method.releaseConnection(); } } return json; }