Example usage for org.apache.http.client.utils URIUtils createURI

List of usage examples for org.apache.http.client.utils URIUtils createURI

Introduction

In this page you can find the example usage for org.apache.http.client.utils URIUtils createURI.

Prototype

@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 

Source Link

Document

Constructs a URI using all the parameters.

Usage

From source file:com.brightcove.com.uploader.helper.OrchestratorFacade.java

private URI createMannheimEndpointURI(final String path, final String query) throws URISyntaxException {
    return URIUtils.createURI("http", orch, orchPort, path, query, null);
}

From source file:uk.ac.susx.tag.method51.twitter.geocoding.geonames.GeonamesSPARQLLocationDatabase.java

public String makeRequest(String query) throws IOException, URISyntaxException {

    HttpGet get = new HttpGet();

    String queryString = "query=" + URLEncoder.encode(query, "UTF-8");

    queryString += "&output=json";

    String locationLookupURI = "/ds/query";
    int locationLookupPort = port;
    String locationLookupHost = host;
    URI uri = URIUtils.createURI("http", locationLookupHost, locationLookupPort, locationLookupURI, queryString,
            null);//from   w  w w.j  a v  a2  s  .  c o  m

    get.setURI(uri);

    HttpClient httpClient = new DefaultHttpClient();

    ResponseHandler<String> responseHandler = new BasicResponseHandler();

    String responseBody = httpClient.execute(get, responseHandler);

    httpClient.getConnectionManager().shutdown();

    return responseBody;
}

From source file:gr.ntua.ivml.awareness.search.SearchServiceAccess.java

private URI constructURIRecord(String recid) {
    URI uri = null;/*from   ww  w  .j  a  v a 2s.co  m*/
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair("wskey", "api2demo"));
    try {
        uri = URIUtils.createURI("http", "preview.europeana.eu", 80, "/api/v2/record" + recid + ".json",
                URLEncodedUtils.format(qparams, "UTF-8"), null);
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return uri;
}

From source file:org.onsteroids.eve.api.connector.http.PooledHttpApiConnection.java

@Override
public XmlApiResult call(final String xmlPath, final ApiKey key, final Map<String, String> parameters)
        throws ApiException {
    if (httpClient == null) {
        initializeHttpClient();/*  w w w .ja v a2s  .c o m*/
    }

    Preconditions.checkNotNull(xmlPath, "XmlPath");
    LOG.debug("Requesting {}...", xmlPath);

    try {
        // build query
        List<NameValuePair> qparams = Lists.newArrayList();
        if (key != null) {
            LOG.trace("Using ApiKey {}", key);
            qparams.add(new BasicNameValuePair("userID", Long.toString(key.getUserId())));
            qparams.add(new BasicNameValuePair("apiKey", key.getApiKey()));
        }
        if (parameters != null) {
            LOG.trace("Using parameters: {}", parameters);
            for (Map.Entry<String, String> entry : parameters.entrySet()) {
                qparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
            }
        }

        final URI requestURI = URIUtils.createURI(serverUri.getScheme(), serverUri.getHost(),
                serverUri.getPort(), xmlPath, URLEncodedUtils.format(qparams, "UTF-8"), null);
        LOG.trace("Resulting URI: {}", requestURI);
        final HttpPost postRequest = new HttpPost(requestURI);

        // make the real call
        LOG.trace("Fetching result from {}...", serverUri);
        final HttpResponse response = httpClient.execute(postRequest);
        final InputStream stream = response.getEntity().getContent();

        // parse the xml
        final DocumentBuilder builder = builderFactory.newDocumentBuilder();
        final Document doc = builder.parse(stream);

        // process the xml
        return apiCoreParser.call(doc, xmlPath, key, parameters, serverUri);

    } catch (ApiException e) {
        throw e;
    } catch (Exception e) {
        throw new InternalApiException(e);
    }
}

From source file:com.jzboy.couchdb.http.URITemplates.java

/**
 * URI used to trigger database compaction
 * @see <a href="http://wiki.apache.org/couchdb/Compaction">CouchDB Wiki</a>
 *///w w w.  ja v a  2  s .c o  m
public static URI compact(String host, int port, String dbName) throws URISyntaxException {
    return URIUtils.createURI("http", host, port, dbName + "/_compact", null, null);
}

From source file:org.mahasen.client.Download.java

