List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod(String uri)
From source file:net.sf.ehcache.constructs.web.filter.PageFragmentCachingFilterTest.java
/** * Tests that a page which is not storeGzipped is not gzipped when the user agent accepts gzip encoding *///w ww . ja v a 2s .co m public void testNotGzippedWhenAcceptEncodingPageFragment() throws Exception { HttpClient httpClient = new HttpClient(); HttpMethod httpMethod = new GetMethod(buildUrl("/include/Footer.jsp")); //httpMethod.setRequestHeader(new Header("Accept-encoding", "gzip")); httpClient.executeMethod(httpMethod); byte[] responseBody = httpMethod.getResponseBody(); assertFalse(PageInfo.isGzipped(responseBody)); assertNotSame("gzip", httpMethod.getResponseHeader("Accept-encoding")); }
From source file:edu.htwm.vsp.phoebook.rest.client.RestClient.java
/** * funktioniert noch nicht/*from w ww . j a v a 2s . c o m*/ * * @param expectedStatusCode * @throws IOException */ public void verifyListAllUsers(int expectedStatusCode) throws IOException { System.out.println("List All Users ... \n"); HttpClient client = new HttpClient(); // -- build HTTP GET request GetMethod method = new GetMethod(getServiceBaseURI() + "/users"); int responseCode = client.executeMethod(method); assertEquals(expectedStatusCode, responseCode); }
From source file:com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; GetMethod get = null;/*from w ww.j a va2s .co m*/ try { // Get Method get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); // Add Parameters to Get Method get.setQueryString(new NameValuePair[] { new NameValuePair(PARAM_PATH, mRemoteFilePath), new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)), new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles)) }); get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); status = client.executeMethod(get); if (isSuccess(status)) { String response = get.getResponseBodyAsString(); result = new RemoteOperationResult(ResultCode.OK); // Parse xml response --> obtain the response in ShareFiles ArrayList // convert String into InputStream InputStream is = new ByteArrayInputStream(response.getBytes()); ShareXMLParser xmlParser = new ShareXMLParser(); mShares = xmlParser.parseXMLResponse(is); if (mShares != null) { Log_OC.d(TAG, "Got " + mShares.size() + " shares"); result = new RemoteOperationResult(ResultCode.OK); ArrayList<Object> sharesObjects = new ArrayList<Object>(); for (OCShare share : mShares) { // Build the link if (share.getToken().length() > 0) { share.setShareLink( client.getBaseUri() + ShareUtils.SHARING_LINK_TOKEN + share.getToken()); } sharesObjects.add(share); } result.setData(sharesObjects); } } else { result = new RemoteOperationResult(false, status, get.getResponseHeaders()); } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Exception while getting shares", e); } finally { if (get != null) { get.releaseConnection(); } } return result; }
From source file:com.sina.stock.SinaStockClient.java
/** * ???// w w w . jav a2 s . c om * * @param stockCodes * ??"sh+?", ?"sz+?" * * @return ?List<SinaStockInfo>null * * @throws IOException * @throws HttpException * @throws ParseStockInfoException */ public List<SinaStockInfo> getStockInfo(String[] stockCodes) throws HttpException, IOException, ParseStockInfoException { String url = STOCK_URL + generateStockCodeRequest(stockCodes); HttpMethod method = new GetMethod(url); int statusCode = mHttpClient.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { method.releaseConnection(); return null; } InputStream is = method.getResponseBodyAsStream(); InputStreamReader reader = new InputStreamReader(new BufferedInputStream(is), Charset.forName("gbk")); BufferedReader bReader = new BufferedReader(reader); List<SinaStockInfo> list = parseSinaStockInfosFromReader(bReader); bReader.close(); method.releaseConnection(); return list; }
From source file:com.google.apphosting.vmruntime.jetty9.VmRuntimeJettySessionTest.java
public void LUDOTODOtestWithInvalidInboundIp() throws Exception { HttpClient httpClient = new HttpClient(); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000); GetMethod get = new GetMethod(createUrlForHostIP("/test-ssl").toString()); int httpCode = httpClient.executeMethod(get); assertEquals(403, httpCode);//from w w w. j av a 2s. c o m }
From source file:com.dlecan.agreg.AgregResultsBot.java
public boolean isResultatsDisponibles(String type) throws Exception { boolean resultatsDisponibles = false; String urlAppelee = URL_PUBLINET_PREFIX + type + URL_PUBLINET_SUFFIX; HttpMethod getUrlPublinet = new GetMethod(urlAppelee); try {/*from w w w . j a v a 2s . c o m*/ int status = client.executeMethod(getUrlPublinet); if (status == HttpStatus.SC_OK) { InputStream streamPage = getUrlPublinet.getResponseBodyAsStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(streamPage)); String line; while ((line = reader.readLine()) != null) { if (line.toUpperCase().contains("AUCUN CANDIDAT ADMIS")) { resultatsDisponibles = false; break; } else if (line.toUpperCase() .contains("Cliquez sur une des lettres de l'alphabet".toUpperCase())) { resultatsDisponibles = true; break; } else { // Le systme dconne } } if (resultatsDisponibles) { while ((line = reader.readLine()) != null) { if (line.toUpperCase().contains("VALADE")) { recue = true; messageAEnvoyer = urlAppelee + "\n\n" + line; break; } else { // Le systme dconne } } } } else { logger.error("Method failed: {}", getUrlPublinet.getStatusLine()); } } finally { getUrlPublinet.releaseConnection(); } return resultatsDisponibles; }
From source file:com.cloud.network.bigswitch.BigSwitchVnsApi.java
protected HttpMethod createMethod(String type, String uri, int port) throws BigSwitchVnsApiException { String url;//from w w w . jav a2 s . c o m try { url = new URL(s_protocol, _host, port, uri).toString(); } catch (MalformedURLException e) { s_logger.error("Unable to build BigSwitch API URL", e); throw new BigSwitchVnsApiException("Unable to build v API URL", e); } if ("post".equalsIgnoreCase(type)) { return new PostMethod(url); } else if ("get".equalsIgnoreCase(type)) { return new GetMethod(url); } else if ("delete".equalsIgnoreCase(type)) { return new DeleteMethod(url); } else if ("put".equalsIgnoreCase(type)) { return new PutMethod(url); } else { throw new BigSwitchVnsApiException("Requesting unknown method type"); } }
From source file:com.wafersystems.util.HttpUtil.java
/** * ??/*from www. j a va2s . c o m*/ * * @param ip IP? * @param port ?? * @param hClient HttpClient * @param method HttpMethod * @param lastResult * * @return */ public static int checkRedirect(String ip, int port, HttpClient hClient, HttpMethod method, int lastResult) throws Exception { int result = HttpStatus.SC_OK; if ((lastResult == HttpStatus.SC_MOVED_TEMPORARILY) || (lastResult == HttpStatus.SC_MOVED_PERMANENTLY) || (lastResult == HttpStatus.SC_SEE_OTHER) || (lastResult == HttpStatus.SC_TEMPORARY_REDIRECT)) { //????URL? Header header = method.getResponseHeader("location"); if (header != null) { String newURI = header.getValue(); if (StrUtil.isEmptyStr(newURI)) newURI = "http://" + ip + ":" + port + "/"; //URL??IP?? if (!newURI.startsWith("http")) newURI = "http://" + ip + ":" + port + newURI; logger.warn("??" + newURI); method = new GetMethod(newURI); result = hClient.executeMethod(method); } } return result; }
From source file:com.swdouglass.joid.consumer.Discoverer.java
/** * 14.2.1. Relying Parties/*from ww w. java 2s.com*/ */ public Boolean findWithHTML(String identityUrl, ServerAndDelegate serverAndDelegate) throws Exception { boolean found = false; GetMethod get = new GetMethod(identityUrl); BufferedReader in = httpGet(get); String str; while ((str = in.readLine()) != null) { if (serverAndDelegate.getServer() == null) { serverAndDelegate.setServer(findLinkTag(str, "openid.server", in)); } if (serverAndDelegate.getDelegate() == null) { serverAndDelegate.setDelegate(findLinkTag(str, "openid.delegate", in)); } if (str.indexOf("</head>") >= 0) { break; } } if (serverAndDelegate.getServer() != null) { found = true; } return found; }
From source file:com.interaction.example.odata.multicompany.ODataMulticompanyITCase.java
@Test public void testGetServiceDocumentBaseUri() throws Exception { org.apache.abdera.model.Service service = null; GetMethod method = new GetMethod(baseUri); try {/* www . j av a2 s. c o m*/ client.executeMethod(method); assertEquals(200, method.getStatusCode()); if (method.getStatusCode() == HttpStatus.SC_OK) { // read as string for debugging String response = method.getResponseBodyAsString(); System.out.println("Response = " + response); Abdera abdera = new Abdera(); Parser parser = abdera.getParser(); Document<org.apache.abdera.model.Service> doc = parser.parse(new StringReader(response)); service = doc.getRoot(); } } catch (IOException e) { fail(e.getMessage()); } finally { method.releaseConnection(); } assertNotNull(service); assertEquals("http://localhost:8080/example/interaction-odata-multicompany.svc/MockCompany001/", service.getBaseUri().toString()); }