List of usage examples for org.apache.http.client.utils URIUtils createURI
@Deprecated public static URI createURI(final String scheme, final String host, final int port, final String path, final String query, final String fragment) throws URISyntaxException
From source file:org.wso2.carbon.appfactory.apiManager.integration.utils.Utils.java
public static HttpPost createHttpPostRequest(URL url, List<NameValuePair> params, String path) throws AppFactoryException { URI uri;/*from w w w.j a v a 2 s . co m*/ try { uri = URIUtils.createURI(url.getProtocol(), url.getHost(), url.getPort(), path, URLEncodedUtils.format(params, "UTF-8"), null); } catch (URISyntaxException e) { String msg = "Invalid URL syntax"; log.error(msg, e); throw new AppFactoryException(msg, e); } return new HttpPost(uri); }
From source file:org.coffeebreaks.validators.nu.NuValidator.java
ValidationResult validateUri(URL url, ValidationRequest request) throws IOException { String parser = request.getValue("parser", null); HttpRequestBase method;//from w ww .ja v a2 s.co m List<NameValuePair> qParams = new ArrayList<NameValuePair>(); qParams.add(new BasicNameValuePair("out", "json")); if (parser != null) { qParams.add(new BasicNameValuePair("parser", parser)); } qParams.add(new BasicNameValuePair("doc", url.toString())); try { URI uri = new URI(baseUrl); URI uri2 = URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), URLEncodedUtils.format(qParams, "UTF-8"), null); method = new HttpGet(uri2); return validate(method); } catch (URISyntaxException e) { throw new IllegalArgumentException("invalid uri. Check your baseUrl " + baseUrl, e); } }
From source file:com.jzboy.couchdb.http.URITemplates.java
/** * URI used to clean up outdated view indexes * @see <a href="http://wiki.apache.org/couchdb/Compaction#View_compaction">CouchDB Wiki</a> *///from w w w .j a v a2 s . c om public static URI cleanupViews(String host, int port, String dbName) throws URISyntaxException { return URIUtils.createURI("http", host, port, dbName + "/_view_cleanup", null, null); }
From source file:org.cinedroid.util.CineworldAPIAssistant.java
/** * Sends a request tot he Cineworld API using a given {@link HttpClient}. * /*from w w w . j a va 2 s .co m*/ * @param client * @param method * the method to execute on the Cineworld server. * @param params * params to execute the method with, must include a valid key. For other restrictions see the <a * href="http://www.cineworld.co.uk/developer/api">API documentation</a> * @return the text returned by the server. * @throws CineworldAPIException * if the request failed for any reason. */ public String sendRequest(final HttpClient client, final API_METHOD method, final NameValuePair... params) throws CineworldAPIException { URI uri; try { uri = URIUtils.createURI("http", CINEWORLD_API_URL, -1, method.getMethod(), URLEncodedUtils.format(Arrays.asList(params), "UTF-8"), null); } catch (URISyntaxException e) { throw new CineworldAPIException("Unable to create API request, invalid URL", e); } HttpGet request = new HttpGet(uri); HttpResponse response; try { response = client.execute(request); } catch (ClientProtocolException e) { throw new CineworldAPIException("Unable to execute API request", e); } catch (IOException e) { throw new CineworldAPIException("Unable to execute API request", e); } if (response.getStatusLine().getStatusCode() != HttpsURLConnection.HTTP_OK) { throw new CineworldAPIException(String.format("Unable to execute API request, Code:%d", response.getStatusLine().getStatusCode())); } String responseBody; try { responseBody = EntityUtils.toString(response.getEntity()); } catch (ParseException e) { throw new CineworldAPIException("Unable to parse API response", e); } catch (IOException e) { throw new CineworldAPIException("Unable to read API response", e); } return responseBody; }
From source file:org.craftercms.social.util.UGCHttpClient.java
public HttpResponse getAudit(String ticket, String ugcId) throws URISyntaxException, ClientProtocolException, IOException { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("ticket", ticket)); URI uri = URIUtils.createURI(scheme, host, port, appPath + "/api/2/audit/" + ugcId + ".json", URLEncodedUtils.format(qparams, HTTP.UTF_8), null); HttpGet httpget = new HttpGet(uri); HttpClient httpclient = new DefaultHttpClient(); return httpclient.execute(httpget); }
From source file:org.jboss.shrinkwrap.tomcat_6.test.TomcatDeploymentIntegrationUnitTestCase.java
/** * Tests that we can execute an HTTP request and it's fulfilled as expected, * proving our deployment succeeded// w ww .ja v a2 s . co m */ @Test public void requestWebapp() throws Exception { // Get an HTTP Client final HttpClient client = new DefaultHttpClient(); // Make an HTTP Request, adding in a custom parameter which should be echoed back to us final String echoValue = "ShrinkWrap>Tomcat Integration"; final List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("to", PATH_ECHO_SERVLET)); params.add(new BasicNameValuePair("echo", echoValue)); final URI uri = URIUtils.createURI("http", HTTP_BIND_HOST, HTTP_BIND_PORT, NAME_WEBAPP + SEPARATOR + servletClass.getSimpleName(), URLEncodedUtils.format(params, "UTF-8"), null); final HttpGet request = new HttpGet(uri); // Execute the request log.info("Executing request to: " + request.getURI()); final HttpResponse response = client.execute(request); System.out.println(response.getStatusLine()); final HttpEntity entity = response.getEntity(); if (entity == null) { Assert.fail("Request returned no entity"); } // Read the result, ensure it's what we're expecting (should be the value of request param "echo") final BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); final String line = reader.readLine(); Assert.assertEquals("Unexpected response from Servlet", echoValue, line); }
From source file:ch.entwine.weblounge.common.impl.util.TestUtils.java
/** * Issues the the given request.// www . jav a 2 s.co m * * @param httpClient * the http client * @param request * the request * @param params * the request parameters * @throws Exception * if the request fails */ public static HttpResponse request(HttpClient httpClient, HttpUriRequest request, String[][] params) throws Exception { if (params != null) { if (request instanceof HttpGet) { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); if (params.length > 0) { for (String[] param : params) { if (param.length < 2) continue; qparams.add(new BasicNameValuePair(param[0], param[1])); } } URI requestURI = request.getURI(); URI uri = URIUtils.createURI(requestURI.getScheme(), requestURI.getHost(), requestURI.getPort(), requestURI.getPath(), URLEncodedUtils.format(qparams, "utf-8"), null); HeaderIterator headerIterator = request.headerIterator(); request = new HttpGet(uri); while (headerIterator.hasNext()) { request.addHeader(headerIterator.nextHeader()); } } else if (request instanceof HttpPost) { List<NameValuePair> formparams = new ArrayList<NameValuePair>(); for (String[] param : params) formparams.add(new BasicNameValuePair(param[0], param[1])); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "utf-8"); ((HttpPost) request).setEntity(entity); } else if (request instanceof HttpPut) { List<NameValuePair> formparams = new ArrayList<NameValuePair>(); for (String[] param : params) formparams.add(new BasicNameValuePair(param[0], param[1])); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "utf-8"); ((HttpPut) request).setEntity(entity); } } else { if (request instanceof HttpPost || request instanceof HttpPut) { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(new ArrayList<NameValuePair>(), "utf-8"); ((HttpEntityEnclosingRequestBase) request).setEntity(entity); } } return httpClient.execute(request); }
From source file:com.healthcit.cacure.dao.CouchDBDao.java
public String generateContextSpecificDb(String context) throws URISyntaxException, IOException { // Create the context-specific database if it does not exist log.info("In generateContextSpecificDb() method..."); String clonedDb = getSourceDbName() + buildDbSuffix(context); URI uri = URIUtils.createURI("http", host, port, "/" + clonedDb, null, null); String response = runGetQuery(uri); boolean dbDoesNotExist = JSONUtils.isJSONObject(response) && JSONObject.fromObject(response).containsKey(REASON) && StringUtils.equals(JSONObject.fromObject(response).getString(REASON), NO_DB_FILE); if (dbDoesNotExist) // then generate the database {/* w w w . j av a 2 s . com*/ runPutQuery(uri, new JSONObject().toString()); log.info("Database " + clonedDb + " generated."); } else // then the database already exists { log.info("Database " + clonedDb + " already exists on the server."); } // Initiate the replication job for the context-specific database log.info("Initiating replication for " + clonedDb); response = replicateDesignDocsInContextSpecificDb(clonedDb, getReplicationDesignDoc()); return response; }
From source file:com.jzboy.couchdb.http.URITemplates.java
/** * URI used to manipulate a document/* www. ja va 2 s. c o m*/ */ public static URI document(String host, int port, String dbName, String docId, boolean batch) throws URISyntaxException { String path = String.format("%s/%s", dbName, docId); String query = batch ? "batch=ok" : null; return URIUtils.createURI("http", host, port, path, query, null); }