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:org.finra.msl.client.MockAPI.java

/**
 * This allows for the removal of a registered mock once it is no longer in
 * use./*from w  w  w  . j a  v  a  2s  .  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
 * @throws Exception
 */
public static String unRegisterMock(String server, int port, String requestPath) throws Exception {

    URIBuilder builder = new URIBuilder();

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

    JSONObject object = new JSONObject();
    object.put("requestPath", 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:de.ii.xtraplatform.ogc.api.CSW.java

public static String cleanUrl(String url) {
    try {/*from  w  w  w  .j a  v  a2  s .  com*/
        URI inUri = new URI(url.trim());
        URIBuilder outUri = new URIBuilder(inUri).removeQuery();

        if (inUri.getQuery() != null && !inUri.getQuery().isEmpty()) {
            for (String inParam : inUri.getQuery().split("&")) {
                String[] param = inParam.split("=");
                if (!CSW.hasKVPKey(param[0].toUpperCase())) {
                    outUri.addParameter(param[0], param[1]);
                }
            }
        }

        return outUri.toString();
    } catch (URISyntaxException ex) {
        return url;
    }
}

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

/**
 * Method to retrieve intercepted XHRs. Use in conjunction with
 * setInterceptXHR()/*from  w  w w .ja  va 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 requestPath
 *            => path which you want to mock a fake response with
 * 
 * @return list of intercepted XHR objects
 */
public static XHR[] getInterceptedXHR(String server, int port, String requestPath) throws Exception {
    URIBuilder builder = new URIBuilder();

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

    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("GET failed. Error code: " + resp.getStatusLine().getStatusCode());
    }

    // Parse JSON
    JSONObject jsonObj = (JSONObject) JSONValue.parse(EntityUtils.toString(resp.getEntity()));
    XHR[] interceptedXHRs = new XHR[jsonObj.keySet().size()];
    for (String key : jsonObj.keySet()) {
        int index = Integer.parseInt(key.split("_")[1]);
        JSONObject xhrDataObj = (JSONObject) jsonObj.get(key);
        JSONObject xhrObj = (JSONObject) xhrDataObj.get("xhr");
        Object postObj = xhrDataObj.get("post");

        // Get URL and method
        String urlStr = xhrObj.get("url").toString();
        String method = xhrObj.get("method").toString();

        // Post body
        String body = "";
        if (postObj != null) {
            body = postObj.toString();
        }

        XHR xhr = new XHR(urlStr, method, body);
        interceptedXHRs[index - 1] = xhr;
    }

    return interceptedXHRs;
}

From source file:de.ii.xtraplatform.ogc.api.WFS.java

public static String cleanUrl(String url) {
    try {/*from   w w w.  ja v  a2 s. co  m*/
        URI inUri = new URI(url.trim());
        URIBuilder outUri = new URIBuilder(inUri).removeQuery();

        if (inUri.getQuery() != null && !inUri.getQuery().isEmpty()) {
            for (String inParam : inUri.getQuery().split("&")) {
                String[] param = inParam.split("=");
                if (!WFS.hasKVPKey(param[0].toUpperCase())) {
                    if (param.length >= 2)
                        outUri.addParameter(param[0], param[1]);
                    else
                        System.out.println("SINGLE " + param[0]);
                }
            }
        }

        return outUri.toString();
    } catch (URISyntaxException ex) {
        return url;
    }
}

From source file:io.kamax.mxisd.controller.profile.v1.ProfileController.java

private String resolveProxyUrl(HttpServletRequest req) {
    URI target = URI.create(req.getRequestURL().toString()
            + (Objects.isNull(req.getQueryString()) ? "" : "?" + req.getQueryString()));
    URIBuilder builder = dns.transform(target);
    String urlToLogin = builder.toString();
    log.info("Proxy resolution: {} to {}", target.toString(), urlToLogin);
    return urlToLogin;
}

From source file:org.activiti.service.engine.FormInstanceService.java

public JsonNode getFormInstances(ServerConfig serverConfig, ObjectNode objectNode) {

    JsonNode resultNode = null;/*  w  w  w.  j a  v  a 2s . com*/

    try {
        URIBuilder builder = clientUtil.createUriBuilder("/query/form-instances");
        HttpPost post = clientUtil.createPost(builder.toString(), serverConfig);
        post.setEntity(clientUtil.createStringEntity(objectNode.toString()));

        resultNode = clientUtil.executeRequest(post, serverConfig);
    } catch (Exception ex) {
        throw new ActivitiServiceException(ex.getMessage(), ex);
    }

    return resultNode;
}

From source file:org.restcomm.connect.java.sdk.http.Request.java

public void addGetParameters(String a, String b) throws MalformedURLException, URISyntaxException {

    URIBuilder urib = new URIBuilder(Url);
    urib.addParameter(a, b);/*from  w w w  .  j a  va2s  . c o  m*/
    urib.build();
    Url = new URL(urib.toString()).toString();
}

From source file:org.flowable.admin.service.engine.FormInstanceService.java

public JsonNode getFormInstances(ServerConfig serverConfig, ObjectNode objectNode) {

    JsonNode resultNode = null;// ww  w.j  a  va 2s.c  o  m

    try {
        URIBuilder builder = clientUtil.createUriBuilder("query/form-instances");
        HttpPost post = clientUtil.createPost(builder.toString(), serverConfig);
        post.setEntity(clientUtil.createStringEntity(objectNode.toString()));

        resultNode = clientUtil.executeRequest(post, serverConfig);
    } catch (Exception ex) {
        throw new FlowableServiceException(ex.getMessage(), ex);
    }

    return resultNode;
}

From source file:com.collective.celos.JettyServer.java

private void startServer() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("WEB-INF");
    URIBuilder uriBuilder = new URIBuilder(url.toURI());
    uriBuilder.setPath(Paths.get(url.getPath()).getParent().toString());

    context = new WebAppContext(uriBuilder.toString() + "/", "/");
    context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");

    context.setExtractWAR(false);/*from www.j  av a 2 s  .c  o m*/

    server.setHandler(context);
    server.start();
}

