List of usage examples for org.apache.commons.httpclient NameValuePair NameValuePair
public NameValuePair(String name, String value)
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())); }//from www . j a v a 2s . c om 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.ClientImportCommand.java
public void setTargetLocationContainerType(String targetLocationContainerType) { setParam(new NameValuePair(RestConstants.PROP_IMPORT_TARGET_LOCATION_CONTAINER_TYPE, targetLocationContainerType)); }
From source file:ixa.entity.linking.DBpediaSpotlightClient.java
public Document extract(Text text, int port) throws AnnotationException { LOG.info("Querying API."); String spotlightResponse = ""; Document doc = null;/*from w w w . ja v a 2 s . co m*/ try { String url = "http://localhost:" + port + "/rest/disambiguate"; PostMethod method = new PostMethod(url); method.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); NameValuePair[] params = { new NameValuePair("text", text.text()), new NameValuePair("spotter", "SpotXmlParser"), new NameValuePair("confidence", Double.toString(CONFIDENCE)), new NameValuePair("support", Integer.toString(SUPPORT)) }; method.setRequestBody(params); method.setRequestHeader(new Header("Accept", "text/xml")); spotlightResponse = request(method); doc = loadXMLFromString(spotlightResponse); } catch (javax.xml.parsers.ParserConfigurationException ex) { } catch (org.xml.sax.SAXException ex) { } catch (java.io.IOException ex) { } return doc; }
From source file:net.datapipe.CloudStack.CloudStackAPI.java
public Document deleteLBHealthCheckPolicy(String id) throws Exception { LinkedList<NameValuePair> arguments = newQueryValues("deleteLBHealthCheckPolicy", null); arguments.add(new NameValuePair("id", id)); return Request(arguments); }
From source file:it.geosolutions.geoserver.rest.publisher.GeoserverRESTShapeTest.java
@Test public void testPublishDeleteExternalComplexShapeZip() throws FileNotFoundException, IOException { if (!enabled()) { return;/*from ww w. j a v a2 s .c om*/ } deleteAllWorkspacesRecursively(); // Assume.assumeTrue(enabled); assertTrue(publisher.createWorkspace(DEFAULT_WS)); String storeName = "resttestshp_complex"; String datasetName = "cities"; File zipFile = new ClassPathResource("testdata/shapefile/cities.shp").getFile(); // test insert boolean published = publisher.publishShp(DEFAULT_WS, storeName, new NameValuePair[] { new NameValuePair("charset", "UTF-8") }, datasetName, UploadMethod.EXTERNAL, zipFile.toURI(), "EPSG:4326", GSCoverageEncoderTest.WGS84, ProjectionPolicy.REPROJECT_TO_DECLARED, "polygon"); assertTrue("publish() failed", published); assertTrue(existsLayer(datasetName)); RESTLayer layer = reader.getLayer(datasetName); LOGGER.info("Layer style is " + layer.getDefaultStyle()); //test delete boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, storeName, datasetName); assertTrue("Unpublish() failed", ok); assertFalse(existsLayer(datasetName)); // remove also datastore boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName, false); assertTrue("removeDatastore() failed", dsRemoved); }
From source file:eu.learnpad.core.impl.or.XwikiBridgeInterfaceRestResource.java
@Override public Recommendations askRecommendation(String modelSetId, String artifactId, String userId, String simulationSessionId) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/or/bridge/%s/recommendation", DefaultRestResource.REST_URI, modelSetId);//www.j a v a 2s . c o m GetMethod getMethod = new GetMethod(uri); getMethod.addRequestHeader("Accept", "application/xml"); boolean hasSimulationId = false; if ((simulationSessionId != null) && (!simulationSessionId.isEmpty())) { hasSimulationId = true; } int queryStringSize = 2; if (hasSimulationId) { queryStringSize = 3; } NameValuePair[] queryString = new NameValuePair[queryStringSize]; queryString[0] = new NameValuePair("artifactid", artifactId); queryString[1] = new NameValuePair("userid", userId); if (hasSimulationId) { queryString[2] = new NameValuePair("simulationsessionid", simulationSessionId); } getMethod.setQueryString(queryString); Recommendations recommendations = null; try { httpClient.executeMethod(getMethod); InputStream recStream = getMethod.getResponseBodyAsStream(); if (recStream != null) { JAXBContext jc = JAXBContext.newInstance(Recommendations.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); recommendations = (Recommendations) unmarshaller.unmarshal(recStream); } } catch (JAXBException | IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); } return recommendations; }
From source file:com.yahoo.flowetl.services.http.BaseHttpGenerator.java
/** * Translates a http param object into a post method. * //from ww w.j a v a 2 s . c om * @return the post method */ @SuppressWarnings("deprecation") protected PostMethod getPostMethod(HttpParams in) { PostMethod meth = new PostMethod(String.valueOf(in.uri)); if (in instanceof PostHttpParams) { PostHttpParams pin = (PostHttpParams) in; if (pin.additionalData instanceof Map<?, ?>) { Map<?, ?> bodyParams = (Map<?, ?>) pin.additionalData; NameValuePair[] pieces = new NameValuePair[bodyParams.size()]; int i = 0; for (Entry<?, ?> kv : bodyParams.entrySet()) { pieces[i] = new NameValuePair(String.valueOf(kv.getKey()), String.valueOf(kv.getValue())); i++; } meth.setRequestBody(pieces); } else if (pin.additionalData instanceof String) { meth.setRequestBody((String) pin.additionalData); } else if (pin.additionalData != null) { meth.setRequestBody(String.valueOf(pin.additionalData)); } } return meth; }
From source file:com.ltasks.LtasksNameFinderClient.java
/** * Annotate a text/*from w w w . j a v a 2 s . c om*/ * * @param aText * the text to annotate * @return the annotation object * @throws HttpException * Got a protocol error. * @throws IOException * Failed to communicate or to read the result. * @throws IllegalArgumentException * The data received from server was invalid. */ public LtasksObject processText(String aText) throws HttpException, IOException { return post(Collections.singletonList(new NameValuePair("text", aText))); }
From source file:com.shelrick.openamplify.client.OpenAmplifyClientImpl.java
private List<NameValuePair> getBaseParams() { List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new NameValuePair("apikey", apiKey)); params.add(new NameValuePair("outputformat", "xml")); //params.add(new NameValuePair("optimiseRespTime", "disable")); return params; }
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);// w w w. 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; }