List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod(String uri)
From source file:com.google.apphosting.vmruntime.jetty9.VmRuntimeJettyAuthTest.java
public void testAuth_UserRequiredNoUser() throws Exception { String loginUrl = "http://login-url?url=http://test-app.googleapp.com/user/test-auth"; CreateLoginURLResponse loginUrlResponse = new CreateLoginURLResponse(); loginUrlResponse.setLoginUrl(loginUrl); // Fake the expected call to "user/CreateLoginUrl". FakeableVmApiProxyDelegate fakeApiProxy = new FakeableVmApiProxyDelegate(); ApiProxy.setDelegate(fakeApiProxy);//w ww . j a v a2 s.c o m fakeApiProxy.addApiResponse(loginUrlResponse); HttpClient httpClient = new HttpClient(); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000); GetMethod get = new GetMethod(createUrl("/user/test-auth").toString()); get.setFollowRedirects(false); int httpCode = httpClient.executeMethod(get); assertEquals(302, httpCode); Header redirUrl = get.getResponseHeader("Location"); assertEquals(loginUrl, redirUrl.getValue()); }
From source file:com.interaction.example.odata.embedded.LinkIdITCase.java
@Test public void testLinkId() { try {/*from ww w. ja va 2 s. co m*/ method = new GetMethod(baseUri + AIRPORTS); client.executeMethod(method); assertEquals(200, method.getStatusCode()); if (method.getStatusCode() == HttpStatus.SC_OK) { // read as string for debugging String response = method.getResponseBodyAsString(); Abdera abdera = new Abdera(); Parser parser = abdera.getParser(); Document<Feed> feedEntry = parser.parse(new StringReader(response)); Feed feed = feedEntry.getRoot(); List<Entry> entries = feed.getEntries(); assertEquals(6, entries.size()); // for(int i=0; i<entries.size(); i++) { // List<Link> link = entries.get(i).getLinks(); // for(int j=0; j<link.size(); j++) { // System.out.println(link.get(j).getAttributeValue("id")); // } // } List<Link> link = entries.get(0).getLinks(); assertNotNull(link); assertEquals("123456", link.get(0).getAttributeValue("id")); assertEquals("654321", link.get(1).getAttributeValue("id")); link = entries.get(1).getLinks(); assertNotNull(link); assertEquals("123456", link.get(0).getAttributeValue("id")); assertEquals("654321", link.get(1).getAttributeValue("id")); link = entries.get(2).getLinks(); assertNotNull(link); assertEquals("123456", link.get(0).getAttributeValue("id")); assertEquals("654321", link.get(1).getAttributeValue("id")); link = entries.get(3).getLinks(); assertNotNull(link); assertEquals("123456", link.get(0).getAttributeValue("id")); assertEquals("654321", link.get(1).getAttributeValue("id")); link = entries.get(4).getLinks(); assertNotNull(link); assertEquals("123456", link.get(0).getAttributeValue("id")); assertEquals("654321", link.get(1).getAttributeValue("id")); link = entries.get(5).getLinks(); assertNotNull(link); assertEquals("123456", link.get(0).getAttributeValue("id")); assertEquals("654321", link.get(1).getAttributeValue("id")); } } catch (IOException e) { fail(e.getMessage()); } finally { method.releaseConnection(); } }
From source file:com.universalmind.core.components.mockup.loremipsum.SchmIpsumService.java
@Test public void testService() { String schmipsumSource = "bible"; Integer paragraphs = 2;//from w w w.j a v a 2 s. co m String loremText = null; String url = null; url = "http://www.schmipsum.com/ipsum/" + schmipsumSource + "/" + (paragraphs * 100); HttpMethod method = null; HttpClient client = new HttpClient(); try { method = new GetMethod(url); int statusCode = client.executeMethod(method); byte[] responseBody = method.getResponseBody(); // Create a response handler //ResponseHandler<String> responseHandler = new BasicResponseHandler(); //String responseBody = httpclient.execute(httpget, responseHandler); loremText = parseBaseballIpsum(new String(responseBody)); Assert.assertNotNull(loremText); Assert.assertTrue(loremText.length() > 100); } catch (Exception jse) { //do nothing } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources //httpclient.getConnectionManager().shutdown(); if (method != null) { method.releaseConnection(); } } }
From source file:com.owncloud.android.operations.ConnectionCheckOperation.java
private boolean tryConnection(WebdavClient wc, String urlSt) { boolean retval = false; GetMethod get = null;/*from w ww . ja va 2 s.c o m*/ try { get = new GetMethod(urlSt); int status = wc.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); String response = get.getResponseBodyAsString(); if (status == HttpStatus.SC_OK) { JSONObject json = new JSONObject(response); if (!json.getBoolean("installed")) { mLatestResult = new RemoteOperationResult( RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); } else { mOCVersion = new OwnCloudVersion(json.getString("version")); if (!mOCVersion.isVersionValid()) { mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION); } else { mLatestResult = new RemoteOperationResult( urlSt.startsWith("https://") ? RemoteOperationResult.ResultCode.OK_SSL : RemoteOperationResult.ResultCode.OK_NO_SSL); retval = true; } } } else { mLatestResult = new RemoteOperationResult(false, status); } } catch (JSONException e) { mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); } catch (Exception e) { mLatestResult = new RemoteOperationResult(e); } finally { if (get != null) get.releaseConnection(); } if (mLatestResult.isSuccess()) { Log.i(TAG, "Connection check at " + urlSt + ": " + mLatestResult.getLogMessage()); } else if (mLatestResult.getException() != null) { Log.e(TAG, "Connection check at " + urlSt + ": " + mLatestResult.getLogMessage(), mLatestResult.getException()); } else { Log.e(TAG, "Connection check at " + urlSt + ": " + mLatestResult.getLogMessage()); } return retval; }
From source file:cn.edu.seu.herald.ws.api.impl.RequestGetMethodFactoryImpl.java
@Override public GetMethod newPlainTextRequestMethod(URI uri) { GetMethod getMethod = new GetMethod(uri.toASCIIString()); getMethod.setRequestHeader(HTTP_HEADER_ACCEPT, MEDIA_TYPE_TEXT_PLAIN); return getMethod; }
From source file:net.neurowork.cenatic.centraldir.workers.xml.SectorXmlImporter.java
public Sector buscarSector(int sectorCode) { HttpClient httpclient = XMLRestWorker.getHttpClient(); GetMethod get = new GetMethod(restUrl.getSectorUrl()); get.addRequestHeader("Accept", "application/xml"); Sector ret = null;/*w w w . j a v a2 s . c om*/ try { int result = httpclient.executeMethod(get); logger.info("Response status code: " + result); String xmlString = get.getResponseBodyAsString(); logger.info("Response body: " + xmlString); ret = importSector(xmlString, sectorCode); } catch (HttpException e) { logger.error(e.getMessage()); } catch (IOException e) { logger.error(e.getMessage()); } catch (ParserConfigurationException e) { logger.error(e.getMessage()); } catch (SAXException e) { logger.error(e.getMessage()); } finally { get.releaseConnection(); } return ret; }
From source file:com.criticalsoftware.mobics.presentation.util.GeolocationUtil.java
/** * Get the full address name/*ww w. j av a 2 s .c o m*/ * * @param latitude * @param longitude * @return address string */ public static String getAddressFromCoordinates(String latitude, String longitude) { String address = null; String url = MessageFormat.format(GEOLOCATION_URL, Configuration.INSTANCE.getGeolocationServer(), latitude, longitude); HttpMethod method = new GetMethod(url); try { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Making reverse geolocation call to: {}", url); } int statusCode = new HttpClient().executeMethod(method); if (statusCode == HttpStatus.SC_OK) { byte[] responseBody = readResponse(method); JSONObject jsonObject = (JSONObject) new JSONParser().parse(new String(responseBody)); if (LOGGER.isTraceEnabled()) { LOGGER.trace(jsonObject.toJSONString()); } address = getFormattedAddress(jsonObject); } else { LOGGER.warn("Recived a HTTP status {}. Response was not good from {}", statusCode, url); } } catch (HttpException e) { LOGGER.error("Error while making call.", e); } catch (IOException e) { LOGGER.error("Error while reading the response.", e); } catch (ParseException e) { LOGGER.error("Error while parsing json response.", e); } return address; }
From source file:example.nz.org.take.compiler.userv.main.DUIConvictionInfoSource.java
@Override public ResourceIterator<hasBeenConvictedOfaDUI> fetch(Driver driver) { HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager()); client.getHttpConnectionManager().getParams().setConnectionTimeout(30000); GetMethod get = new GetMethod(URL); get.setFollowRedirects(true);/*from ww w.j a va 2 s . co m*/ get.setQueryString(new NameValuePair[] { new NameValuePair("id", driver.getId()) }); try { logger.info("DUI conviction lookup " + get.getURI()); client.executeMethod(get); String response = get.getResponseBodyAsString(); logger.info("DUI conviction lookup result: " + response); if (response != null && "true".equals(response.trim())) { hasBeenConvictedOfaDUI record = new hasBeenConvictedOfaDUI(); record.slot1 = driver; get.releaseConnection(); return new SingletonIterator<hasBeenConvictedOfaDUI>(record); } } catch (Exception e) { logger.error("Error connecting to web service " + URL); } return EmptyIterator.DEFAULT; }
From source file:com.alibaba.intl.bcds.goldroom.remote.DoubanBookInfoFetcher.java
public BookInfo fetch(String isbn) { HttpMethod method = new GetMethod(fetchUrl + isbn); HttpClient client = new HttpClient(); try {/*from w ww . ja va 2 s . c o m*/ client.executeMethod(method); BookInfo info = parserBookInfo(method.getResponseBodyAsString()); return info; } catch (HttpException e) { logger.error("fetch bookinfo whth isbn(" + isbn + ") error", e); } catch (Exception e) { logger.error("fetch bookinfo whth isbn(" + isbn + ") error", e); } return null; }
From source file:com.predic8.membrane.core.interceptor.authentication.BasicAuthenticationInterceptorIntegrationTest.java
private GetMethod getGetMethod() { GetMethod get = new GetMethod("http://localhost:8000/axis2/services/BLZService?wsdl"); get.setRequestHeader(Header.CONTENT_TYPE, "text/xml;charset=UTF-8"); get.setRequestHeader(Header.SOAP_ACTION, ""); return get;//from ww w . java2 s. c o m }