public void download(String fileName, String downloadRepo)
        throws IOException, MahasenClientException, URISyntaxException {
    httpclient = new DefaultHttpClient();
    OutputStream outputStream = null;

    try {/* www.j a  va 2  s.c o m*/
        String userName = clientLoginData.getUserName();
        String passWord = clientLoginData.getPassWord();
        String hostAndPort = clientLoginData.getHostNameAndPort();
        String userId = clientLoginData.getUserId(userName, passWord);
        Boolean isLogged = clientLoginData.isLoggedIn();
        System.out.println(" Is Logged : " + isLogged);

        if (isLogged == true) {
            httpclient = WebClientSSLWrapper.wrapClient(httpclient);

            List<NameValuePair> qparams = new ArrayList<NameValuePair>();
            qparams.add(new BasicNameValuePair("fileName", fileName));

            URI uri = URIUtils.createURI("https", hostAndPort, -1, "/mahasen/download_ajaxprocessor.jsp",
                    URLEncodedUtils.format(qparams, "UTF-8"), null);

            HttpPost httppost = new HttpPost(uri);

            System.out.println("executing request " + httppost.getRequestLine());
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity httpEntity = response.getEntity();

            if (httpEntity.getContentLength() > 0) {
                outputStream = new FileOutputStream(downloadRepo + "/" + fileName);
                httpEntity.writeTo(outputStream);
            } else {
                System.out.println("no content available");
            }

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (httpEntity != null) {
                System.out.println("Response content length: " + httpEntity.getContentLength());
                System.out.println("Chunked?: " + httpEntity.isChunked());
            }
            EntityUtils.consume(httpEntity);

            if (response.getStatusLine().getStatusCode() == 900) {
                throw new MahasenClientException(String.valueOf(response.getStatusLine()));
            }
        } else {
            System.out.println("User has to be logged in to perform this function");
        }
    } finally {
        httpclient.getConnectionManager().shutdown();
    }

}

From source file:org.mahasen.client.Delete.java

/**
 * @param fileName//from w ww .  java 2 s  .co  m
 * @throws IOException
 */
public void delete(String fileName) throws IOException, MahasenClientException, URISyntaxException {
    httpclient = new DefaultHttpClient();

    try {

        String userName = clientLoginData.getUserName();
        String passWord = clientLoginData.getPassWord();
        String hostAndPort = clientLoginData.getHostNameAndPort();
        String userId = clientLoginData.getUserId(userName, passWord);
        Boolean isLogged = clientLoginData.isLoggedIn();
        System.out.println(" Is Logged : " + isLogged);

        if (isLogged == true) {
            httpclient = WebClientSSLWrapper.wrapClient(httpclient);

            List<NameValuePair> qparams = new ArrayList<NameValuePair>();

            qparams.add(new BasicNameValuePair("fileName", fileName));

            URI uri = URIUtils.createURI("https", hostAndPort, -1, "/mahasen/delete_ajaxprocessor.jsp",
                    URLEncodedUtils.format(qparams, "UTF-8"), null);

            HttpPost httppost = new HttpPost(uri);

            System.out.println("executing request " + httppost.getRequestLine());
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity resEntity = response.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());

            EntityUtils.consume(resEntity);
            if (response.getStatusLine().getStatusCode() == 900) {
                throw new MahasenClientException(String.valueOf(response.getStatusLine()));
            }

        } else {
            System.out.println("User has to be logged in to perform this function");
        }
    } finally

    {
        httpclient.getConnectionManager().shutdown();
    }

}

From source file:org.craftercms.social.util.UGCHttpClient.java

public HttpResponse dislike(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/ugc/dislike/" + ugcId + ".json",
            URLEncodedUtils.format(qparams, HTTP.UTF_8), null);
    HttpPost httppost = new HttpPost(uri);
    HttpClient httpclient = new DefaultHttpClient();
    return httpclient.execute(httppost);
}

From source file:com.todoist.TodoistBase.java

protected HttpGet request(String command, Map<String, Object> parameters, boolean secure) {
    List<NameValuePair> qparameters = new ArrayList<NameValuePair>();
    for (Map.Entry<String, Object> entry : parameters.entrySet()) {
        Object value = entry.getValue();
        String paramValue = value == null ? null : value.toString();
        qparameters.add(new BasicNameValuePair(entry.getKey(), paramValue));
    }//from  w  w w .ja va  2s .c om

    try {
        String scheme = secure ? "https" : "http";
        int port = secure ? 443 : 80;

        return new HttpGet(URIUtils.createURI(scheme, "todoist.com", port, "/API/" + command,
                URLEncodedUtils.format(qparameters, "UTF-8"), null));
    } catch (URISyntaxException e) {
        throw new TodoistException(e);
    }
}

From source file:org.jboss.shrinkwrap.jetty_6.test.JettyDeploymentIntegrationUnitTestCase.java

/**
 * Doesn't really test anything now; shows end-user view only
 *//*from  w  w  w.  java  2s .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>Jetty Integration";
    final List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("jsp", PATH_JSP));
    params.add(new BasicNameValuePair("echo", echoValue));
    final URI uri = URIUtils.createURI("http", "localhost", 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);
    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);

}