List of usage examples for org.apache.commons.httpclient.methods GetMethod setQueryString
public void setQueryString(String queryString)
From source file:com.apifest.oauth20.tests.OAuth20BasicTest.java
public String validateToken(String token) { URIBuilder builder = null;//w w w . ja va 2 s .co m String response = null; try { builder = new URIBuilder(baseOAuth20Uri + TOKEN_VALIDATE_ENDPOINT); GetMethod get = new GetMethod(builder.build().toString()); get.setQueryString("token=" + token); response = readResponse(get); } catch (IOException e) { log.error("cannot obtain client default scope", e); } catch (URISyntaxException e) { log.error("cannot obtain client default scope", e); } return response; }
From source file:com.gisgraphy.servlet.StreetServletTest.java
@Test public void testServletShouldReturnCorrectContentTypeForSupportedFormat() { String url = streetServletUrl + STREET_SERVLET_CONTEXT + "/geolocsearch"; String queryString;/*from w w w .j a va 2s .c o m*/ for (OutputFormat format : OutputFormat.values()) { GetMethod get = null; try { queryString = StreetSearchQuery.LAT_PARAMETER + "=3&" + StreetSearchQuery.LONG_PARAMETER + "=4&format=" + format.toString(); HttpClient client = new HttpClient(); get = new GetMethod(url); get.setQueryString(queryString); client.executeMethod(get); // result = get.getResponseBodyAsString(); Header contentType = get.getResponseHeader("Content-Type"); OutputFormat expectedformat = OutputFormatHelper.getDefaultForServiceIfNotSupported(format, GisgraphyServiceType.STREET); assertTrue(contentType.getValue().equals(expectedformat.getContentType())); } catch (IOException e) { fail("An exception has occured " + e.getMessage()); } finally { if (get != null) { get.releaseConnection(); } } } }
From source file:eu.learnpad.core.impl.cw.XwikiCoreFacadeRestResource.java
@Override public InputStream getModel(String modelSetId, ModelSetType type) throws LpRestException { // Now send the package's path to the importer for XWiki HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/cw/corefacade/getmodel/%s", DefaultRestResource.REST_URI, modelSetId);/*from w ww . j ava 2 s . c om*/ GetMethod getMethod = new GetMethod(uri); getMethod.addRequestHeader("Accept", "application/xml"); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("type", type.toString()); getMethod.setQueryString(queryString); InputStream model = null; try { httpClient.executeMethod(getMethod); model = getMethod.getResponseBodyAsStream(); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } return model; }
From source file:eu.learnpad.core.impl.cw.XwikiCoreFacadeRestResource.java
@Override public String calculateKPI(String modelSetId) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/cw/corefacade/dashboardkpi/%s/calculatekpi", DefaultRestResource.REST_URI, modelSetId); GetMethod getMethod = new GetMethod(uri); getMethod.addRequestHeader(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("modelsetid", modelSetId); getMethod.setQueryString(queryString); try {/*from w w w .j a v a 2 s.c om*/ httpClient.executeMethod(getMethod); String url = getMethod.getResponseBodyAsString(); return url; } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } }
From source file:com.agiletec.plugins.jpcasclient.aps.system.services.controller.control.CasClientTicketValidationUtil.java
/** * Service method for execution of get request. * *///from ww w . j a v a 2 s.com public String CASgetMethod(GetMethod authget, HttpClient client, String url, Map<String, String> params) { String body = null; authget.setPath(url); int i = 0; if (null != params && params.size() > 0) { NameValuePair[] services = new NameValuePair[params.size()]; for (Iterator iter = params.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String key = (String) entry.getKey(); String value = (String) entry.getValue(); services[i++] = new NameValuePair(key, value); } authget.setQueryString(services); } try { client.executeMethod(authget); body = authget.getResponseBodyAsString(); } catch (Throwable t) { _logger.error("Error in CasClientTicketValidationUtil - CASgetMethod", t); throw new RuntimeException("Error in CasClientTicketValidationUtil - CASgetMethod", t); } finally { authget.releaseConnection(); } return body; }
From source file:com.bluexml.side.framework.facetmap.alfrescoConnector.AlfrescoCommunicator.java
private byte[] buildGetMethodAndExecute(String url, Map<String, String> params) { byte[] responseBody = {}; GetMethod get = new GetMethod(url); get.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); logger.debug("parameters :" + params); ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>(); for (Map.Entry<String, String> entry : params.entrySet()) { pairs.add(new NameValuePair(entry.getKey(), entry.getValue())); }/* w ww . j a v a2s . co m*/ NameValuePair[] arr = new NameValuePair[pairs.size()]; arr = pairs.toArray(arr); get.setQueryString(arr); // Execute the method. int statusCode; try { statusCode = http.executeMethod(get); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + get.getStatusLine()); } // Read the response body. responseBody = get.getResponseBody(); } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { // Release the connection. get.releaseConnection(); } return responseBody; }
From source file:fr.openwide.talendalfresco.rest.client.RestAuthenticationTest.java
public void testRestLogin() { // create client and configure it HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout); // instantiating a new method and configuring it GetMethod method = new GetMethod(restCommandUrlPrefix + "login"); method.setFollowRedirects(true); // ? // Provide custom retry handler is necessary (?) method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); NameValuePair[] params = new NameValuePair[] { new NameValuePair("username", "admin"), new NameValuePair("password", "admin") }; method.setQueryString(params); try {//from ww w. ja v a 2 s. c o m // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } // Read the response body. byte[] responseBody = method.getResponseBody(); System.out.println(new String(responseBody)); // TODO rm HashSet<String> defaultElementSet = new HashSet<String>( Arrays.asList(new String[] { RestConstants.TAG_COMMAND, RestConstants.TAG_CODE, RestConstants.TAG_CONTENT, RestConstants.TAG_ERROR, RestConstants.TAG_MESSAGE })); HashMap<String, String> elementValueMap = new HashMap<String, String>(6); try { XMLEventReader xmlReader = XmlHelper.getXMLInputFactory() .createXMLEventReader(new ByteArrayInputStream(responseBody)); StringBuffer singleLevelTextBuf = null; while (xmlReader.hasNext()) { XMLEvent event = xmlReader.nextEvent(); switch (event.getEventType()) { case XMLEvent.CHARACTERS: case XMLEvent.CDATA: if (singleLevelTextBuf != null) { singleLevelTextBuf.append(event.asCharacters().getData()); } // else element not meaningful break; case XMLEvent.START_ELEMENT: StartElement startElement = event.asStartElement(); String elementName = startElement.getName().getLocalPart(); if (defaultElementSet.contains(elementName) // TODO another command specific level || "ticket".equals(elementName)) { // reinit buffer at start of meaningful elements singleLevelTextBuf = new StringBuffer(); } else { singleLevelTextBuf = null; // not useful } break; case XMLEvent.END_ELEMENT: if (singleLevelTextBuf == null) { break; // element not meaningful } // TODO or merely put it in the map since the element has been tested at start EndElement endElement = event.asEndElement(); elementName = endElement.getName().getLocalPart(); if (defaultElementSet.contains(elementName)) { String value = singleLevelTextBuf.toString(); elementValueMap.put(elementName, value); // TODO test if it is code and it is not OK, break to error handling } // TODO another command specific level else if ("ticket".equals(elementName)) { ticket = singleLevelTextBuf.toString(); } // singleLevelTextBuf = new StringBuffer(); // no ! in start break; } } } catch (XMLStreamException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Throwable t) { // TODO Auto-generated catch block t.printStackTrace(); //throw t; } String code = elementValueMap.get(RestConstants.TAG_CODE); assertTrue(RestConstants.CODE_OK.equals(code)); System.out.println("got ticket " + ticket); } catch (HttpException e) { // TODO e.printStackTrace(); } catch (IOException e) { // TODO e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } }
From source file:edu.stanford.epad.epadws.processing.pipeline.task.PluginStartTask.java
@Override public void run() { String username = EPADSessionOperations.getSessionUser(jsessionID); EpadProjectOperations projectOperations = DefaultEpadProjectOperations.getInstance(); projectOperations.createEventLog(username, projectID, null, null, null, null, annotationID, "Start PlugIn", pluginName);/*from ww w . j av a 2s . c o m*/ HttpClient client = new HttpClient(); // TODO Get rid of localhost String url = EPADConfig.getParamValue("serverProxy", "http://localhost:8080") + EPADConfig.getParamValue("webserviceBase", "/epad") + "/plugin/" + pluginName + "/?" //aimFile=" + annotationID + "&frameNumber=" + frameNumber + "&projectID=" + projectID; if (annotationID != null) url += "&aimFile=" + annotationID; // else // url+="&aimFile=" + getAnnotationIDs(); log.info("Triggering ePAD plugin at " + url + " is annotation null " + (annotationID != null)); projectOperations.updateUserTaskStatus(username, TaskStatus.TASK_PLUGIN, pluginName.toLowerCase() + ":" + annotationID, "Started Plugin", new Date(), null); GetMethod method = new GetMethod(url); log.info("pluginurl " + url); if (annotationID == null && annotationIDs.length > 0) { NameValuePair[] params = new NameValuePair[annotationIDs.length + 2]; int i = 0; for (String aimId : annotationIDs) { params[i++] = new NameValuePair("aims", aimId); } params[i++] = new NameValuePair("frameNumber", String.valueOf(frameNumber)); params[i] = new NameValuePair("projectID", projectID); method.setQueryString(params); } method.setRequestHeader("Cookie", "JSESSIONID=" + jsessionID); try { int statusCode = client.executeMethod(method); log.info("Status code returned from plugin " + statusCode); } catch (Exception e) { log.warning("Error calling plugin " + pluginName, e); try { PluginOperations pluginOperations = PluginOperations.getInstance(); Plugin plugin = pluginOperations.getPluginByName(pluginName); plugin.setStatus("Error calling plugin :" + e.getMessage()); plugin.save(); } catch (Exception e1) { } } finally { method.releaseConnection(); } }
From source file:eu.learnpad.core.impl.cw.XwikiCoreFacadeRestResource.java
@Override public KBProcessingStatus getKPICalculationStatus(String kpiCalculationProcessId) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/cw/corefacade/dashboardkpi/%s/status", DefaultRestResource.REST_URI, kpiCalculationProcessId);/*from w ww .jav a 2 s. c o m*/ GetMethod getMethod = new GetMethod(uri); getMethod.addRequestHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("kpiCalculationProcessId", kpiCalculationProcessId); getMethod.setQueryString(queryString); KBProcessingStatus status = null; try { httpClient.executeMethod(getMethod); InputStream statusAsStream = getMethod.getResponseBodyAsStream(); JAXBContext jc = JAXBContext.newInstance(KBProcessingStatus.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); status = (KBProcessingStatus) unmarshaller.unmarshal(statusAsStream); } catch (IOException | JAXBException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } return status; }
From source file:fr.openwide.talendalfresco.rest.client.importer.RestImportFileTest.java
public void logout() { // create client and configure it HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout); // instantiating a new method and configuring it GetMethod method = new GetMethod(restCommandUrlPrefix + "logout"); method.setFollowRedirects(true); // ? // Provide custom retry handler is necessary (?) method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); NameValuePair[] params = new NameValuePair[] { new NameValuePair("ticket", ticket) }; // TODO always provide ticket method.setQueryString(params); try {/*from w w w . j av a 2s. c o m*/ // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } // Read the response body. byte[] responseBody = method.getResponseBody(); // Deal with the response. // Use caution: ensure correct character encoding and is not binary data System.out.println(new String(responseBody)); } catch (HttpException e) { // TODO e.printStackTrace(); } catch (IOException e) { // TODO e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } }