List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod(String uri)
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.file.RemoteFileReader.java
public static GetMethod httpGet(String url, String user, String password) throws HttpException, IOException { // http client HttpClient client = new HttpClient(); // credentials if (!StringUtils.isEmpty(user) || !StringUtils.isEmpty(password)) { Credentials creds = new UsernamePasswordCredentials(user, password); client.getState().setCredentials(AuthScope.ANY, creds); }/*from w w w . j a v a 2 s . c om*/ // executes get method HttpMethod getMethod = new GetMethod(url); client.executeMethod(getMethod); return (GetMethod) getMethod; }
From source file:com.predic8.membrane.core.interceptor.balancer.ClusterNotificationInterceptorTest.java
@Test public void testTakeOutEndpoint() throws Exception { GetMethod get = new GetMethod("http://localhost:3002/clustermanager/takeout?" + createQueryString("host", "node1.clustera", "port", "3018", "cluster", "c1")); assertEquals(204, new HttpClient().executeMethod(get)); assertEquals(1, BalancerUtil.lookupBalancer(router, "Default").getAllNodesByCluster("c1").size()); assertTrue(BalancerUtil.lookupBalancer(router, "Default").getAllNodesByCluster("c1").get(0).isTakeOut()); }
From source file:com.tasktop.c2c.server.profile.tests.service.ProfileWebServiceClientTest.java
@Test public void serviceAcceptsNonCompliantJSONMediaTypes() throws HttpException, IOException { String baseUrl = profileWebServiceClient.getBaseUrl(); for (String mediaType : new String[] { "application/json", "application/x-javascript", "text/javascript", "text/x-javascript", "text/x-json", "text/json" }) { HttpClient client = new HttpClient(); HttpMethod get = new GetMethod(baseUrl + "/" + ProfileWebServiceClient.GET_PROJECT_BY_IDENTIFIER_URL.replaceAll("\\{.*?\\}", "123")); get.addRequestHeader("Accept", mediaType); int rc = client.executeMethod(get); String responseBody = get.getResponseBodyAsString(); assertTrue("Expected JSON response for media type \"" + mediaType + "\" but got " + responseBody, responseBody.trim().startsWith("{\"error\":{\"message\":")); }/*from w w w . j a va2 s . co m*/ }
From source file:br.com.edu.dbpediaspotlight.db.java
public List<DBpediaResource> extract(Text text) throws AnnotationException { LOG.info("Querying API."); String spotlightResponse;//from w w w .j ava2 s. c o m try { String Query = API_URL + "rest/annotate/?" + "confidence=" + CONFIDENCE + "&support=" + SUPPORT + "&spotter=Default" + "&disambiguator=" + disambiguator + "&showScores=" + showScores + "&powered_by=" + powered_by + "&text=" + URLEncoder.encode(text.text(), "utf-8"); LOG.info(Query); GetMethod getMethod = new GetMethod(Query); getMethod.addRequestHeader(new Header("Accept", "application/json")); spotlightResponse = request(getMethod); } catch (UnsupportedEncodingException e) { throw new AnnotationException("Could not encode text.", e); } assert spotlightResponse != null; JSONObject resultJSON = null; JSONArray entities = null; try { resultJSON = new JSONObject(spotlightResponse); entities = resultJSON.getJSONArray("Resources"); } catch (JSONException e) { throw new AnnotationException("Received invalid response from DBpedia Spotlight API."); } LinkedList<DBpediaResource> resources = new LinkedList<DBpediaResource>(); if (entities != null) for (int i = 0; i < entities.length(); i++) { try { JSONObject entity = entities.getJSONObject(i); resources.add(new DBpediaResource(entity.getString("@URI"), Integer.parseInt(entity.getString("@support")))); } catch (JSONException e) { LOG.error("JSON exception " + e); } } return resources; }
From source file:com.bsb.common.vaadin.embed.AbstractEmbedTest.java
protected void checkVaadinIsDeployed(int port, String context) { final StringBuilder sb = new StringBuilder(); sb.append("http://localhost:").append(port); if (context.trim().isEmpty() || context.equals("/")) { sb.append("/"); } else {/*from w w w. ja v a2s .co m*/ sb.append(context); } final String url = sb.toString(); final HttpClient client = new HttpClient(); client.getParams().setConnectionManagerTimeout(2000); final GetMethod method = new GetMethod(url); try { assertEquals("Wrong return code invoking [" + url + "]", HttpStatus.SC_OK, client.executeMethod(method)); } catch (IOException e) { throw new IllegalStateException("Failed to invoke url [" + url + "]", e); } }
From source file:edu.unc.lib.dl.admin.controller.RESTProxyController.java
@RequestMapping(value = { "/services/rest", "/services/rest/*", "/services/rest/**/*" }) public final void proxyAjaxCall(HttpServletRequest request, HttpServletResponse response) throws IOException { log.debug("Prepending service url " + this.servicesUrl + " to " + request.getRequestURI()); String url = request.getRequestURI().replaceFirst(".*/services/rest/?", this.servicesUrl); if (request.getQueryString() != null) url = url + "?" + request.getQueryString(); OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream()); HttpClient client = new HttpClient(); HttpMethod method = null;// w w w. ja v a 2 s.co m try { log.debug("Proxying ajax request to services REST api via " + request.getMethod()); // Split this according to the type of request if (request.getMethod().equals("GET")) { method = new GetMethod(url); } else if (request.getMethod().equals("POST")) { method = new PostMethod(url); // Set any eventual parameters that came with our original // request (POST params, for instance) Enumeration<String> paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { String paramName = paramNames.nextElement(); ((PostMethod) method).setParameter(paramName, request.getParameter(paramName)); } } else { throw new NotImplementedException("This proxy only supports GET and POST methods."); } // Forward the user's groups along with the request method.addRequestHeader(HttpClientUtil.SHIBBOLETH_GROUPS_HEADER, GroupsThreadStore.getGroupString()); method.addRequestHeader("On-Behalf-Of", GroupsThreadStore.getUsername()); // Execute the method client.executeMethod(method); // Set the content type, as it comes from the server Header[] headers = method.getResponseHeaders(); for (Header header : headers) { if ("Content-Type".equalsIgnoreCase(header.getName())) { response.setContentType(header.getValue()); } } try (InputStream responseStream = method.getResponseBodyAsStream()) { int b; while ((b = responseStream.read()) != -1) { response.getOutputStream().write(b); } } response.getOutputStream().flush(); } catch (HttpException e) { writer.write(e.toString()); throw e; } catch (IOException e) { e.printStackTrace(); writer.write(e.toString()); throw e; } finally { if (method != null) method.releaseConnection(); } }
From source file:com.linkage.utils.wsdl.support.UrlWsdlLoader.java
/** * function building XmlObject/* www.j a v a 2 s . co m*/ */ public XmlObject load(String url, XmlOptions option) throws XmlException, IOException, Exception { XmlObject object = null; if (!PathUtils.isHttpPath(url)) { try { File file = new File(url.replace('/', File.separatorChar)); if (file.exists()) url = file.toURI().toURL().toString(); } catch (Exception e) { } } if (wsdlcache.containsKey(url)) { return wsdlcache.get(url); } if (url.startsWith("file:")) { object = load(handleFile(url), option); wsdlcache.put(url, object); return object; } else if (url.startsWith("http:")) { log.debug("Getting wsdl component from [" + url + "]"); // HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); getMethod = new GetMethod(url); client.executeMethod(getMethod); byte[] content = getMethod.getResponseBody(); getMethod.releaseConnection(); object = load(new ByteArrayInputStream(content), option); wsdlcache.put(url, object); return object; } else { return object; } }
From source file:com.cloud.test.longrun.VirtualMachine.java
public void deployVM(long zoneId, long serviceOfferingId, long templateId, String server, String apiKey, String secretKey) throws IOException { String encodedZoneId = URLEncoder.encode("" + zoneId, "UTF-8"); String encodedServiceOfferingId = URLEncoder.encode("" + serviceOfferingId, "UTF-8"); String encodedTemplateId = URLEncoder.encode("" + templateId, "UTF-8"); String encodedApiKey = URLEncoder.encode(apiKey, "UTF-8"); String requestToSign = "apiKey=" + encodedApiKey + "&command=deployVirtualMachine&serviceOfferingId=" + encodedServiceOfferingId + "&templateId=" + encodedTemplateId + "&zoneId=" + encodedZoneId; requestToSign = requestToSign.toLowerCase(); String signature = TestClientWithAPI.signRequest(requestToSign, secretKey); String encodedSignature = URLEncoder.encode(signature, "UTF-8"); String url = server + "?command=deployVirtualMachine" + "&zoneId=" + encodedZoneId + "&serviceOfferingId=" + encodedServiceOfferingId + "&templateId=" + encodedTemplateId + "&apiKey=" + encodedApiKey + "&signature=" + encodedSignature; s_logger.info("Sending this request to deploy a VM: " + url); HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(url); int responseCode = client.executeMethod(method); s_logger.info("deploy linux vm response code: " + responseCode); if (responseCode == 200) { InputStream is = method.getResponseBodyAsStream(); Map<String, String> values = TestClientWithAPI.getSingleValueFromXML(is, new String[] { "id", "ipaddress" }); long linuxVMId = Long.parseLong(values.get("id")); s_logger.info("got linux virtual machine id: " + linuxVMId); this.setPrivateIp(values.get("ipaddress")); } else if (responseCode == 500) { InputStream is = method.getResponseBodyAsStream(); Map<String, String> errorInfo = TestClientWithAPI.getSingleValueFromXML(is, new String[] { "errorcode", "description" }); s_logger.error("deploy linux vm test failed with errorCode: " + errorInfo.get("errorCode") + " and description: " + errorInfo.get("description")); } else {/*from ww w . jav a 2 s. co m*/ s_logger.error("internal error processing request: " + method.getStatusText()); } }
From source file:eu.impact_project.wsclient.HtmlServiceProvider.java
private InputStream getRemoteFile(URL url) { HttpClient client = new HttpClient(); GetMethod getMethod = new GetMethod(url.toString()); try {/*from www.j a v a 2 s .co m*/ client.executeMethod(getMethod); return getMethod.getResponseBodyAsStream(); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:ccc.api.http.SiteBrowserImpl.java
/** {@inheritDoc} */ @Override//from w w w . j av a2 s . c om public String previewContent(final Resource rs, final boolean wc) { final GetMethod get = new GetMethod(_previewUrl + rs.getAbsolutePath() + ((wc) ? "?wc=" : "")); return invoke(get); }