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


Java GetRequest.queryString方法代码示例

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


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

示例1: check

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
/**
 * Call the health service check consul end point
 *
 * When consul index is specified the consul service will wait to to return services until either the waitTime has expired or
 * a change has happened to the specified service.
 *
 * More details: https://www.consul.io/docs/agent/watches.html
 *
 * @param name Service name to look up
 * @param consulIndex When not null passes this index to consul to allow a blocked query
 * @param waitTimeSeconds time to pass to consul to wait for changes to a service
 * @param passing if true only returns services that are passing their health check.
 * @return Response object with Consul-Index and a list of services
 * @throws ConsulException
 */
public HealthServiceCheckResponse check(String name, String consulIndex, int waitTimeSeconds, boolean passing) throws ConsulException {
    HttpResponse<String> resp;
    GetRequest request = Unirest.get(consul().getUrl() + EndpointCategory.HealthService.getUri() + "{name}")
                                .routeParam("name", name);
    if (consulIndex != null) {
        request.queryString("index", consulIndex);
        request.queryString("wait", waitTimeSeconds + "s");
    }
    if (passing) {
        request.queryString("passing", "true");
    }
    try {
        resp = request.asStringAsync().get((long)Math.ceil(1.1f * waitTimeSeconds), TimeUnit.SECONDS);
    } catch (ExecutionException | InterruptedException | TimeoutException e) {
       throw new ConsulException(e);
    }

    String newConsulIndex = resp.getHeaders().getFirst(INDEX_HEADER);
    List<HealthServiceCheck> serviceChecks = new ArrayList<>();
    if (resp.getStatus() >= 500) {
        throw new ConsulException("Error Status Code: " + resp.getStatus() + "  body: " + resp.getBody());
    }
    JSONArray arr = parseJson(resp.getBody()).getArray();
    for (int i = 0; i < arr.length(); i++) {
        serviceChecks.add(new HealthServiceCheck(arr.getJSONObject(i)));
    }
    return new HealthServiceCheckResponse(newConsulIndex, serviceChecks);
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:44,代码来源:HealthService.java

示例2: executeGet

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
private BaseRequest executeGet(String baseUrl, Object urlMap, Object bodyMap) {
    GetRequest getRequest = Unirest.get(baseUrl + urlTemplate.execute(urlMap));
    Map<String, Object> map = (Map<String, Object>) bodyMap;
    if (field == null || !map.containsKey("predicates"))
        return getRequest;
    return getRequest
            .queryString(field,
                    bodyTemplate.execute(bodyMap).replace("\n", "").replace("\r", "").replace("\t", ""));
}
 
开发者ID:unipop-graph,项目名称:unipop,代码行数:10,代码来源:TemplateRequest.java

示例3: executeGetQuery

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
/**
 * Test the {@link FreesoundClient#executeQuery(Query)} method, to ensure it correctly constructs and submits an
 * HTTP GET request, and processes the results.
 *
 * @param mockUnirest Mock version of the {@link Unirest} library
 * @param mockGetRequest Mock {@link GetRequest}
 * @param mockHttpResponse Mock {@link HttpResponse}
 * @param mockResultsMapper Mock {@link SoundMapper}
 *
 * @throws Exception Any exceptions thrown in test
 */
@SuppressWarnings("static-access")
@Test
public void executeGetQuery(
		@Mocked final Unirest mockUnirest,
		@Mocked final GetRequest mockGetRequest,
		@Mocked final HttpResponse<JsonNode> mockHttpResponse,
		@Mocked final SoundMapper mockResultsMapper) throws Exception {
	final Sound sound = new Sound();
	new Expectations() {
		{
			mockUnirest.get(FreesoundClient.API_ENDPOINT + TEST_PATH); result = mockGetRequest;

			mockGetRequest.header("Authorization", "Token " + CLIENT_SECRET);
			mockGetRequest.routeParam(ROUTE_ELEMENT, ROUTE_ELEMENT_VALUE);
			mockGetRequest.queryString(with(new Delegate<HashMap<String, Object>>() {
				@SuppressWarnings("unused")
				void checkRequestParameters(final Map<String, Object> queryParameters) {
					assertNotNull(queryParameters);
					assertTrue(queryParameters.size() == 1);
					assertEquals(QUERY_PARAMETER_VALUE, queryParameters.get(QUERY_PARAMETER));
				}
			}));

			mockGetRequest.asJson(); result = mockHttpResponse;
			mockHttpResponse.getStatus(); result = 200;
			mockResultsMapper.map(mockHttpResponse.getBody().getObject()); result = sound;
		}
	};

	final JSONResponseQuery<Sound> query = new TestJSONResponseQuery(HTTPRequestMethod.GET, mockResultsMapper);
	final Response<Sound> response = freesoundClient.executeQuery(query);

	assertSame(sound, response.getResults());
}
 
开发者ID:Sonoport,项目名称:freesound-java,代码行数:46,代码来源:FreesoundClientTest.java

示例4: executeBinaryResponseQuery

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
/**
 * Test the {@link FreesoundClient#executeQuery(Query)} method, to ensure it correctly constructs and submits an
 * HTTP GET request, and processes the results.
 *
 * @param mockUnirest Mock version of the {@link Unirest} library
 * @param mockGetRequest Mock {@link GetRequest}
 * @param mockHttpResponse Mock {@link HttpResponse}
 * @param mockInputStream Mock {@link InputStream} response
 *
 * @throws Exception Any exceptions thrown in test
 */
@SuppressWarnings("static-access")
@Test
public void executeBinaryResponseQuery(
		@Mocked final Unirest mockUnirest,
		@Mocked final GetRequest mockGetRequest,
		@Mocked final HttpResponse<InputStream> mockHttpResponse,
		@Mocked final InputStream mockInputStream) throws Exception {
	new Expectations() {
		{
			mockUnirest.get(FreesoundClient.API_ENDPOINT + TEST_PATH); result = mockGetRequest;

			mockGetRequest.header("Authorization", "Token " + CLIENT_SECRET);
			mockGetRequest.routeParam(ROUTE_ELEMENT, ROUTE_ELEMENT_VALUE);
			mockGetRequest.queryString(with(new Delegate<HashMap<String, Object>>() {
				@SuppressWarnings("unused")
				void checkRequestParameters(final Map<String, Object> queryParameters) {
					assertNotNull(queryParameters);
					assertTrue(queryParameters.size() == 1);
					assertEquals(QUERY_PARAMETER_VALUE, queryParameters.get(QUERY_PARAMETER));
				}
			}));

			mockGetRequest.asBinary(); result = mockHttpResponse;
			mockHttpResponse.getStatus(); result = 200;
			mockHttpResponse.getBody(); result = mockInputStream;
		}
	};

	final TestBinaryResponseQuery query = new TestBinaryResponseQuery();
	final Response<InputStream> response = freesoundClient.executeQuery(query);

	assertSame(mockInputStream, response.getResults());
}
 
开发者ID:Sonoport,项目名称:freesound-java,代码行数:45,代码来源:FreesoundClientTest.java

示例5: unexpected500Response

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
/**
 * Test situations where an unexpected error has been returned by the freesound API.
 *
 * @param mockUnirest Mock version of the {@link Unirest} library
 * @param mockGetRequest Mock {@link GetRequest}
 * @param mockHttpResponse Mock {@link HttpResponse}
 * @param mockResultsMapper Mock {@link SoundMapper}
 *
 * @throws Exception Any exceptions thrown in test
 */
@SuppressWarnings("static-access")
@Test (expected = FreesoundClientException.class)
public void unexpected500Response(
		@Mocked final Unirest mockUnirest,
		@Mocked final GetRequest mockGetRequest,
		@Mocked final HttpResponse<JsonNode> mockHttpResponse,
		@Mocked final SoundMapper mockResultsMapper) throws Exception {
	new Expectations() {
		{
			mockUnirest.get(FreesoundClient.API_ENDPOINT + TEST_PATH); result = mockGetRequest;

			mockGetRequest.header("Authorization", "Token " + CLIENT_SECRET);
			mockGetRequest.routeParam(ROUTE_ELEMENT, ROUTE_ELEMENT_VALUE);
			mockGetRequest.queryString(with(new Delegate<HashMap<String, Object>>() {
				@SuppressWarnings("unused")
				void checkRequestParameters(final Map<String, Object> queryParameters) {
					assertNotNull(queryParameters);
					assertTrue(queryParameters.size() == 1);
					assertEquals(QUERY_PARAMETER_VALUE, queryParameters.get(QUERY_PARAMETER));
				}
			}));

			mockGetRequest.asJson(); result = mockHttpResponse;
			mockHttpResponse.getBody(); result = "<html><body><h1>500 Error</h1></body></html>";
		}
	};

	final JSONResponseQuery<Sound> query = new TestJSONResponseQuery(HTTPRequestMethod.GET, mockResultsMapper);
	freesoundClient.executeQuery(query);
}
 
开发者ID:Sonoport,项目名称:freesound-java,代码行数:41,代码来源:FreesoundClientTest.java

示例6: select

import com.mashape.unirest.request.GetRequest; //导入方法依赖的package包/类
/**
 * Select List of data of table with defined Query Parameters.
 *
 * @param query defined query
 * @return list of table items
 * @throws AirtableException
 */
@SuppressWarnings("WeakerAccess")
public List<T> select(final Query query) throws AirtableException {
    HttpResponse<Records> response;
    try {
        final GetRequest request = Unirest.get(getTableEndpointUrl())
                .header("accept", MIME_TYPE_JSON)
                .header("Authorization", getBearerToken())
                .header("Content-type" , MIME_TYPE_JSON);

        if (query.getFields() != null && query.getFields().length > 0) {
            String[] fields = query.getFields();
            for (String field : fields) {
                request.queryString("fields[]", field);

            }
        }
        if (query.getMaxRecords() != null) {
            request.queryString("maxRecords", query.getMaxRecords());
        }
        if (query.getView() != null) {
            request.queryString("view", query.getView());
        }
        if (query.filterByFormula() != null) {
            request.queryString("filterByFormula", query.filterByFormula());
        }
        if (query.getPageSize() != null) {
            if (query.getPageSize() > 100) {
                LOG.warn("pageSize is limited to max 100 but was " + query.getPageSize());
                request.queryString("pageSize", 100);
            } else {
                request.queryString("pageSize", query.getPageSize());
            }
        }
        if (query.getSort() != null) {
            int i = 0;
            for (Sort sort : query.getSort()) {
                request.queryString("sort[" + i + "][field]", sort.getField());
                request.queryString("sort[" + i + "][direction]", sort.getDirection());
            }
        }
        if (query.getOffset()!= null) {
            request.queryString("offset", query.getOffset());
        }

        LOG.debug("URL=" + request.getUrl());

        response = request.asObject(Records.class);
    } catch (UnirestException e) {
        throw new AirtableException(e);
    }

    int code = response.getStatus();
    List<T> list;
    if (200 == code) {
        list = getList(response);

        final String offset = response.getBody().getOffset();

        if (offset != null) {
            list.addAll(this.select(query, offset));
        }
    } else {
        HttpResponseExceptionHandler.onResponse(response);
        list = null;
    }

    return list;
}
 
开发者ID:Sybit-Education,项目名称:airtable.java,代码行数:76,代码来源:Table.java


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