From source file:org.flowable.admin.service.engine.FormInstanceService.java

public JsonNode getFormInstanceFormFieldValues(ServerConfig serverConfig, String formInstanceId) {

    ObjectNode returnNode = null;//from   w  w w. jav  a2s .  c om

    try {
        returnNode = objectMapper.createObjectNode();

        ObjectNode requestNode = objectMapper.createObjectNode();
        requestNode.put("formInstanceId", formInstanceId);

        URIBuilder builder = clientUtil.createUriBuilder("form/form-instance-model");
        HttpPost post = clientUtil.createPost(builder.toString(), serverConfig);
        post.setEntity(clientUtil.createStringEntity(requestNode.toString()));

        JsonNode resultNode = clientUtil.executeRequest(post, serverConfig);

        ArrayNode formFieldValues = objectMapper.createArrayNode();

        if (resultNode != null && resultNode.has("fields") && resultNode.get("fields").isArray()) {

            ArrayNode fieldsNode = (ArrayNode) resultNode.get("fields");
            for (JsonNode fieldNode : fieldsNode) {

                ObjectNode formFieldValue = objectMapper.createObjectNode();

                formFieldValue.set("id", fieldNode.get("id"));
                formFieldValue.set("name", fieldNode.get("name"));
                formFieldValue.set("type", fieldNode.get("type"));
                formFieldValue.set("value", fieldNode.get("value"));

                formFieldValues.add(formFieldValue);
            }
        }

        returnNode.put("size", formFieldValues.size());
        returnNode.put("total", formFieldValues.size());
        returnNode.set("data", formFieldValues);
    } catch (Exception ex) {
        throw new FlowableServiceException(ex.getMessage(), ex);
    }

    return returnNode;
}