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


Java URIBuilder类代码示例

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


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

示例1: client

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

    CloseableHttpClient httpclient = HttpClients.createDefault();

    URI uri = new URIBuilder()
            .setScheme("http")
            .setHost("www.google.com")
            .setPath("/search")
            .setParameter("q", "httpclient")
            .setParameter("btnG", "Google Search")
            .setParameter("aq", "f")
            .setParameter("oq", "")
            .build();
    HttpGet httpget = new HttpGet(uri);
    CloseableHttpResponse response = httpclient.execute(httpget);
}
 
开发者ID:daishicheng,项目名称:outcomes,代码行数:18,代码来源:TestHttpCore.java

示例2: simplePost

import org.apache.http.client.utils.URIBuilder; //导入依赖的package包/类
/**
 * Simple Http Post.
 *
 * @param path the path
 * @param payload the payload
 * @return the closeable http response
 * @throws URISyntaxException the URI syntax exception
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws MininetException the MininetException
 */
public CloseableHttpResponse simplePost(String path, String payload) 
    throws URISyntaxException, IOException, MininetException {
  URI uri = new URIBuilder()
      .setScheme("http")
      .setHost(mininetServerIP.toString())
      .setPort(mininetServerPort.getPort())
      .setPath(path)
      .build();
  CloseableHttpClient client = HttpClientBuilder.create().build();
  RequestConfig config = RequestConfig
      .custom()
      .setConnectTimeout(CONNECTION_TIMEOUT_MS)
      .setConnectionRequestTimeout(CONNECTION_TIMEOUT_MS)
      .setSocketTimeout(CONNECTION_TIMEOUT_MS)
      .build();
  HttpPost request = new HttpPost(uri);
  request.setConfig(config);
  request.addHeader("Content-Type", "application/json");
  request.setEntity(new StringEntity(payload));
  CloseableHttpResponse response = client.execute(request);
  if (response.getStatusLine().getStatusCode() >= 300) {
    throw new MininetException(String.format("failure - received a %d for %s.", 
        response.getStatusLine().getStatusCode(), request.getURI().toString()));
  }
  return response;
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:37,代码来源:Mininet.java

示例3: main

import org.apache.http.client.utils.URIBuilder; //导入依赖的package包/类
public static void main(String[] args) throws IOException, URISyntaxException {
	ObjectMapper mapper = new ObjectMapper();
	try (CloseableHttpClient client =
				 HttpClientBuilder.create().useSystemProperties().build()) {
		URI uri = new URIBuilder("http://api.geonames.org/searchJSON")
				.addParameter("q", "kabupaten garut")
				.addParameter("username", "ceefour")
				.build();
		HttpGet getRequest = new HttpGet(uri);
		try (CloseableHttpResponse resp = client.execute(getRequest)) {
			String body = IOUtils.toString(resp.getEntity().getContent(),
					StandardCharsets.UTF_8);
			JsonNode bodyNode = mapper.readTree(body);
			LOG.info("Status: {}", resp.getStatusLine());
			LOG.info("Headers: {}", resp.getAllHeaders());
			LOG.info("Body: {}", body);
			LOG.info("Body (JsonNode): {}", bodyNode);
			for (JsonNode child : bodyNode.get("geonames")) {
				LOG.info("Place: {} ({}, {})", child.get("toponymName"), child.get("lat"), child.get("lng"));
			}
		}
	}
}
 
开发者ID:ceefour,项目名称:java-web-services-training,代码行数:24,代码来源:Jws1042Application.java

示例4: buildAPICall

import org.apache.http.client.utils.URIBuilder; //导入依赖的package包/类
public static String buildAPICall(APICall query, Map<String, String> parameters) throws Exception
{
	if(query != null && StringUtils.isNotBlank(query.getBaseURL()))
	{
		logger.debug("APICall Base URL: " + query.getBaseURL());
		URIBuilder builder = new URIBuilder(query.getBaseURL());
		if(parameters != null && !parameters.isEmpty() && query.HasParameters())
		{
			for (Map.Entry<String, String> entry : parameters.entrySet())
			{
			    String key = entry.getKey();
			    if(StringUtils.isNotBlank(key) && query.getParameters().contains(key))
			    {
					String value = entry.getValue();
					builder.addParameter(key, value);
					logger.debug("Added Parameter: key=" + key + ", value=" + value);
			    }
			}
		}
		
		return builder.build().toString();
	}
	return null;
}
 
开发者ID:scriptkittie,项目名称:bandcamp-api,代码行数:25,代码来源:ConfigUtil.java

示例5: getPublishAddress

import org.apache.http.client.utils.URIBuilder; //导入依赖的package包/类
/**
 * 对于配置为0.0.0.0的地址,通过查询网卡地址,转换为实际监听的地址。
 */
public static String getPublishAddress(String schema, String address) {
  if (address == null) {
    return address;
  }

  try {
    URI originalURI = new URI(schema + "://" + address);
    IpPort ipPort = NetUtils.parseIpPort(originalURI.getAuthority());
    if (ipPort == null) {
      LOGGER.warn("address {} not valid.", address);
      return null;
    }

    IpPort publishIpPort = genPublishIpPort(schema, ipPort);
    URIBuilder builder = new URIBuilder(originalURI);
    return builder.setHost(publishIpPort.getHostOrIp()).setPort(publishIpPort.getPort()).build().toString();
  } catch (URISyntaxException e) {
    LOGGER.warn("address {} not valid.", address);
    return null;
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:25,代码来源:RegistryUtils.java

示例6: sendPut

import org.apache.http.client.utils.URIBuilder; //导入依赖的package包/类
private JsonObject sendPut(URIBuilder target, JsonObject payload) {
    try {
        if (!target.getScheme().equals("matrix")) {
            throw new IllegalArgumentException("Scheme can only be matrix");
        }

        String domain = target.getHost();
        target.setScheme("https");
        IRemoteAddress addr = resolver.resolve(target.getHost());
        target.setHost(addr.getHost());
        target.setPort(addr.getPort());

        return sendPut(domain, target.build(), payload);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:kamax-io,项目名称:mxhsd,代码行数:18,代码来源:HttpFederationClient.java

示例7: 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

示例8: getProcessState

import org.apache.http.client.utils.URIBuilder; //导入依赖的package包/类
@Async
public Future<ProcessStateDTO> getProcessState(final Long piId) throws URISyntaxException {
  final CompletableFuture<ProcessStateDTO> future = new CompletableFuture<>();

  final URIBuilder uri =
      new URIBuilder(gatewayConfig.getProcessEngineAddress()).setPath("processes/state/" + piId);

  final ListenableFuture<ResponseEntity<ProcessStateDTO>> responseFuture =
      createRequest(uri, HttpMethod.GET, null, ProcessStateDTO.class, null);

  responseFuture.addCallback(result -> {
    final List<UserContainer> container = Lists.newArrayList(result.getBody().getSubjects());
    getUser(container);
    future.complete(result.getBody());
  }, error -> {
    future.completeExceptionally(error);
  });

  return future;
}
 
开发者ID:stefanstaniAIM,项目名称:IPPR2016,代码行数:21,代码来源:ProcessEngineCallerImpl.java

示例9: 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-admin/admin/catalogconvertor/edit.json";
    URIBuilder urlb = new URIBuilder(url);

    // 参数
    urlb.setParameter("id", "1");
    urlb.setParameter("marketName", "eoemarket");
    urlb.setParameter("catalog", "1");
    urlb.setParameter("subCatalog", "15");
    urlb.setParameter("subCatalogName", "系统工具1");
    urlb.setParameter("targetCatalog", "1");
    urlb.setParameter("targetSubCatalog", "14");

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(urlb.build());
    HttpResponse response = httpClient.execute(httpPost);
    logger.debug("URL:{}\n{}\n{}", url, response.getStatusLine(), response.getEntity());
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:20,代码来源:CatalogConvertorControllerTest.java

示例10: loadFileByBioID

import org.apache.http.client.utils.URIBuilder; //导入依赖的package包/类
private BiologicalDataItem loadFileByBioID(String id) {
    try {
        URI uri = new URIBuilder(serverParameters.getServerUrl() + serverParameters.getFileFindUrl())
                .addParameter("id", id)
                .build();
        HttpGet get = new HttpGet(uri);
        setDefaultHeader(get);
        String result = RequestManager.executeRequest(get);
        ResponseResult<BiologicalDataItem> responseResult = getMapper().readValue(result,
                getMapper().getTypeFactory().constructParametrizedType(ResponseResult.class, ResponseResult.class,
                        BiologicalDataItem.class));
        if (responseResult == null || responseResult.getPayload() == null) {
            throw new ApplicationException("Failed to find a file by Bio item ID: " + id + ".");
        }
        return responseResult.getPayload();
    } catch (IOException | URISyntaxException e) {
        throw new ApplicationException("", e);
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:20,代码来源:AbstractHTTPCommandHandler.java

示例11: runCommand

import org.apache.http.client.utils.URIBuilder; //导入依赖的package包/类
/**
 * Performs a dataset registration request to NGB server and prints registration result to
 * StdOut if it is specified by the command line options
 * @return 0 if request completed successfully
 */
@Override public int runCommand() {
    try {
        URIBuilder builder = new URIBuilder(serverParameters.getServerUrl() + getRequestUrl());
        if (parentId != null) {
            builder.addParameter("parentId", String.valueOf(parentId));
        }
        HttpPost post = new HttpPost(builder.build());
        setDefaultHeader(post);
        if (isSecure()) {
            addAuthorizationToRequest(post);
        }
        RegistrationRequest registration = new RegistrationRequest();
        registration.setName(name);
        registration.setItems(items);
        String result = getPostResult(registration, post);
        checkAndPrintDatasetResult(result, printJson, printTable);
    } catch (URISyntaxException e) {
        throw new ApplicationException(e.getMessage(), e);
    }
    return 0;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:27,代码来源:DatasetRegistrationHandler.java

示例12: transform

import org.apache.http.client.utils.URIBuilder; //导入依赖的package包/类
public URIBuilder transform(URI initial) {
    URIBuilder builder = new URIBuilder(initial);
    Entry mapping = mappings.get(initial.getHost());
    if (mapping == null) {
        return builder;
    }

    try {
        URL target = new URL(mapping.getValue());
        builder.setScheme(target.getProtocol());
        builder.setHost(target.getHost());
        if (target.getPort() != -1) {
            builder.setPort(target.getPort());
        }

        return builder;
    } catch (MalformedURLException e) {
        log.warn("Skipping DNS overwrite entry {} due to invalid value [{}]: {}", mapping.getName(), mapping.getValue(), e.getMessage());
        throw new ConfigurationException("Invalid DNS overwrite entry in homeserver client: " + mapping.getName(), e.getMessage());
    }
}
 
开发者ID:kamax-io,项目名称:mxisd,代码行数:22,代码来源:ClientDnsOverwrite.java

示例13: 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

示例14: getUser

import org.apache.http.client.utils.URIBuilder; //导入依赖的package包/类
private User getUser(@NotNull Token token) throws IOException, URISyntaxException {

		URIBuilder builder = new URIBuilder(PROFILE_URL);
		builder.addParameter("access_token", token.getAccessToken());

		HttpClient httpClient = HttpClientBuilder.create().build();
		HttpGet httpGet = new HttpGet(builder.build());
		org.apache.http.HttpResponse response = httpClient.execute(httpGet);
		int statusCode = response.getStatusLine().getStatusCode();
		InputStream inputStream = response.getEntity().getContent();

		if (HttpUtilities.success(statusCode)) {
			User user = gson.fromJson(new InputStreamReader(inputStream), User.class);
			user.setToken(token);
			return user;
		}

		throw new ApiException(HttpStatus.valueOf(statusCode));
	}
 
开发者ID:dhaval-mehta,项目名称:url-to-google-drive,代码行数:20,代码来源:GoogleOauthController.java

示例15: loadItemsByName

import org.apache.http.client.utils.URIBuilder; //导入依赖的package包/类
/**
 * Finds files on the NGB server with a name matching input query.
 * @param strId query to find
 * @param strict determines type of search, if true a strict equality by name search is performed
 *               otherwise a substring case-insensitive search is done
 * @return list of files matching a query
 */
protected List<BiologicalDataItem> loadItemsByName(String strId, boolean strict) {
    try {
        URI uri = new URIBuilder(serverParameters.getServerUrl() + serverParameters.getSearchUrl())
                .addParameter("name", strId)
                .addParameter("strict", String.valueOf(strict))
                .build();
        HttpGet get = new HttpGet(uri);
        setDefaultHeader(get);
        String result = RequestManager.executeRequest(get);
        ResponseResult<List<BiologicalDataItem>> responseResult = getMapper().readValue(result,
                getMapper().getTypeFactory().constructParametrizedType(
                        ResponseResult.class, ResponseResult.class,
                        getMapper().getTypeFactory().constructParametrizedType(
                                List.class, List.class, BiologicalDataItem.class)));
        if (responseResult == null) {
            throw new ApplicationException(getMessage(ERROR_FILE_NOT_FOUND, strId));
        }
        return responseResult.getPayload();
    } catch (IOException | URISyntaxException e) {
        throw new ApplicationException(e.getMessage(), e);
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:30,代码来源:AbstractHTTPCommandHandler.java


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