List of usage examples for org.apache.commons.httpclient.methods GetMethod GetMethod
public GetMethod(String uri)
From source file:com.msbmsb.gogogeocode.GoGoGeocode.java
/** * Given the string of an address, return a Coordinates object that contains * the coordinate information extracted from the API response * @param address the string representation of a physical address * @return Coordinates object containing coordinate information from response *///from w ww . j a va 2s . co m public static Coordinates geocode(String address) { Coordinates coords = new Coordinates(); String requestUrl = ""; try { requestUrl = buildURL(address); } catch (UnsupportedEncodingException uee) { uee.printStackTrace(); } GetMethod getMethod = new GetMethod(requestUrl); getMethod.setFollowRedirects(true); try { httpClient.executeMethod(getMethod); // build the response object GoogleGeocodeResponse response = new GoogleGeocodeResponse( IOUtils.toString(getMethod.getResponseBodyAsStream(), getMethod.getRequestCharSet())); /** * Parsing can be done via Dom Document as well: * GoogleGeocodeResponse response = new GoogleGeocodeResponse(getMethod.getResponseBodyAsStream()); */ // only change coordinates from default if request successful if (response.successful()) { coords = response.getCoords(); } } catch (Exception e) { System.out.println("Geocode exception: " + e.toString()); } finally { getMethod.abort(); getMethod.releaseConnection(); } return coords; }
From source file:com.linkedin.pinot.tools.admin.command.ChangeTableState.java
@Override public boolean execute() throws Exception { if (_controllerHost == null) { _controllerHost = NetUtil.getHostAddress(); }//from w w w . j a v a2 s. c o m String stateValue = _state.toLowerCase(); if (!stateValue.equals("enable") && !stateValue.equals("disable") && !stateValue.equals("drop")) { throw new IllegalArgumentException( "Invalid value for state: " + _state + "\n Value must be one of enable|disable|drop"); } HttpClient httpClient = new HttpClient(); HttpURL url = new HttpURL(_controllerHost, Integer.parseInt(_controllerPort), URI_TABLES_PATH + _tableName); url.setQuery("state", stateValue); GetMethod httpGet = new GetMethod(url.getEscapedURI()); int status = httpClient.executeMethod(httpGet); if (status != 200) { throw new RuntimeException("Failed to change table state, error: " + httpGet.getResponseBodyAsString()); } return true; }
From source file:edu.virginia.speclab.juxta.author.view.export.WebServiceClient.java
/** * Contact the webservice at the current base URL and ensure that * it returns an ok response. If it does, return true. * /*from w w w .j a v a 2s .c o m*/ * @return True if service is alive at the root url; false otherwise */ public boolean isAlive() { GetMethod get = new GetMethod(this.baseUrl); try { execRequest(get); get.releaseConnection(); return true; } catch (IOException e) { return false; } }
From source file:de.mpg.escidoc.http.UserGroup.java
public void getAllUserGroups() { Document responseXML = null;//from w w w. jav a 2s . c om if (this.USER_HANDLE != null) { GetMethod get = new GetMethod(FRAMEWORK_URL + "/aa/user-groups"); get.setRequestHeader("Cookie", "escidocCookie=" + this.USER_HANDLE); try { this.client.executeMethod(get); System.out.println("Server response: "); responseXML = Util.inputStreamToXmlDocument(get.getResponseBodyAsStream()); Util.xmlToString(responseXML); } catch (IOException e) { e.printStackTrace(); } } else { System.out.println("Error in getAllUserGroups: No userHandle available"); } }
From source file:com.predic8.membrane.core.interceptor.rest.RESTBLZServiceIntegrationTest.java
@Test public void testRest() throws Exception { HttpClient client = new HttpClient(); client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); GetMethod get = new GetMethod("http://localhost:3005/bank/37050198"); int status = client.executeMethod(get); System.out.println(get.getResponseBodyAsString()); assertEquals(200, status);/*from w w w . j av a2 s . c o m*/ }
From source file:com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; GetMethod get = null;/*from w w w. j a v a 2s . c o m*/ //Get the user try { get = new GetMethod(client.getBaseUri() + OCS_ROUTE); get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); status = client.executeMethod(get); if (isSuccess(status)) { String response = get.getResponseBodyAsString(); Log_OC.d(TAG, "Successful response: " + response); // Parse the response JSONObject respJSON = new JSONObject(response); JSONObject respOCS = respJSON.getJSONObject(NODE_OCS); JSONObject respData = respOCS.getJSONObject(NODE_DATA); UserInfo userInfo = new UserInfo(); userInfo.mId = respData.getString(NODE_ID); userInfo.mDisplayName = respData.getString(NODE_DISPLAY_NAME); userInfo.mEmail = respData.getString(NODE_EMAIL); // Result result = new RemoteOperationResult(true, status, get.getResponseHeaders()); // Username in result.data ArrayList<Object> data = new ArrayList<>(); data.add(userInfo); result.setData(data); } else { result = new RemoteOperationResult(false, status, get.getResponseHeaders()); String response = get.getResponseBodyAsString(); Log_OC.e(TAG, "Failed response while getting user information "); if (response != null) { Log_OC.e(TAG, "*** status code: " + status + " ; response message: " + response); } else { Log_OC.e(TAG, "*** status code: " + status); } } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Exception while getting OC user information", e); } finally { if (get != null) { get.releaseConnection(); } } return result; }
From source file:at.ait.dme.yuma.suite.apps.map.server.geo.KMLConverterServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Params: URL of the base map into which KML shall be transformed, URL of the KML String mapUrl = request.getParameter("map"); String kmlUrl = request.getParameter("kml"); if ((mapUrl != null) && (kmlUrl != null)) { // Get KML source file via HTTP GetMethod kmlRequest = new GetMethod(kmlUrl); int responseCode = new HttpClient().executeMethod(kmlRequest); if (responseCode == 200) { try { // Parse KML DOM DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document kml = builder.parse(kmlRequest.getResponseBodyAsStream()); // Instantiate Interpolator ControlPointManager cpm = new ControlPointManager(request, response, mapUrl); AffineTransformation ip = new AffineTransformation(cpm.getControlPoints()); // Convert coordinates in DOM kml = convert(kml, ip);//www . j a v a 2 s . co m // Serialize KML result DOM and return Transformer tf = TransformerFactory.newInstance().newTransformer(); Source source = new DOMSource(kml); Result result = new StreamResult(response.getOutputStream()); tf.transform(source, result); } catch (Exception e) { response.sendError(500, e.getMessage()); return; } } else { response.sendError(500, "KML not found. (Server returned error " + responseCode + ")"); return; } response.setContentType("application/vnd.google-earth.kml+xml"); response.setCharacterEncoding("UTF-8"); response.getWriter().write("done"); } else { response.sendError(404); } }
From source file:eu.learnpad.core.impl.mv.XwikiBridgeInterfaceRestResource.java
@Override public VerificationsAvailable getAvailableVerifications() throws LpRestException { HttpClient httpClient = this.getHttpClient(); String uri = String.format("%s/learnpad/mv/bridge/getavailableverifications", this.restPrefix); GetMethod getMethod = new GetMethod(uri); getMethod.addRequestHeader("Accept", "application/xml"); try {// w w w . ja v a 2 s. c om httpClient.executeMethod(getMethod); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } VerificationsAvailable verificationsAvailable = null; try { JAXBContext jaxbContext = JAXBContext.newInstance(VerificationsAvailable.class); InputStream retIs = getMethod.getResponseBodyAsStream(); verificationsAvailable = (VerificationsAvailable) jaxbContext.createUnmarshaller().unmarshal(retIs); } catch (Exception e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } return verificationsAvailable; }
From source file:com.predic8.membrane.core.interceptor.acl.AccessControlInterceptorTest.java
private int callService(String uri) throws Exception { HttpClient client = new HttpClient(); client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); GetMethod get = new GetMethod("http://localhost:4000" + uri); return client.executeMethod(get); }
From source file:com.sixdimensions.wcm.cq.dao.webdav.WebDavDAO.java
/** * Creates a folder at the specified path if one does not already exist. * /* w w w . j a v a2 s . co m*/ * @param path * the path at which to create the folder * @throws IOException */ public void createFolder(final String path) throws IOException { this.log.debug("createFolder"); int status = 0; final String url = this.config.getHost() + ":" + this.config.getPort() + path; status = this.httpClient.executeMethod(new GetMethod(url + ".txt")); if (status != 200) { status = this.httpClient.executeMethod(new HttpAnyMethod("MKCOL", url)); if (status != 201) { throw new IOException("mkdir(" + url + ") failed, status code=" + status); } } }