List of usage examples for org.apache.commons.httpclient HttpMethodBase getResponseBodyAsString
@Override public String getResponseBodyAsString() throws IOException
From source file:com.google.gsa.valve.modules.utils.HTTPAuthZProcessor.java
/** * Includes the HTML document in the response * /*from www. j a v a2 s. c o m*/ * @param response HTTP response * @param method HTTP method * @param url document url * @param loginUrl login url * @param contentType content type * * @throws IOException */ public static void returnHTML(HttpServletResponse response, HttpMethodBase method, String url, String loginUrl, String contentType) throws IOException { logger.debug("Returning an HTML document"); //Get writer PrintWriter out = null; try { out = response.getWriter(); if (out != null) { //set content out.print(method.getResponseBodyAsString()); //close writer out.close(); response.setHeader("Content-Type", contentType); } } catch (Exception e) { logger.error("Error when returning HTML content: " + e.getMessage(), e); //protection if (out != null) { out.close(); } } }
From source file:com.arjuna.qa.junit.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 {/* ww w .ja v a 2s . c o m*/ System.err.println("Connecting to: " + url); String userInfo = url.getUserInfo(); if (userInfo != null) { UsernamePasswordCredentials auth = new UsernamePasswordCredentials(userInfo); httpConn.getState().setCredentials(realm, url.getHost(), auth); } System.err.println("RequestURI: " + request.getURI()); int responseCode = httpConn.executeMethod(request); String response = request.getStatusText(); System.err.println("responseCode=" + responseCode + ", response=" + response); String content = request.getResponseBodyAsString(); System.err.println(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:com.owncloud.android.lib.resources.OCSRemoteOperation.java
public <T> T getServerResponse(HttpMethodBase method, TypeToken<T> type) throws IOException { String response = method.getResponseBodyAsString(); JsonParser parser = new JsonParser(); JsonElement element = parser.parse(response); Gson gson = new Gson(); return gson.fromJson(element, type.getType()); }
From source file:com.bdaum.juploadr.uploadapi.smugrest.SmugmugMethod.java
public boolean execute() throws ProtocolException, CommunicationException { HttpMethodBase method = getMethod(); boolean rv = false; try {/*from ww w . ja v a2 s . c o m*/ int response = client.executeMethod(method); if (HttpStatus.SC_OK == response) { rv = parseResponse(method.getResponseBodyAsString()); } else { throw new CommunicationException(Messages.getString("juploadr.ui.error.bad.http.response", //$NON-NLS-1$ Activator.getStatusText(response))); } } catch (HttpException e) { throw new CommunicationException(e.getMessage(), e); } catch (IOException e) { throw new CommunicationException(e.getMessage(), e); } finally { method.releaseConnection(); } return rv; }
From source file:edu.ucsb.eucalyptus.cloud.ws.tests.CreateSnapshotTest.java
public void testSendDummy() throws Exception { HttpClient httpClient = new HttpClient(); String addr = System.getProperty(WalrusProperties.URL_PROPERTY) + "/meh/ttt.wsl?gg=vol&hh=snap"; HttpMethodBase method = new PutMethod(addr); method.setRequestHeader("Authorization", "Euca"); method.setRequestHeader("Date", (new Date()).toString()); method.setRequestHeader("Expect", "100-continue"); httpClient.executeMethod(method);/* w ww. ja v a 2s. com*/ String responseString = method.getResponseBodyAsString(); System.out.println(responseString); method.releaseConnection(); }
From source file:com.eucalyptus.blockstorage.CreateSnapshotTest.java
@Test public void testSendDummy() throws Exception { HttpClient httpClient = new HttpClient(); String addr = System.getProperty("euca.objectstorage.url") + "/meh/ttt.wsl?gg=vol&hh=snap"; HttpMethodBase method = new PutMethod(addr); method.setRequestHeader("Authorization", "Euca"); method.setRequestHeader("Date", (new Date()).toString()); method.setRequestHeader("Expect", "100-continue"); httpClient.executeMethod(method);//from www .java2s. c om String responseString = method.getResponseBodyAsString(); System.out.println(responseString); method.releaseConnection(); }
From source file:com.eucalyptus.blockstorage.tests.CreateSnapshotTest.java
@Test public void testSendDummy() throws Exception { HttpClient httpClient = new HttpClient(); String addr = System.getProperty(WalrusProperties.URL_PROPERTY) + "/meh/ttt.wsl?gg=vol&hh=snap"; HttpMethodBase method = new PutMethod(addr); method.setRequestHeader("Authorization", "Euca"); method.setRequestHeader("Date", (new Date()).toString()); method.setRequestHeader("Expect", "100-continue"); httpClient.executeMethod(method);/*from w w w . ja v a 2 s. c om*/ String responseString = method.getResponseBodyAsString(); System.out.println(responseString); method.releaseConnection(); }
From source file:de.juwimm.cms.common.http.HttpClientWrapper.java
public synchronized String getString(String destUrl, String userName, String password) throws IOException { HttpMethodBase method = invoke(destUrl, userName, password); String retString = method.getResponseBodyAsString(); method.releaseConnection();//from w w w.j av a2 s . c o m return retString; }
From source file:com.bdaum.juploadr.uploadapi.locrrest.LocrMethod.java
public boolean execute() throws ProtocolException, CommunicationException { HttpMethodBase method = getMethod(); boolean rv = false; try {// ww w .j a va 2 s .c o m int response = client.executeMethod(method); if (HttpStatus.SC_OK == response) { rv = parseResponse(method.getResponseBodyAsString()); if (!rv) { throw defaultExceptionFor(handler.getErrorCode()); } } else { throw new CommunicationException(Messages.getString("juploadr.ui.error.bad.http.response", //$NON-NLS-1$ Activator.getStatusText(response))); } } catch (InvalidAuthTokenException iat) { ((RestLocrApi) session.getApi()).reauthAccount(session); } catch (HttpException e) { throw new CommunicationException(e.getMessage(), e); } catch (IOException e) { throw new CommunicationException(e.getMessage(), e); } finally { method.releaseConnection(); } return rv; }
From source file:edu.ucsb.eucalyptus.cloud.ws.tests.CreateSnapshotTest.java
public void testGetSnapshotInfo() throws Exception { HttpClient httpClient = new HttpClient(); String addr = System.getProperty(WalrusProperties.URL_PROPERTY) + "/snapset-FuXLn1MUHJ66BkK0/snap-zVl2kZJmjhxnEg.."; HttpMethodBase method = new GetMethod(addr); method.setRequestHeader("Authorization", "Euca"); method.setRequestHeader("Date", (new Date()).toString()); method.setRequestHeader("Expect", "100-continue"); method.setRequestHeader("EucaOperation", "GetSnapshotInfo"); httpClient.executeMethod(method);/*from w w w. j a va 2 s .c o m*/ String responseString = method.getResponseBodyAsString(); System.out.println(responseString); method.releaseConnection(); }