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.jelastic.JelasticService.java

DeployResponse deploy(AuthenticationResponse authentication, UploadResponse upLoader) {
    DeployResponse deployResponse = null;
    try {/*from  w w  w  .ja v a2 s.c o m*/
        DefaultHttpClient httpclient = getHttpClient();
        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("charset", "UTF-8"));
        qparams.add(new BasicNameValuePair("session", authentication.getSession()));
        qparams.add(new BasicNameValuePair("archiveUri", upLoader.getFile()));
        qparams.add(new BasicNameValuePair("archiveName", upLoader.getName()));
        qparams.add(new BasicNameValuePair("newContext", getContext()));
        qparams.add(new BasicNameValuePair("domain", getEnvironment()));

        for (NameValuePair nameValuePair : qparams) {
            project.log(nameValuePair.getName() + " : " + nameValuePair.getValue(), Project.MSG_DEBUG);
        }

        URI uri = URIUtils.createURI(getProtocol(), getApiHoster(), getPort(), getUrlDeploy(),
                URLEncodedUtils.format(qparams, "UTF-8"), null);
        project.log("Deploy url : " + uri.toString(), Project.MSG_DEBUG);
        HttpGet httpPost = new HttpGet(uri);
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = httpclient.execute(httpPost, responseHandler);
        project.log("Deploy response : " + responseBody, Project.MSG_DEBUG);

        deployResponse = deserialize(responseBody, DeployResponse.class);
    } catch (URISyntaxException | IOException e) {
        project.log(e.getMessage(), Project.MSG_ERR);
    }
    return deployResponse;
}

From source file:com.github.feribg.audiogetter.helpers.Utils.java

/**
 * Prepare a valid Youtube API request URI
 * @param query//from  ww w .jav a  2  s  . co m
 * @param pageToken
 * @return
 * @throws URISyntaxException
 */
public static URI getYoutubeSearchURI(String query, String pageToken) throws URISyntaxException {
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair("q", query));
    //if there is a specific page to load
    if (pageToken != null && pageToken.length() > 0) {
        qparams.add(new BasicNameValuePair("pageToken", pageToken));
    }
    qparams.add(new BasicNameValuePair("part", "snippet,id"));
    qparams.add(new BasicNameValuePair("maxResults", String.valueOf(Constants.Youtube.PER_PAGE)));
    qparams.add(new BasicNameValuePair("safeSearch", Constants.Youtube.SAFE_SEARCH));
    qparams.add(new BasicNameValuePair("type", Constants.Youtube.TYPE));
    qparams.add(new BasicNameValuePair("key", Constants.Youtube.API_TOKEN));
    return URIUtils.createURI(Constants.Youtube.API_SCHEME, Constants.Youtube.API_HOST, -1,
            Constants.Youtube.API_SEARCH, URLEncodedUtils.format(qparams, "UTF-8"), null);
}

From source file:com.healthcit.cacure.dao.CouchDBDao.java

private void batchWriteToDb(JSONArray docList, String host, int port, String dbName)
        throws IOException, URISyntaxException {
    if (docList == null || docList.size() < 1)
        return; // nothing to send

    JSONObject jObj = new JSONObject();
    jObj.put("docs", docList);

    String jsonStr = jObj.toString();
    URI uri = URIUtils.createURI("http", host, port, "/" + dbName + "/_bulk_docs", null, null);

    // Prepare a request object
    HttpPost httpPost = new HttpPost(uri);
    httpPost.setHeader("Content-Type", "application/json");
    StringEntity body = new StringEntity(jsonStr);
    httpPost.setEntity(body);/*  w  w w  .  ja va 2s  .  c  om*/

    String response = doHttp(httpPost);

}

From source file:org.carrot2.workbench.vis.FlashViewPage.java

/**
 * Construct a HTTP GET. //  w  w w  . j  av  a 2  s .co  m
 */
