当前位置: 首页>>代码示例>>Java>>正文


Java URIBuilder.build方法代码示例

本文整理汇总了Java中org.apache.http.client.utils.URIBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java URIBuilder.build方法的具体用法?Java URIBuilder.build怎么用?Java URIBuilder.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.client.utils.URIBuilder的用法示例。


在下文中一共展示了URIBuilder.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testbrokenLink

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
@Test
public void testbrokenLink() throws IOException, URISyntaxException {

    JSONObject object = new JSONObject();
    object.put("key", "sprSCKKWf8xUeXxEo6Bv0lE1sSjWRDkO");
    object.put("marketName", "eoemarket");
    object.put("count", 1);
    JSONArray data = new JSONArray();
    JSONObject o = new JSONObject();
    o.put("id", -1);
    o.put("link", "http://testsssssss");
    o.put("statusCode", 404);
    data.add(o);
    object.put("data", data);

    String test = "eyJjb3VudCI6IDEwLCAibWFya2V0TmFtZSI6ICJBcHBDaGluYSIsICJkYXRhIjogW3sibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmdvb2dsZS5hbmRyb2lkLmFwcHMubWFwcyIsICJpZCI6IDEsICJzdGF0dXNDb2RlIjogNDA0fSwgeyJsaW5rIjogImh0dHA6Ly93d3cuYXBwY2hpbmEuY29tL2FwcC9jb20ud2VhdGhlci5XZWF0aGVyIiwgImlkIjogMiwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5zdHlsZW0ud2FsbHBhcGVycyIsICJpZCI6IDQsICJzdGF0dXNDb2RlIjogNDA0fSwgeyJsaW5rIjogImh0dHA6Ly93d3cuYXBwY2hpbmEuY29tL2FwcC9jb20uc2hhemFtLmVuY29yZS5hbmRyb2lkIiwgImlkIjogNSwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5yaW5nZHJvaWQiLCAiaWQiOiA2LCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLnAxLmNob21wc21zIiwgImlkIjogNywgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5oYW5kY2VudC5uZXh0c21zIiwgImlkIjogOCwgInN0YXR1c0NvZGUiOiA0MDR9LCB7ImxpbmsiOiAiaHR0cDovL3d3dy5hcHBjaGluYS5jb20vYXBwL2NvbS5mYWNlYm9vay5rYXRhbmEiLCAiaWQiOiA5LCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmNvZGUuaS5tdXNpYyIsICJpZCI6IDEwLCAic3RhdHVzQ29kZSI6IDQwNH0sIHsibGluayI6ICJodHRwOi8vd3d3LmFwcGNoaW5hLmNvbS9hcHAvY29tLmJpZ2d1LnNob3BzYXZ2eSIsICJpZCI6IDExLCAic3RhdHVzQ29kZSI6IDQwNH1dLCAia2V5IjogImpqRzhMa0MzTUh5RjlYY3NWS2g2Rkh4bXRMQ05ZdE14In0=";
    Reader input = new StringReader(object.toJSONString());
    byte[] binaryData = IOUtils.toByteArray(input, "UTF-8");
    String encodeBase64 = Base64.encodeBase64String(binaryData);
    System.out.println(encodeBase64);

    String url = "http://localhost:9080/sjk-market-admin/market/brokenLink.d";
    url = "http://app.sjk.ijinshan.com/market/brokenLink.d";
    URIBuilder builder = new URIBuilder(url);
    builder.setParameter("c", test);
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(builder.build());
    HttpResponse response = httpclient.execute(httpPost);
    logger.debug("URI: {} , {}", url, response.getStatusLine());

    HttpEntity entity = response.getEntity();
    InputStream is = entity.getContent();
    // be convinient to debug
    String rspJSON = IOUtils.toString(is, "UTF-8");
    System.out.println(rspJSON);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:37,代码来源:ControllerTest.java

示例2: createPutRequest

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
/**
 * 
 * @param payload
 * @return
 */
protected HttpPut createPutRequest(final Object value, final String collection) {

    try {
        logger.debug("received value {}, and collection {}", value, collection);
        final Map<?, ?> valueMap = new LinkedHashMap<>((Map<?,?>)value);
        final Object url = valueMap.remove(URL);
        final URIBuilder uriBuilder = getURIBuilder(null == url ? UUID.randomUUID().toString() : url.toString(), collection);
        final String jsonString = MAPPER.writeValueAsString(valueMap);
        final HttpPut request = new HttpPut(uriBuilder.build());
        final StringEntity params = new StringEntity(jsonString, "UTF-8");
        params.setContentType(DEFAULT_CONTENT_TYPE.toString());
        request.setEntity(params);
        return request;
    } catch (URISyntaxException | JsonProcessingException | MalformedURLException e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    } 
}
 
开发者ID:sanjuthomas,项目名称:kafka-connect-marklogic,代码行数:24,代码来源:MarkLogicWriter.java

示例3: buildUri

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
private static URI buildUri(String pathPrefix, String path, Map<String, String> params) {
    Objects.requireNonNull(path, "path must not be null");
    try {
        String fullPath;
        if (pathPrefix != null) {
            if (path.startsWith("/")) {
                fullPath = pathPrefix + path;
            } else {
                fullPath = pathPrefix + "/" + path;
            }
        } else {
            fullPath = path;
        }

        URIBuilder uriBuilder = new URIBuilder(fullPath);
        for (Map.Entry<String, String> param : params.entrySet()) {
            uriBuilder.addParameter(param.getKey(), param.getValue());
        }
        return uriBuilder.build();
    } catch(URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:RestClient.java

示例4: buildUrl

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
private URI buildUrl(String subPath, List<NameValuePair> queryParams)
{
    URIBuilder uB= new URIBuilder()
    .setScheme(serverConfig.isUseHTTPS() ? "https" : "http")
    .setHost(serverConfig.getServerName())
    .setUserInfo(serverConfig.getUserName(), serverConfig.getPassword())
    .setPath(subPath);
    if (queryParams != null)
    {
        uB.addParameters(queryParams);
    }
    try {
        return uB.build();
    } catch (URISyntaxException e) {
        throw new NextcloudApiException(e);
    }
}
 
开发者ID:a-schild,项目名称:nextcloud-java-api,代码行数:18,代码来源:ConnectorCommon.java

示例5: createTreeRequest

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
private HttpRequestBase createTreeRequest(Long parentId) {
    try {
        URIBuilder builder = new URIBuilder(serverParameters.getServerUrl()
                + serverParameters.getProjectTreeUrl());
        builder.addParameter("parentId", String.valueOf(parentId));

        HttpGet get = new HttpGet(builder.build());
        setDefaultHeader(get);
        if (isSecure()) {
            addAuthorizationToRequest(get);
        }
        return get;
    } catch (URISyntaxException e) {
        throw new ApplicationException(e.getMessage(), e);
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:17,代码来源:DatasetListHandler.java

示例6: testbrokenLink

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
@Test
public void testbrokenLink() throws IOException, URISyntaxException {

    JSONObject object = new JSONObject();
    object.put("key", "sprSCKKWf8xUeXxEo6Bv0lE1sSjWRDkO");
    object.put("marketName", "eoemarket");
    object.put("count", 1);
    JSONArray data = new JSONArray();
    JSONObject o = new JSONObject();
    o.put("id", -1);
    o.put("link", "http://testsssssss");
    o.put("statusCode", 404);
    data.add(o);
    object.put("data", data);

    Reader input = new StringReader(object.toJSONString());
    byte[] binaryData = IOUtils.toByteArray(input, "UTF-8");
    String encodeBase64 = Base64.encodeBase64String(binaryData);

    String url = "http://localhost:8080/sjk-market/market/brokenLink.d";
    url = "http://app-t.sjk.ijinshan.com/market/brokenLink.d";
    URIBuilder builder = new URIBuilder(url);
    builder.setParameter("c", encodeBase64);
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(builder.build());
    HttpResponse response = httpclient.execute(httpPost);
    logger.debug("URI: {} , {}", url, response.getStatusLine());

    HttpEntity entity = response.getEntity();
    InputStream is = entity.getContent();
    // be convinient to debug
    String rspJSON = IOUtils.toString(is, "UTF-8");
    System.out.println(rspJSON);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:35,代码来源:ControllerTest.java

示例7: runCommand

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
@Override
public int runCommand() {
    try {
        String url = serverParameters.getServerUrl() + getRequestUrl();
        URIBuilder builder = new URIBuilder(String.format(url, datasetId));
        if (parentId != null) {
            builder.addParameter("parentId", String.valueOf(parentId));
        }
        HttpPut put = new HttpPut(builder.build());
        setDefaultHeader(put);
        if (isSecure()) {
            addAuthorizationToRequest(put);
        }
        RequestManager.executeRequest(put);
    } catch (URISyntaxException e) {
        throw new ApplicationException(e.getMessage(), e);
    }
    return 0;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:20,代码来源:DatasetMovingHandler.java

示例8: buildUri

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
URI buildUri(URI baseUri, Map<String, String> params) {

            String schemaAfterReplacements = replaceParamsInTemplate(schema, params);

            URIBuilder builder = new URIBuilder();
            builder.setScheme(baseUri.getScheme());
            builder.setHost(baseUri.getHost());
            builder.setPort(baseUri.getPort());
            String path = baseUri.normalize().getPath() + schemaAfterReplacements;
            builder.setPath(path.replaceAll("//", "/")); // Replace double slashes

            for (String templateParamKey : templateParams.keySet()) {
                String templateParamKeyAfterReplacements = replaceParamsInTemplate(templateParamKey, params);
                String templateParamValueAfterReplacements = replaceParamsInTemplate(templateParams.get(templateParamKey), params);
                builder.setParameter(templateParamKeyAfterReplacements, templateParamValueAfterReplacements);
            }


            URI result;
            try {
                result = builder.build();
            } catch (URISyntaxException e) {
                throw new WebmateApiClientException("Could not build valid API URL", e);
            }
            return result;
        }
 
开发者ID:webmate-io,项目名称:webmate-sdk-java,代码行数:27,代码来源:WebmateApiClient.java

示例9: testListMarkert

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
@Test
public void testListMarkert() throws URISyntaxException, ClientProtocolException, IOException {
    String url = "http://127.0.0.1:8080/sjk-market-admin/market/list.json";
    URIBuilder urlb = new URIBuilder(url);
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(urlb.build());
    HttpResponse response = httpClient.execute(httpget);
    logger.debug("URL:{}\n{}\n{}", url, response.getStatusLine(), response.getEntity());
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:10,代码来源:MarketControllerTest.java

示例10: testEdit

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
@Test
public void testEdit() throws URISyntaxException, ClientProtocolException, IOException {
    String url = "http://127.0.0.1:8080/sjk-market-appsvr/app/api/cdn/tagapp/tagtopic/0/9.json";
    URIBuilder urlb = new URIBuilder(url);
    // 参数
    urlb.setParameter("tabId", "0");
    urlb.setParameter("tagId", "9");
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(urlb.build());
    HttpResponse response = httpClient.execute(httpGet);
    logger.debug("URL:{}\n{}\n{}", url, response.getStatusLine(), response.getEntity());
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:13,代码来源:TestTagAppController.java

示例11: createTranslationURI

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
private URI createTranslationURI(String query) throws URISyntaxException {
    URIBuilder builder = new URIBuilder();
    builder.setScheme("http")
            .setHost(HOST)
            .setPath(PATH)
            .addParameter(PARAM_KEY_FROM, KEY_FROM)
            .addParameter(PARAM_KEY, KEY)
            .addParameter(PARAM_TYPE, TYPE)
            .addParameter(PARAM_VERSION, VERSION)
            .addParameter(PARAM_DOC_TYPE, DOC_TYPE)
            .addParameter(PARAM_CALL_BACK, CALL_BACK)
            .addParameter(PARAM_QUERY, query);
    return builder.build();
}
 
开发者ID:BolexLiu,项目名称:ReciteWords,代码行数:15,代码来源:RequestRunnable.java

示例12: httpGetRequest

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
public static String httpGetRequest(String url, Map<String, Object> params) throws URISyntaxException {
    URIBuilder ub = new URIBuilder();
    ub.setPath(url);

    ArrayList<NameValuePair> pairs = covertParams2NVPS(params);
    ub.setParameters(pairs);

    HttpGet httpGet = new HttpGet(ub.build());
    return getResult(httpGet);
}
 
开发者ID:wolfboys,项目名称:opencron,代码行数:11,代码来源:HttpClientUtils.java

示例13: buildURIByConfig

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
/**
 * 创建URI
 *
 * @return
 */
public URI buildURIByConfig() throws URISyntaxException {
    URIBuilder builder = new URIBuilder();
    builder.setHost(config.getHost());
    builder.setPort(config.getPort());
    builder.setPath(config.getPath());
    builder.setScheme(config.getProtocol());
    builder.setCharset(Charset.forName(config.getCharset()));
    return builder.build();
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:15,代码来源:AbstractHttpSmsReceiver.java

示例14: getClientPathWithAccessToken

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
protected URI getClientPathWithAccessToken(String action) {
    try {
        URIBuilder builder = getClientPathBuilder(action);
        builder.setParameter("access_token", getAccessTokenOrThrow());
        return builder.build();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:kamax-io,项目名称:matrix-java-sdk,代码行数:10,代码来源:AMatrixHttpClient.java

示例15: AnalyzeImage

import org.apache.http.client.utils.URIBuilder; //导入方法依赖的package包/类
/**
 * Encapsulates the Microsoft Cognitive Services REST API call to analyze an image.
 * @param imageUrl: The string URL of the image to analyze.
 * @return: A JSONObject describing the image, or null if a runtime error occurs.
 */
private JSONObject AnalyzeImage(String imageUrl) {
    try (CloseableHttpClient httpclient = HttpClientBuilder.create().build())
    {
        // Create the URI to access the REST API call for Analyze Image.
        String uriString = uriBasePreRegion + 
                String.valueOf(subscriptionRegionComboBox.getSelectedItem()) + 
                uriBasePostRegion + uriBaseAnalyze;
        URIBuilder builder = new URIBuilder(uriString);

        // Request parameters. All of them are optional.
        builder.setParameter("visualFeatures", "Categories,Description,Color,Adult");
        builder.setParameter("language", "en");

        // Prepare the URI for the REST API call.
        URI uri = builder.build();
        HttpPost request = new HttpPost(uri);

        // Request headers.
        request.setHeader("Content-Type", "application/json");
        request.setHeader("Ocp-Apim-Subscription-Key", subscriptionKeyTextField.getText());

        // Request body.
        StringEntity reqEntity = new StringEntity("{\"url\":\"" + imageUrl + "\"}");
        request.setEntity(reqEntity);

        // Execute the REST API call and get the response entity.
        HttpResponse response = httpclient.execute(request);
        HttpEntity entity = response.getEntity();

        // If we got a response, parse it and display it.
        if (entity != null)
        {
            // Return the JSONObject.
            String jsonString = EntityUtils.toString(entity);
            return new JSONObject(jsonString);
        } else {
            // No response. Return null.
            return null;
        }
    }
    catch (Exception e)
    {
        // An error occurred. Print error message and return null.
        System.out.println(e.getMessage());
        return null;
    }
}
 
开发者ID:Azure-Samples,项目名称:cognitive-services-java-computer-vision-tutorial,代码行数:53,代码来源:MainFrame.java


注:本文中的org.apache.http.client.utils.URIBuilder.build方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。