Example usage for org.apache.http.client.utils URIBuilder toString

List of usage examples for org.apache.http.client.utils URIBuilder toString

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:com.thoughtworks.go.util.UrlUtil.java

public static String urlWithQuery(String oldUrl, String paramName, String paramValue)
        throws URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder(oldUrl);
    uriBuilder.addParameter(paramName, paramValue);
    return uriBuilder.toString();
}

From source file:com.github.tomakehurst.wiremock.common.UniqueFilenameGenerator.java

public static String generateIdFromUrl(final String prefix, final String id, final String url) {
    URIBuilder urlbuild = null;
    try {//w  w w. j  a va 2s .  c o  m
        urlbuild = new URIBuilder(url);
        urlbuild = urlbuild.removeQuery();
        return getRandomId(prefix, id, new URI(urlbuild.toString()));
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.glom.web.server.Utils.java

/** Build the URL for the service that will return the binary data for an image.
 * //from w  ww  .j  a v a 2  s .  co m
 * @param primaryKeyValue
 * @param field
 * @return
 */
public static String buildImageDataUrl(final String documentID, final String tableName, final String layoutName,
        final int[] path) {
    final URIBuilder uriBuilder = buildImageDataUrlStart(documentID, tableName);
    uriBuilder.setParameter("layout", layoutName);
    uriBuilder.setParameter("layoutpath", buildLayoutPath(path));
    return uriBuilder.toString();
}

From source file:org.finra.msl.client.MockAPI.java

/**
 * Register a template that is passed to the web-server where the it is
 * stored using the ID as the key. This is used later when setting up a mock
 * response./*  w  w w. j  a  v a  2  s  .  com*/
 * 
 * @param server
 *            => url of web-server.js running on node
 * @param port
 *            => port number of web-server.js running on node
 * @param template
 *            => the template that is to be registered for later use
 * @param id
 *            => key used to indicate which template is to be used when
 *            mocking a response
 * @return => returns the response
 * @throws Exception
 */
public static String registerTemplate(String server, int port, String template, String id) throws Exception {
    HttpPost post = null;
    JSONObject object = new JSONObject();

    URIBuilder builder = new URIBuilder();

    builder.setScheme("http").setHost(server).setPort(port).setPath("/mock/template");

    post = new HttpPost(builder.toString());
    object.put("template", template);
    object.put("id", id);

    post.setHeader("Content-Type", "application/json");
    post.setEntity(new StringEntity(object.toString()));

    HttpClient client = new DefaultHttpClient();
    HttpResponse resp = client.execute(post);

    if (resp.getStatusLine().getStatusCode() != 200) {
        throw new Exception("POST failed. Error code: " + resp.getStatusLine().getStatusCode());
    }
    return EntityUtils.toString(resp.getEntity());

}

From source file:org.glom.web.server.Utils.java

/** Build the URL for the service that will return the binary data for an image.
 * /*from w  w w.  j av a2s  .com*/
 * @param primaryKeyValue
 * @param field
 * @return
 */
public static String buildImageDataUrl(final TypedDataItem primaryKeyValue, final String documentID,
        final String tableName, final LayoutItemField field) {
    final URIBuilder uriBuilder = buildImageDataUrlStart(documentID, tableName);

    //TODO: Handle other types:
    if (primaryKeyValue != null) {
        uriBuilder.setParameter("value", Double.toString(primaryKeyValue.getNumber()));
    }

    uriBuilder.setParameter("field", field.getName());
    return uriBuilder.toString();
}

From source file:com.mxhero.plugin.cloudstorage.onedrive.api.OneDrive.java

/**
 * Business email.//w ww  .  j  a v a  2s .  com
 *
 * @param accessToken the access token
 * @return the string
 */
@SuppressWarnings("unchecked")
private static String businessEmail(String accessToken) {
    try {

        URIBuilder builder = new URIBuilder(ApiEnviroment.graphApiUrl.getValue() + "me");
        builder.addParameter("api-version", "1.6");
        HttpGet httpGet = new HttpGet(builder.toString());
        httpGet.setHeader("Authorization", "Bearer " + accessToken);

        HttpResponse response = HttpClientBuilder.create().build().execute(httpGet);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            Map<String, Object> responseObject = (Map<String, Object>) OneDrive.JACKSON
                    .readValue(EntityUtils.toString(response.getEntity()), Map.class);
            if (responseObject.containsKey("userPrincipalName")) {
                return (String) responseObject.get("userPrincipalName");
            } else {
                return (String) responseObject.get("mail");
            }
        }
        throw new RuntimeException(
                "error reading response with code " + response.getStatusLine().getStatusCode());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.finra.msl.client.MockAPI.java

/**
 * Method to set up parameters that will be ignored in the URL.
 * /*from  ww w.j a  v a2s .  co  m*/
 * @param server
 *            => url of web-server.js running on node
 * @param port
 *            => port number of web-server.js running on node
 * @param params => parameters that will be ignored in the app URL, type is string. 
 *                  For example,if we set ignore paramB, URL http://aa.bb.com/result?paramA=123&paramB=456 will be treated as http://aa.bb.com/result?paramA=123
 * 
 * @return String response
 **/
public static String setParamIgnored(String server, int port, String params) throws Exception {

    URIBuilder builder = new URIBuilder();
    builder.setScheme("http").setHost(server).setPort(port).setPath("/setIgnoreFlag");

    JSONObject object = new JSONObject();
    object.put("requestPath", params);

    HttpPost get = new HttpPost(builder.toString());
    get.setHeader("Content-Type", "application/json");
    get.setEntity(new StringEntity(object.toString()));

    HttpClient client = new DefaultHttpClient();
    HttpResponse resp = client.execute(get);

    if (resp.getStatusLine().getStatusCode() != 200) {
        throw new Exception("GET failed. Error code: " + resp.getStatusLine().getStatusCode());
    }

    return EntityUtils.toString(resp.getEntity());
}

From source file:org.finra.msl.client.MockAPI.java

/**
 * This allows for the removal of all registered mocks once they are no longer in
 * use./*  www.j a v  a 2 s. c om*/
 * 
 * 
 * @param server
 *            => url of web-server.js running on node
 * @param port
 *            => port number of web-server.js running on node
 * @return
 * @throws Exception
 */
public static String unRegisterMock(String server, int port) throws Exception {

    URIBuilder builder = new URIBuilder();

    builder.setScheme("http").setHost(server).setPort(port).setPath("/unregisterMock");

    JSONObject object = new JSONObject();
    object.put("requestPath", "");

    HttpPost get = new HttpPost(builder.toString());
    get.setHeader("Content-Type", "application/json");
    get.setEntity(new StringEntity(object.toString()));

    HttpClient client = new DefaultHttpClient();
    HttpResponse resp = client.execute(get);

    if (resp.getStatusLine().getStatusCode() != 200) {
        throw new Exception("GET failed. Error code: " + resp.getStatusLine().getStatusCode());
    }

    return EntityUtils.toString(resp.getEntity());

}

From source file:alluxio.cli.LogLevel.java

private static void setLogLevel(final TargetInfo targetInfo, String logName, String level) throws IOException {
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme("http");
    uriBuilder.setHost(targetInfo.getHost());
    uriBuilder.setPort(targetInfo.getPort());
    uriBuilder.setPath(Constants.REST_API_PREFIX + "/" + targetInfo.getRole() + "/" + LOG_LEVEL);
    uriBuilder.addParameter(LOG_NAME_OPTION_NAME, logName);
    if (level != null) {
        uriBuilder.addParameter(LEVEL_OPTION_NAME, level);
    }//from   w  w w . j  ava 2 s  .com
    HttpUtils.post(uriBuilder.toString(), 5000, new HttpUtils.IProcessInputStream() {
        @Override
        public void process(InputStream inputStream) throws IOException {
            ObjectMapper mapper = new ObjectMapper();
            LogInfo logInfo = mapper.readValue(inputStream, LogInfo.class);
            System.out.println(targetInfo.toString() + logInfo.toString());
        }
    });
}

From source file:org.finra.msl.client.MockAPI.java

/**
 * Method to register intercept XHR. Once you register, whenever
 * server receives a request matching the registered requestPath, it will
 * intercept and store for later retrieval
 * /*from www. j  a  v a2  s . c  o  m*/
 * @param server
 *            => url of web-server.js running on node
 * @param port
 *            => port number of web-server.js running on node
 * @param requestPath
 *            => path which you want to mock a fake response with
 * 
 * @return String response
 **/
public static String setInterceptXHR(String server, int port, String requestPath) throws Exception {
    URIBuilder builder = new URIBuilder();
    builder.setScheme("http").setHost(server).setPort(port).setPath("/mock/interceptxhr");

    JSONObject object = new JSONObject();
    object.put("requestPath", requestPath);

    HttpPost post = new HttpPost(builder.toString());
    post.setHeader("Content-Type", "application/json");
    post.setEntity(new StringEntity(object.toString()));

    HttpClient client = new DefaultHttpClient();
    HttpResponse resp = client.execute(post);

    if (resp.getStatusLine().getStatusCode() != 200) {
        throw new Exception("POST failed. Error code: " + resp.getStatusLine().getStatusCode());
    }
    return EntityUtils.toString(resp.getEntity());
}