List of usage examples for org.apache.commons.httpclient.methods GetMethod setQueryString
public void setQueryString(String queryString)
From source file:eu.learnpad.rest.utils.internal.DefaultCPRestUtils.java
public InputStream getModel(String modelId, String type) { HttpClient httpClient = getClient(); String uri = REST_URI + "/learnpad/model/" + modelId; GetMethod getMethod = new GetMethod(uri); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("type", type); getMethod.setQueryString(queryString); getMethod.addRequestHeader("Accept", "application/xml"); getMethod.addRequestHeader("Accept-Ranges", "bytes"); try {//from w w w.jav a2s . c om httpClient.executeMethod(getMethod); } catch (HttpException e) { logger.error("Unable to process the GET request for model '" + modelId + "' (" + type + ").", e); return null; } catch (IOException e) { logger.error("Unable to GET the '" + modelId + "' model (" + type + ").", e); return null; } try { return getMethod.getResponseBodyAsStream(); } catch (IOException e) { logger.error("Unable to extract the '" + modelId + "' model (" + type + ") from GET response.", e); return null; } }
From source file:edu.unc.lib.dl.fedora.FedoraAccessControlService.java
public boolean hasAccess(PID pid, AccessGroupSet groups, Permission permission) { GetMethod method = new GetMethod(this.aclEndpointUrl + pid.getPid() + "/hasAccess/" + permission.name()); try {/*from w w w .j ava2 s . co m*/ method.setQueryString( new NameValuePair[] { new NameValuePair("groups", groups.joinAccessGroups(";")) }); int statusCode = httpClient.executeMethod(method); if (statusCode == HttpStatus.SC_OK) { String response = method.getResponseBodyAsString(); Boolean hasAccess = Boolean.parseBoolean(response); return hasAccess != null && hasAccess; } } catch (HttpException e) { log.error("Failed to check hasAccess for " + pid, e); } catch (IOException e) { log.error("Failed to check hasAccess for " + pid, e); } finally { method.releaseConnection(); } return false; }
From source file:eu.learnpad.core.impl.dash.XwikiBridgeInterfaceRestResource.java
@Override public String getKPIValuesView(String modelSetId, String businessActorId) throws LpRestException { HttpClient httpClient = this.getAnonymousClient(); String uri = String.format("%s/learnpad/dash/bridge/view/%s", this.restPrefix, modelSetId); GetMethod getMethod = new GetMethod(uri); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("businessactor", businessActorId); getMethod.setQueryString(queryString); try {//from w ww.j av a2 s . co m httpClient.executeMethod(getMethod); return getMethod.getResponseBodyAsString(); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); } }
From source file:edu.ucsb.eucalyptus.admin.server.extensions.store.ImageStoreServiceImpl.java
public String requestJSON(String sessionId, Method method, String uri, Parameter[] params) { UserInfoWeb user;/*ww w .ja v a 2s .c o m*/ try { user = EucalyptusWebBackendImpl.getUserRecord(sessionId); } catch (Exception e) { return errorJSON("Session authentication error: " + e.getMessage()); } NameValuePair[] finalParams; try { finalParams = getFinalParameters(method, uri, params, user); } catch (MalformedURLException e) { return errorJSON("Malformed URL: " + uri); } HttpClient client = new HttpClient(); HttpMethod httpMethod; if (method == Method.GET) { GetMethod getMethod = new GetMethod(uri); httpMethod = getMethod; getMethod.setQueryString(finalParams); } else if (method == Method.POST) { PostMethod postMethod = new PostMethod(uri); httpMethod = postMethod; postMethod.addParameters(finalParams); } else { throw new UnsupportedOperationException("Unknown method"); } try { int statusCode = client.executeMethod(httpMethod); String str = ""; InputStream in = httpMethod.getResponseBodyAsStream(); byte[] readBytes = new byte[1024]; int bytesRead = -1; while ((bytesRead = in.read(readBytes)) > 0) { str += new String(readBytes, 0, bytesRead); } return str; } catch (HttpException e) { return errorJSON("Protocol error: " + e.getMessage()); } catch (IOException e) { return errorJSON("Proxy error: " + e.getMessage()); } finally { httpMethod.releaseConnection(); } }
From source file:com.cerema.cloud2.lib.resources.shares.GetRemoteSharesForFileOperation.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; GetMethod get = null; try {//w w w . j a v a2s . c o m // 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(); // Parse xml response and obtain the list of shares ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( new ShareXMLParser()); parser.setOwnCloudVersion(client.getOwnCloudVersion()); parser.setServerBaseUri(client.getBaseUri()); result = parser.parse(response); if (result.isSuccess()) { Log_OC.d(TAG, "Got " + result.getData().size() + " shares"); } } 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.navercorp.pinpoint.plugin.httpclient3.HttpClientIT.java
@Test public void hostConfig() throws Exception { HttpClient client = new HttpClient(); client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT); client.getParams().setSoTimeout(SO_TIMEOUT); HostConfiguration config = new HostConfiguration(); config.setHost("weather.naver.com", 80, "http"); GetMethod method = new GetMethod("/rgn/cityWetrMain.nhn"); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") }); try {/*from w ww.j a v a2s .c om*/ // Execute the method. client.executeMethod(config, method); } catch (Exception ignored) { } finally { method.releaseConnection(); } PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); }
From source file:com.shelrick.openamplify.client.OpenAmplifyClientImpl.java
@Override public OpenAmplifyResponse analyzeUrl(String url, Analysis analysis, Integer maxTopicResults) throws OpenAmplifyClientException { List<NameValuePair> params = getBaseParams(); params.add(new NameValuePair("sourceurl", url)); params.add(new NameValuePair("analysis", analysis.type())); params.add(new NameValuePair("maxtopicresult", maxTopicResults.toString())); GetMethod getMethod = new GetMethod(apiUrl); getMethod.setQueryString(params.toArray(new NameValuePair[1])); String responseText = doRequest(getMethod); return parseResponse(responseText, analysis); }
From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClientIT.java
@Test public void test() throws Exception { HttpClient client = new HttpClient(); client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT); client.getParams().setSoTimeout(SO_TIMEOUT); GetMethod method = new GetMethod(webServer.getCallHttpUrl()); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") }); try {/*from ww w .j av a 2 s .co m*/ // Execute the method. client.executeMethod(method); } catch (Exception ignored) { } finally { method.releaseConnection(); } PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); }
From source file:com.shelrick.openamplify.client.OpenAmplifyClientImpl.java
@Override public OpenAmplifyResponse searchUrl(String url, Analysis analysis, List<String> searchTermsList, Integer maxTopicResults) throws OpenAmplifyClientException { List<NameValuePair> params = getBaseParams(); params.add(new NameValuePair("sourceurl", url)); params.add(new NameValuePair("analysis", analysis.type())); params.add(new NameValuePair("searchTerms", getSearchTerms(searchTermsList))); params.add(new NameValuePair("maxtopicresult", maxTopicResults.toString())); GetMethod getMethod = new GetMethod(apiUrl); getMethod.setQueryString(params.toArray(new NameValuePair[1])); String responseText = doRequest(getMethod); return parseResponse(responseText, analysis); }
From source file:egpi.tes.ahv.servicio.MenuReporteJasper.java
/** * //from ww w. j ava 2 s . com */ public void obtenerDescriptorGeneral() throws ReporteJasperException { boolean privado = false; try { String user = autenticacionVO != null && autenticacionVO.getUsername() != null ? autenticacionVO.getUsername() : this.properties.getProperty("usuariopublico"); String pass = autenticacionVO != null && autenticacionVO.getPassword() != null ? autenticacionVO.getPassword() : this.properties.getProperty("password"); if (this.properties != null && user != null && this.properties.getProperty("usuariopublico") != null && !this.properties.getProperty("usuariopublico").equals(user)) { pathaplicacion = "pathprivado"; privado = true; } else { pathaplicacion = "pathpublico"; } System.out.println("pathaplicacion==" + pathaplicacion + " privado=" + privado); PostMethod postMethod = new PostMethod(properties.getProperty("urllogueo")); postMethod.addParameter("j_username", user); postMethod.addParameter("j_password", pass); status = client.executeMethod(postMethod); System.out.println("status 01=" + status + "pathaplicacion:" + pathaplicacion); if (status == 200) { String resourseURL = properties.getProperty("urlrecursos") + "" + properties.getProperty(pathaplicacion); GetMethod getMethod = new GetMethod(resourseURL); getMethod.setQueryString("?type=reportUnit&recursive=1"); status = client.executeMethod(getMethod); if (status == 200) { String descriptorSource = getMethod.getResponseBodyAsString(); listaReporte = (ArrayList) this.listadoReportes.getReportes(descriptorSource); sincronizarMenu.setProperties(properties); sincronizarMenu.setUSER(user); sincronizarMenu.setPASS(pass); sincronizarMenu.sincronizarArbolNavegacion(listaReporte); obj.put("status", String.valueOf(status)); obj.put("user", String.valueOf(user)); obj.put("privado", String.valueOf(privado)); } else { throw new ReporteJasperException(this.properties.getProperty("msg_" + String.valueOf(status))); } } else { throw new ReporteJasperException(this.properties.getProperty("msg_" + String.valueOf(status))); } } catch (IOException ex) { ex.printStackTrace(); throw new ReporteJasperException(ex.getMessage()); } }