List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod(String uri)
From source file:net.sourceforge.jwbf.actions.mw.queries.GetRecentchanges.java
/** * generates the next MediaWiki-request (GetMethod) and adds it to msgs. * @param namespace the namespace(s) that will be searched for links, * as a string of numbers separated by '|'; * if null, this parameter is omitted *///from w w w . j ava2s . c o m protected void generateRequest(String namespace) { String uS = ""; uS = "/api.php?action=query&list=recentchanges" + ((namespace != null) ? ("&rcnamespace=" + namespace) : "") //+ "&rcminor=" //+ "&rcusertype=" // (dflt=not|bot) + "&rclimit=" + limit + "&format=xml"; msgs.add(new GetMethod(uS)); }
From source file:edu.du.penrose.systems.util.HttpClientUtils.java
/** * Get file from URL, directories are created and files overwritten. * /* www. j a va 2 s . c o m*/ * * @deprecated use org.apache.commons.io.FileUtils.copyURLToFile(URL, File) * @param requestUrl * @param outputPathAndFileName * * @return int request status code OR -1 if an exception occurred */ static public int getToFile(String requestUrl, String outputPathAndFileName) { int resultStatus = -1; File outputFile = new File(outputPathAndFileName); String outputPath = outputFile.getAbsolutePath().replace(outputFile.getName(), ""); File outputDir = new File(outputPath); if (!outputDir.exists()) { outputDir.mkdir(); } HttpClient client = new HttpClient(); // client.getState().setCredentials( // new AuthScope("localhost", 7080, null ), // new UsernamePasswordCredentials("nation", "nationPW") // ); // client.getParams().setAuthenticationPreemptive(true); HttpMethod method = new GetMethod(requestUrl); // method.setDoAuthentication( true ); // client.getParams().setAuthenticationPreemptive(true); // Execute and print response try { OutputStream os = new FileOutputStream(outputFile); client.executeMethod(method); InputStream is = method.getResponseBodyAsStream(); BufferedInputStream bis = new BufferedInputStream(is); byte[] bytes = new byte[8192]; // reading as chunk of 8192 bytes int count = bis.read(bytes); while (count != -1 && count <= 8192) { os.write(bytes, 0, count); count = bis.read(bytes); } bis.close(); os.close(); resultStatus = method.getStatusCode(); } catch (Exception e) { e.printStackTrace(); } finally { method.releaseConnection(); } return resultStatus; }
From source file:ccc.api.http.SiteBrowserImpl.java
/** {@inheritDoc} */ @Override/* www . j av a 2s . c om*/ public String previewContent(final ResourceSummary rs, final boolean wc) { final GetMethod get = new GetMethod(_previewUrl + rs.getAbsolutePath() + ((wc) ? "?wc=" : "")); return invoke(get); }
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 va 2s . co 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:com.liferay.portlet.rss.util.RSSWebCacheItem.java
public Object convert(String key) throws WebCacheException { SyndFeed feed = null;// ww w . java2s .c om try { // com.liferay.portal.kernel.util.HttpUtil will break the connection // if it spends more than 5 seconds looking up a location. However, // German umlauts do not get encoded correctly. This may be a bug // with commons-httpclient or with how FeedParser uses // java.io.Reader. // Use http://xml.newsisfree.com/feeds/29/629.xml and // http://test.domosoft.com/up/RSS to test if German umlauts show // up correctly. /*Reader reader = new StringReader( new String(HttpUtil.URLtoByteArray(_url))); channel = FeedParser.parse(builder, reader);*/ HttpImpl httpImpl = (HttpImpl) HttpUtil.getHttp(); HostConfiguration hostConfiguration = httpImpl.getHostConfiguration(_url); HttpClient httpClient = httpImpl.getClient(hostConfiguration); httpImpl.proxifyState(httpClient.getState(), hostConfiguration); HttpClientParams httpClientParams = httpClient.getParams(); httpClientParams.setConnectionManagerTimeout(PropsValues.RSS_CONNECTION_TIMEOUT); httpClientParams.setSoTimeout(PropsValues.RSS_CONNECTION_TIMEOUT); GetMethod getMethod = new GetMethod(_url); httpClient.executeMethod(hostConfiguration, getMethod); SyndFeedInput input = new SyndFeedInput(); feed = input.build(new XmlReader(getMethod.getResponseBodyAsStream())); } catch (Exception e) { throw new WebCacheException(_url + " " + e.toString()); } return feed; }
From source file:net.sourceforge.jwbf.actions.mw.queries.GetLogEvents.java
/** * generates the next MediaWiki-request (GetMethod) and adds it to msgs. * // ww w. j ava 2 s .c o m * @param logtype * type of log, like upload */ protected void generateRequest(String... logtype) { String uS = ""; uS = "/api.php?action=query&list=logevents"; if (logtype.length > 0) { String logtemp = ""; for (int i = 0; i < logtype.length; i++) { logtemp += logtype[i] + "|"; } uS += "&letype=" + logtemp.substring(0, logtemp.length() - 1); } uS += "&lelimit=" + limit + "&format=xml"; msgs.add(new GetMethod(uS)); }
From source file:de.mpg.mpdl.inge.transformation.transformations.LocalUriResolver.java
/** * {@inheritDoc}/*from ww w.j a v a 2 s. c o m*/ */ public final Source resolve(String href, String altBase) throws TransformerException { String path = null; if (altBase == null) { altBase = ""; } try { if ("ves-mapping.xml".equals(href) || "vocabulary-mappings.xsl".equals(href)) { path = TRANS_PATH + href; } else if (href != null && href.matches("^https?://.*")) { HttpClient client = new HttpClient(); GetMethod getMethod = new GetMethod(href); ProxyHelper.executeMethod(client, getMethod); return new StreamSource(getMethod.getResponseBodyAsStream()); } else { path = this.base + altBase + "/" + href; } return new StreamSource( ResourceUtil.getResourceAsStream(path, LocalUriResolver.class.getClassLoader())); } catch (FileNotFoundException e) { // throw new TransformerException("Cannot resolve URI: " + href); throw new TransformerException("Cannot resolve URI: " + path, e); } catch (HttpException e) { throw new TransformerException("Cannot connect to URI: " + path, e); } catch (IOException e) { throw new TransformerException("Cannot get content from URI: " + path, e); } }
From source file:com.cloud.agent.direct.download.HttpDirectTemplateDownloader.java
protected GetMethod createRequest(String downloadUrl, Map<String, String> headers) { GetMethod request = new GetMethod(downloadUrl); request.setFollowRedirects(true);/* www . j a v a 2 s .c om*/ if (MapUtils.isNotEmpty(headers)) { for (String key : headers.keySet()) { request.setRequestHeader(key, headers.get(key)); reqHeaders.put(key, headers.get(key)); } } return request; }
From source file:com.interaction.example.odata.multicompany.ODataMulticompanyITCase.java
@Test public void testGetServiceDocumentUri() throws Exception { ODataConsumer consumer = ODataJerseyConsumer.newBuilder(baseUri).build(); // get the service document for the company specific service document String serviceRootUri = consumer.getServiceRootUri(); assertNotNull(serviceRootUri);/*from www .j a va2 s .c o m*/ GetMethod method = new GetMethod(serviceRootUri); String response = null; try { method.setDoAuthentication(true); //Require authentication client.executeMethod(method); assertEquals(200, method.getStatusCode()); if (method.getStatusCode() == HttpStatus.SC_OK) { // read as string response = method.getResponseBodyAsString(); } } catch (IOException e) { fail(e.getMessage()); } finally { method.releaseConnection(); } // assert the Users entity set exists in service document assertTrue(response.contains("<collection href=\"Flights\">")); }
From source file:de.mpg.escidoc.services.transformation.transformations.LocalUriResolver.java
/** * {@inheritDoc}/* w ww.ja va 2 s . c o m*/ */ public final Source resolve(String href, String altBase) throws TransformerException { String path = null; if (altBase == null) { altBase = ""; } try { if ("ves-mapping.xml".equals(href) || "vocabulary-mappings.xsl".equals(href)) { path = TRANS_PATH + href; } else if (href != null && href.matches("^https?://.*")) { HttpClient client = new HttpClient(); GetMethod getMethod = new GetMethod(href); ProxyHelper.executeMethod(client, getMethod); return new StreamSource(getMethod.getResponseBodyAsStream()); } else { path = this.base + altBase + "/" + href; } return new StreamSource( ResourceUtil.getResourceAsStream(path, LocalUriResolver.class.getClassLoader())); } catch (FileNotFoundException e) { //throw new TransformerException("Cannot resolve URI: " + href); throw new TransformerException("Cannot resolve URI: " + path, e); } catch (HttpException e) { throw new TransformerException("Cannot connect to URI: " + path, e); } catch (IOException e) { throw new TransformerException("Cannot get content from URI: " + path, e); } }