本文整理匯總了Java中javax.ws.rs.core.GenericType類的典型用法代碼示例。如果您正苦於以下問題:Java GenericType類的具體用法?Java GenericType怎麽用?Java GenericType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GenericType類屬於javax.ws.rs.core包,在下文中一共展示了GenericType類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testRegister
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
/**
* Test if after registration of service they can be found in registry.
*/
@Test
public void testRegister() {
Response response1 = ClientBuilder.newBuilder().build().target("http://localhost:"
+ getTomcatPort() + "/test/rest/services/service1/abbaasd")
.request(MediaType.APPLICATION_JSON).put(Entity.text(""));
Assert.assertTrue(response1.getStatus() == Response.Status.OK.getStatusCode());
Response response2 = ClientBuilder.newBuilder().build().target("http://localhost:"
+ getTomcatPort() + "/test/rest/services/service1/abbaasd2")
.request(MediaType.APPLICATION_JSON).put(Entity.text(""));
Assert.assertTrue(response2.getStatus() == Response.Status.OK.getStatusCode());
Response response = ClientBuilder.newBuilder().build().target("http://localhost:"
+ getTomcatPort() + "/test/rest/services/service1").request(MediaType.APPLICATION_JSON).get();
Assert.assertTrue(response.getStatus() == Response.Status.OK.getStatusCode());
List<String> list = response.readEntity(new GenericType<List<String>>() { });
Assert.assertTrue(list != null);
Assert.assertTrue(list.size() == 2);
Assert.assertTrue(list.get(0).equals("abbaasd"));
Assert.assertTrue(list.get(1).equals("abbaasd2"));
}
示例2: deserialize
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
/**
* Deserialize response body to Java object according to the Content-Type.
* @param <T> Type
* @param response Response
* @param returnType Return type
* @return Deserialize object
* @throws ApiException API exception
*/
@SuppressWarnings("unchecked")
public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
if (response == null || returnType == null) {
return null;
}
if ("byte[]".equals(returnType.toString())) {
// Handle binary response (byte array).
return (T) response.readEntity(byte[].class);
} else if (returnType.getRawType() == File.class) {
// Handle file downloading.
T file = (T) downloadFileFromResponse(response);
return file;
}
String contentType = null;
List<Object> contentTypes = response.getHeaders().get("Content-Type");
if (contentTypes != null && !contentTypes.isEmpty())
contentType = String.valueOf(contentTypes.get(0));
if (contentType == null)
throw new ApiException(500, "missing Content-Type in response");
return response.readEntity(returnType);
}
示例3: getEnabledTransactions_returnsOkAndEnabledTransactions
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
@Test
public void getEnabledTransactions_returnsOkAndEnabledTransactions(){
URI uri = configAppRule.getUri("/config/transactions" + Urls.ConfigUrls.ENABLED_TRANSACTIONS_PATH).build();
Response response = client.target(uri).request().get();
assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
List<TransactionDisplayData> transactionDisplayItems
= response.readEntity(new GenericType<List<TransactionDisplayData>>() {});
for (TransactionDisplayData transactionDisplayItem : transactionDisplayItems) {
List<LevelOfAssurance> loas = transactionDisplayItem.getLoaList();
assertThat(loas != null);
}
}
示例4: shouldSuccessfullyCreateRequestWithCustomRange
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
@Test
public void shouldSuccessfullyCreateRequestWithCustomRange() {
final String symbol = "IBM";
final SplitsRange splitsRange = SplitsRange.ONE_YEAR;
final RestRequest<List<Split>> request = new SplitsRequestBuilder()
.withSymbol(symbol)
.withSplitsRange(splitsRange)
.build();
assertThat(request.getMethodType()).isEqualTo(MethodType.GET);
assertThat(request.getPath()).isEqualTo("/stock/{symbol}/splits/{range}");
assertThat(request.getResponseType()).isEqualTo(new GenericType<List<Split>>() {});
assertThat(request.getPathParams()).containsExactly(
entry("symbol", symbol),
entry("range", splitsRange.getCode()));
assertThat(request.getQueryParams()).isEmpty();
}
示例5: shouldReturnFibonacciNos
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
@Test
public void shouldReturnFibonacciNos() {
List<Sequence> first10FibonacciNos = ImmutableList.of(
new Sequence(new BigInteger("1"), new BigInteger("0")),
new Sequence(new BigInteger("2"), new BigInteger("1")),
new Sequence(new BigInteger("3"), new BigInteger("1")),
new Sequence(new BigInteger("4"), new BigInteger("2")),
new Sequence(new BigInteger("5"), new BigInteger("3")),
new Sequence(new BigInteger("6"), new BigInteger("5")),
new Sequence(new BigInteger("7"), new BigInteger("8")),
new Sequence(new BigInteger("8"), new BigInteger("13")),
new Sequence(new BigInteger("9"), new BigInteger("21")),
new Sequence(new BigInteger("10"), new BigInteger("34"))
);
List<Sequence> evenNos = resources.client().target("/fibonacci?limit=100").request().get(new GenericType<List<Sequence>>(){});
assertThat(evenNos).hasSize(100);
assertThat(evenNos).containsAll(first10FibonacciNos);
assertThat(evenNos).contains(new Sequence(new BigInteger("100"), new BigInteger("218922995834555169026")));
}
示例6: testUnregisterSuccess
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
/**
* Test if unregistering a service actually removes it from the registry.
*/
@Test
public void testUnregisterSuccess() {
Response response1 = ClientBuilder.newBuilder().build().target("http://localhost:"
+ getTomcatPort() + "/test/rest/services/service2/abbaasd")
.request(MediaType.APPLICATION_JSON).put(Entity.text(""));
Assert.assertTrue(response1.getStatus() == Response.Status.OK.getStatusCode());
Response response2 = ClientBuilder.newBuilder().build().target("http://localhost:"
+ getTomcatPort() + "/test/rest/services/service2/abbaasd")
.request(MediaType.APPLICATION_JSON).delete();
Assert.assertTrue(response2.getStatus() == Response.Status.OK.getStatusCode());
Response response = ClientBuilder.newBuilder().build().target("http://localhost:"
+ getTomcatPort() + "/test/rest/services/service2").request(MediaType.APPLICATION_JSON).get();
Assert.assertTrue(response.getStatus() == Response.Status.OK.getStatusCode());
List<String> list = response.readEntity(new GenericType<List<String>>() { });
Assert.assertTrue(list != null);
Assert.assertTrue(list.size() == 0);
}
示例7: getWebImages
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
/**
* Retrieves a series of web image.
* @param names list of name of image.
* @param size target size
* @throws NotFoundException If 404 was returned.
* @throws LoadBalancerTimeoutException On receiving the 408 status code
* and on repeated load balancer socket timeouts.
* @return HashMap containing requested images.
*/
public static HashMap<String, String> getWebImages(List<String> names, ImageSize size)
throws NotFoundException, LoadBalancerTimeoutException {
HashMap<String, String> img = new HashMap<>();
for (String name : names) {
img.put(name, size.toString());
}
Response r = ServiceLoadBalancer.loadBalanceRESTOperation(Service.IMAGE, "image", HashMap.class,
client -> client.getService().path(client.getApplicationURI())
.path(client.getEndpointURI()).path("getWebImages").request(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON).post(Entity.entity(img, MediaType.APPLICATION_JSON)));
if (r == null) {
return new HashMap<String, String>();
}
HashMap<String, String> result = r.readEntity(new GenericType<HashMap<String, String>>() { });
if (result == null) {
return new HashMap<String, String>();
}
return result;
}
示例8: testBeanParameter
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
@Test
public void testBeanParameter() throws Exception {
WebTarget webTarget = client.target(server.getURI().toString());
Invocation.Builder invocationBuilder = webTarget.path("/book")
.queryParam("author", "Scott Oaks")
.request(MediaType.APPLICATION_JSON);
Response response = invocationBuilder.get();
Map<String, String> entity = response.readEntity(new GenericType<Map<String, String>>() {});
assertThat(response.getStatus(), equalTo(OK.getStatusCode()));
assertThat(entity.get("author"), equalTo("Scott Oaks"));
}
示例9: if
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
/**
* Lists all of a location's item categories.
* Lists all of a location's item categories.
* @param locationId The ID of the location to list categories for. (required)
* @return CompleteResponse<List<V1Category>>
* @throws ApiException if fails to make API call
*/
public CompleteResponse<List<V1Category>>listCategoriesWithHttpInfo(String locationId) throws ApiException {
Object localVarPostBody = null;
// verify the required parameter 'locationId' is set
if (locationId == null) {
throw new ApiException(400, "Missing the required parameter 'locationId' when calling listCategories");
}
// create path and map variables
String localVarPath = "/v1/{location_id}/categories"
.replaceAll("\\{" + "location_id" + "\\}", apiClient.escapeString(locationId.toString()));
// query params
List<Pair> localVarQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
final String[] localVarAccepts = {
"application/json"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = {
"application/json"
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
String[] localVarAuthNames = new String[] { "oauth2" };
GenericType<List<V1Category>> localVarReturnType = new GenericType<List<V1Category>>() {};
return (CompleteResponse<List<V1Category>>)apiClient.invokeAPI(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
}
示例10: listBankAccounts
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
/**
* Provides non-confidential details for all of a location's associated bank accounts. This endpoint does not provide full bank account numbers, and there is no way to obtain a full bank account number with the Connect API.
* Provides non-confidential details for all of a location's associated bank accounts. This endpoint does not provide full bank account numbers, and there is no way to obtain a full bank account number with the Connect API.
* @param locationId The ID of the location to list bank accounts for. (required)
* @return List<V1BankAccount>
* @throws ApiException if fails to make API call
*/
public List<V1BankAccount> listBankAccounts(String locationId) throws ApiException {
Object localVarPostBody = null;
// verify the required parameter 'locationId' is set
if (locationId == null) {
throw new ApiException(400, "Missing the required parameter 'locationId' when calling listBankAccounts");
}
// create path and map variables
String localVarPath = "/v1/{location_id}/bank-accounts"
.replaceAll("\\{" + "location_id" + "\\}", apiClient.escapeString(locationId.toString()));
// query params
List<Pair> localVarQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
final String[] localVarAccepts = {
"application/json"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = {
"application/json"
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
String[] localVarAuthNames = new String[] { "oauth2" };
GenericType<List<V1BankAccount>> localVarReturnType = new GenericType<List<V1BankAccount>>() {};
CompleteResponse<List<V1BankAccount>> completeResponse = (CompleteResponse<List<V1BankAccount>>)apiClient.invokeAPI(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
return completeResponse.getData();
}
示例11: doubleInMapTest
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
@Test
public void doubleInMapTest() {
MapTest response = client.target(SERVER_URI)
.path("/doubleInMapTest")
.request()
.accept(MediaType.APPLICATION_JSON_TYPE)
.get(new GenericType<MapTest>() {});
check(response.mapDouble().values()).isOf(5.0d);
}
示例12: getOpenShiftClusters
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
public List<String> getOpenShiftClusters(String authHeader) {
URI targetURI = UriBuilder.fromUri(missionControlOpenShiftURI).path("/clusters").build();
try {
return perform(client -> client
.target(targetURI)
.request(MediaType.APPLICATION_JSON_TYPE)
.header(HttpHeaders.AUTHORIZATION, authHeader)
.get().readEntity(new GenericType<List<String>>() {
}));
} catch (Exception e) {
log.log(Level.SEVERE, "Error while returning openshift clusters", e);
return Collections.emptyList();
}
}
示例13: retrieveBusiness
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
/**
* Get a business's information.
* Get a business's information.
* @return V1Merchant
* @throws ApiException if fails to make API call
*/
public V1Merchant retrieveBusiness() throws ApiException {
Object localVarPostBody = null;
// create path and map variables
String localVarPath = "/v1/me";
// query params
List<Pair> localVarQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
final String[] localVarAccepts = {
"application/json"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = {
"application/json"
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
String[] localVarAuthNames = new String[] { "oauth2" };
GenericType<V1Merchant> localVarReturnType = new GenericType<V1Merchant>() {};
CompleteResponse<V1Merchant> completeResponse = (CompleteResponse<V1Merchant>)apiClient.invokeAPI(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
return completeResponse.getData();
}
示例14: shouldSuccessfullyCreateRequest
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
@Test
public void shouldSuccessfullyCreateRequest() {
final String symbol = "IBM";
final RestRequest<Map<String, SsrStatus>> request = new SsrStatusRequestBuilder()
.withSymbol(symbol)
.build();
assertThat(request.getMethodType()).isEqualTo(MethodType.GET);
assertThat(request.getPath()).isEqualTo("/deep/ssr-status");
assertThat(request.getResponseType()).isEqualTo(new GenericType<Map<String, SsrStatus>>() {});
assertThat(request.getPathParams()).isEmpty();
assertThat(request.getQueryParams()).contains(entry("symbols", symbol));
}
示例15: readEntity
import javax.ws.rs.core.GenericType; //導入依賴的package包/類
@Override
public <U> U readEntity(GenericType<U> entityType) {
if (!entityType.getRawType().equals(bodyClass)) {
throw new IllegalArgumentException(
"Raw generic type is not the same type as the body entity");
}
return rawResponse.readEntity(entityType);
}