private String createGetURI(String uriString, Map<String, Object> customParams) {
    try {
        List<NameValuePair> pairs = Lists.newArrayList();
        for (Map.Entry<String, Object> e : customParams.entrySet()) {
            pairs.add(new BasicNameValuePair(e.getKey(), e.getValue().toString()));
        }

        URI uri = new URI(uriString);
        uri = URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(),
                URLEncodedUtils.format(pairs, "UTF-8"), null);

        return uri.toString();
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

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

/**
 * URI used to run a temporary (ad-hoc) view
 *///  w w w . ja va 2  s  . c  o  m
public static URI tempView(String host, int port, String dbName) throws URISyntaxException {
    return URIUtils.createURI("http", host, port, dbName + "/_temp_view", null, null);
}

From source file:iristk.speech.nuancecloud.NuanceCloudRecognizerListener.java

private void initRequest() {
    try {//from w  ww  . jav  a 2s  .c om
        speechQueue.reset();

        InputStream inputStream;
        String codec;

        if (!(audioFormat.getSampleRate() == 8000 || audioFormat.getSampleRate() == 16000)) {
            System.err.println("Error: NuanceCloudRecognizer must get 8 or 16 Khz audio, not "
                    + audioFormat.getSampleRate());
        }

        if (useSpeex) {
            encodedQueue.reset();
            JSpeexEnc encoder = new JSpeexEnc((int) audioFormat.getSampleRate());
            encoder.startEncoding(speechQueue, encodedQueue);
            inputStream = encodedQueue.getInputStream();
            codec = "audio/x-speex;rate=" + (int) audioFormat.getSampleRate();
        } else {
            inputStream = speechQueue.getInputStream();
            codec = "audio/x-wav;codec=pcm;bit=16;rate=" + (int) audioFormat.getSampleRate();
        }

        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("appId", license.getAppId()));
        qparams.add(new BasicNameValuePair("appKey", license.getAppKey()));
        qparams.add(new BasicNameValuePair("id", DEVICE_ID));
        URI uri = URIUtils.createURI("https", HOSTNAME, 443, SERVLET, URLEncodedUtils.format(qparams, "UTF-8"),
                null);
        final HttpPost httppost = new HttpPost(uri);
        httppost.addHeader("Content-Type", codec);
        httppost.addHeader("Content-Language", language);
        httppost.addHeader("Accept-Language", language);
        httppost.addHeader("Accept", RESULTS_FORMAT);
        httppost.addHeader("Accept-Topic", LM);
        if (nuanceAudioSource != null) {
            httppost.addHeader("X-Dictation-AudioSource", nuanceAudioSource.name());
        }
        if (cookie != null)
            httppost.addHeader("Cookie", cookie);

        InputStreamEntity reqEntity = new InputStreamEntity(inputStream, -1);
        reqEntity.setContentType(codec);

        httppost.setEntity(reqEntity);

        postThread = new PostThread(httppost);

    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

From source file:com.healthcit.cacure.dao.CouchDBDao.java

public JSONObject getFormByOwnerIdAndFormId(JSONArray key) throws IOException, URISyntaxException {
    String keyString = key.toString();
    String encodedURL = URLEncoder.encode(keyString, "UTF-8");
    String viewURL = constructViewURL("GetDocByOwnerAndForm");
    URI uri = URIUtils.createURI("http", host, port, viewURL, "key=" + encodedURL, null);
    HttpGet httpGet = new HttpGet(uri);
    String response = doHttp(httpGet);
    JSONObject json = JSONObject.fromObject(response);
    JSONArray objects = json.getJSONArray("rows");
    JSONObject form = null;/*  ww w.j  a v a 2  s .  c o m*/
    if (objects != null && objects.size() > 0) {
        JSONObject row = objects.getJSONObject(0);
        form = row.getJSONObject("value");
    }
    return form;
}

From source file:com.ai.alm.launcher.Launcher.java

void requestStop() throws URISyntaxException, IOException {
    try {/*w w  w  .  ja  va2s . co m*/
        URI uri = URIUtils.createURI("http", host, port, "jetty-shutdown", "secret=" + secret, null);
        new DefaultHttpClient().execute(new HttpPost(uri));
    } catch (Exception ignored) {
    }
}

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

/**
 * URI used to format a document through a "show" template
 *//* w  w  w .ja  v a  2  s.com*/
public static URI formatDoc(String host, int port, String dbName, String designDocName, String showName,
        String docId) throws URISyntaxException {
    String path = String.format("%s/_design/%s/_show/%s/%s", dbName, designDocName, showName, docId);
    return URIUtils.createURI("http", host, port, path, null, null);
}