本文整理汇总了Java中javax.ws.rs.core.Response.readEntity方法的典型用法代码示例。如果您正苦于以下问题:Java Response.readEntity方法的具体用法?Java Response.readEntity怎么用?Java Response.readEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.Response
的用法示例。
在下文中一共展示了Response.readEntity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInvokesGetOperationWithCDIBean
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testInvokesGetOperationWithCDIBean() throws Exception{
String expectedBody = "Hello, MicroProfile!";
stubFor(get(urlEqualTo("/"))
.willReturn(aResponse()
.withBody(expectedBody)));
Response response = api.executeGet();
String body = response.readEntity(String.class);
response.close();
assertEquals(body, expectedBody);
verify(1, getRequestedFor(urlEqualTo("/")));
}
示例2: getEnabledTransactions_returnsOkAndEnabledTransactions
import javax.ws.rs.core.Response; //导入方法依赖的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);
}
}
示例3: getRegionData
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public RegionDataParams getRegionData() throws IOException {
WebTarget webTarget = restClient.target(SERVER_PATH + "regiondata");
Invocation.Builder invocationBuilder =
webTarget.request();
invocationBuilder.header("clientId", clientId);
Response response = invocationBuilder.get();
String noTransfer = response.getHeaderString("nothingToTransfer");
if ("nothingToTransfer".equals(noTransfer)) {
return null;
}
int fileId = Integer.valueOf(response.getHeaderString("fileId"));
long offset = Long.valueOf(response.getHeaderString("offset"));
long size = Long.valueOf(response.getHeaderString("size"));
InputStream inputStream = response.readEntity(InputStream.class);
byte[] bytes = IOUtils.toByteArray(inputStream);
return new RegionDataParams(fileId, offset, size, bytes, response);
}
示例4: verifyInjectedAuthTime2
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@RunAsClient
@Test(groups = TEST_GROUP_CDI_JSON,
description = "Verify that the injected auth_time is as expected from Token2")
public void verifyInjectedAuthTime2() throws Exception {
Reporter.log("Begin verifyInjectedAuthTime2\n");
HashMap<String, Long> timeClaims = new HashMap<>();
String token2 = TokenUtils.generateTokenString("/Token2.json", null, timeClaims);
Long authTimeClaim = timeClaims.get(Claims.auth_time.name());
String uri = baseURL.toExternalForm() + "/endp/verifyInjectedAuthTime";
WebTarget echoEndpointTarget = ClientBuilder.newClient()
.target(uri)
.queryParam(Claims.auth_time.name(), authTimeClaim);
Response response = echoEndpointTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token2).get();
Assert.assertEquals(response.getStatus(), HttpURLConnection.HTTP_OK);
String replyString = response.readEntity(String.class);
JsonReader jsonReader = Json.createReader(new StringReader(replyString));
JsonObject reply = jsonReader.readObject();
Reporter.log(reply.toString());
Assert.assertTrue(reply.getBoolean("pass"), reply.getString("msg"));
}
示例5: evaluate
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public Evaluation evaluate(String agentId, boolean meta, Map<String, Integer> inputMap) {
String url = String.format("%1$s/agent/%2$s", root, agentId);
WebTarget webTarget = client.target(url);
Invocation.Builder builder = webTarget
.request(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.header("Authorization", String.format("Bearer %s", key))
.header("User-Agent", "fuzzy.ai-java/" + version);
if (meta) {
builder.header("meta", "true");
}
Response response = builder.post(Entity.json(inputMap));
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
}
String evaluationId = response.getHeaderString("X-Evaluation-ID");
@SuppressWarnings("unchecked")
Map<String, Double> map = response.readEntity(Map.class);
return new Evaluation(evaluationId, map);
}
示例6: shouldGenerateRpAuthnResponseWithUnsignedMessage
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void shouldGenerateRpAuthnResponseWithUnsignedMessage() throws Exception {
// Given
ResponseFromHubDto responseFromHubDto = aResponseFromHubDto().build();
configStub.setUpStubForShouldHubSignResponseMessagesForSamlStandard(responseFromHubDto.getAuthnRequestIssuerEntityId());
Response samlMessageResponse = postToTestSamlMessageResource(responseFromHubDto);
assertThat(samlMessageResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
AuthnResponseFromHubContainerDto expectedResult = anAuthnResponseFromHubContainerDto()
.withSamlResponse(samlMessageResponse.readEntity(String.class))
.withPostEndPoint(responseFromHubDto.getAssertionConsumerServiceUri())
.withResponseId(responseFromHubDto.getResponseId())
.withRelayState(responseFromHubDto.getRelayState())
.build();
// When
URI generateAuthnResponseEndpoint = samlEngineAppRule.getUri(Urls.SamlEngineUrls.GENERATE_RP_AUTHN_RESPONSE_RESOURCE);
Response rpAuthnResponse = client.target(generateAuthnResponseEndpoint).request().post(Entity.entity(responseFromHubDto, MediaType.APPLICATION_JSON_TYPE));
// Then
assertThat(rpAuthnResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
AuthnResponseFromHubContainerDto actualResult = rpAuthnResponse.readEntity(AuthnResponseFromHubContainerDto.class);
assertThat(actualResult).isEqualToComparingFieldByField(expectedResult);
assertStatusCode(actualResult.getSamlResponse(), StatusCode.SUCCESS);
}
示例7: readAccounts
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
private void readAccounts(Client client, URI uri) {
Response response = client
.target(uri)
.request(MediaType.APPLICATION_JSON)
.get();
SNBAccounts accounts = response.readEntity(SNBAccounts.class);
accounts.getAccounts().forEach(account -> {
try {
self.handleAccount(client, account);
} catch (RuntimeException e) {
LOG.warn("Failed to handle transactions for {}", account.getAccountNumber());
}
});
if (accounts.getNext() != null) {
readAccounts(client, URI.create(accounts.getNext().getHref()));
}
}
示例8: aSessionIsCreated
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void responseProcessingDetails_shouldReturnWaitingForC3Status_whenNoMatchResponseSentFromMatchingServiceAndC3Required() throws Exception {
final SessionId sessionId = aSessionIsCreated();
anIdpIsSelectedForRegistration(sessionId, idpEntityId);
anIdpAuthnRequestWasGenerated(sessionId);
anAuthnResponseFromIdpWasReceivedAndMatchingRequestSent(sessionId);
aNoMatchResponseWasReceivedFromTheMSAForCycle01_withCycle3Enabled(sessionId);
URI uri = UriBuilder.fromPath(Urls.PolicyUrls.RESPONSE_PROCESSING_DETAILS_RESOURCE).build(sessionId);
Response response = getResponse(policy.uri(uri.toASCIIString()));
assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
ResponseProcessingDetails responseProcessingDetails = response.readEntity(ResponseProcessingDetails.class);
assertThat(responseProcessingDetails.getResponseProcessingStatus()).isEqualTo(ResponseProcessingStatus.GET_C3_DATA);
assertThat(responseProcessingDetails.getSessionId()).isEqualTo(sessionId);
assertThat(getSessionStateName(sessionId)).isEqualTo(AwaitingCycle3DataState.class.getName());
}
示例9: testEngineWithInjectedClientPost2
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testEngineWithInjectedClientPost2() {
final ResteasyDeployment deployment = new ResteasyDeployment();
deployment.start();
final ResteasyProviderFactory providerFactory = deployment.getProviderFactory();
final HttpClient httpClient = Vertx.vertx().createHttpClient(httpClientOptions);
final Client client = new ResteasyClientBuilder()
.providerFactory(providerFactory)
.httpEngine(new VertxClientEngine(httpClient))
.register(GsonMessageBodyHandler.class)
.build();
final Form xform = new Form();
xform.param("userName", "ca1\\\\meowmix");
xform.param("password", "mingnamulan");
xform.param("state", "authenticate");
xform.param("style", "xml");
xform.param("xsl", "none");
final Response response = client.target("https://httpbin.org/post").request(MediaType.APPLICATION_JSON)
.post(Entity.form(xform), Response.class);
assertFalse(response.getStringHeaders().isEmpty());
System.out.println(response.getStringHeaders());
assertFalse(response.getHeaders().isEmpty());
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getMediaType());
assertTrue(response.hasEntity());
final JsonObject arsString = response.readEntity(JsonObject.class);
assertEquals("xml", arsString.getAsJsonObject("form").get("style").getAsString());
}
示例10: testRandomIncrease
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testRandomIncrease() throws Exception {
final Response response = target()
.request(MediaType.APPLICATION_JSON_TYPE)
.accept(MediaType.APPLICATION_JSON_TYPE)
.get();
final Number rnd = response.readEntity(Number.class);
final Response incResponse = target()
.request(MediaType.APPLICATION_JSON_TYPE)
.accept(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.entity(rnd, MediaType.APPLICATION_JSON_TYPE));
final Number increased = incResponse.readEntity(Number.class);
assertEquals(rnd.getNumber() + 1, increased.getNumber());
}
示例11: approvePendingChanges
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public static void approvePendingChanges(WebTarget webTargetWithPath) throws AssertionError {
// path should contain changeVersion
Response response = webTargetWithPath.request().post(null);
// expect HTTP/1.1 200
String message = response.readEntity(String.class);
Assert.assertEquals("Response status code assertion error [" + message + "] during Approve pending changes:",
HttpURLConnection.HTTP_OK, response.getStatus());
}
示例12: testStringResponseWrapped
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testStringResponseWrapped() throws Exception {
// GIVEN
Map<String, String> queryParams = new HashMap<>();
queryParams.put("msg", "msg");
// WHEN
Response response = get("/repositoryActionJsonApi", queryParams);
// THEN
Assert.assertNotNull(response);
assertThat(response.getStatus())
.describedAs("Status code")
.isEqualTo(Response.Status.OK.getStatusCode());
MediaType mediaType = response.getMediaType();
assertThat(mediaType)
.describedAs("Media-Type")
.isEqualTo(JsonApiMediaType.APPLICATION_JSON_API_TYPE);
String entity = response.readEntity(String.class);
assertThat(entity)
.describedAs("Response content")
.isEqualTo("{\"data\":\"repository action: msg\"}");
}
示例13: updateFlow
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
* Updates flow through Northbound service.
*
* @param flowId flow id
* @param payload flow JSON data
* @return The JSON document of the created flow
*/
public static FlowPayload updateFlow(final String flowId, final FlowPayload payload) {
System.out.println("\n==> Northbound Update Flow");
long current = System.currentTimeMillis();
Client client = clientFactory();
Response response = client
.target(northboundEndpoint)
.path("/api/v1/flows")
.path("{flowid}")
.resolveTemplate("flowid", flowId)
.request(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, authHeaderValue)
.header(Utils.CORRELATION_ID, String.valueOf(System.currentTimeMillis()))
.put(Entity.json(payload));
System.out.println(String.format("===> Request Payload = %s", Entity.json(payload).getEntity()));
System.out.println(String.format("===> Response = %s", response.toString()));
System.out.println(String.format("===> Northbound Update Flow Time: %,.3f", getTimeDuration(current)));
int responseCode = response.getStatus();
if (responseCode == 200) {
FlowPayload flow = response.readEntity(FlowPayload.class);
System.out.println(String.format("====> Northbound Update Flow = %s", flow));
return flow;
} else {
System.out.println(String.format("====> Error: Northbound Update Flow = %s",
response.readEntity(MessageError.class)));
return null;
}
}
示例14: testInvokesPostOperationWithAnnotatedProviders
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testInvokesPostOperationWithAnnotatedProviders() throws Exception{
String inputBody = "input body will be removed";
String outputBody = "output body will be removed";
String expectedReceivedBody = "this is the replaced writer "+inputBody;
String expectedResponseBody = TestMessageBodyReader.REPLACED_BODY;
stubFor(post(urlEqualTo("/"))
.willReturn(aResponse()
.withBody(outputBody)));
InterfaceWithProvidersDefined api = RestClientBuilder.newBuilder()
.baseUrl(getServerURL())
.build(InterfaceWithProvidersDefined.class);
Response response = api.executePost(inputBody);
String body = response.readEntity(String.class);
response.close();
assertEquals(body, expectedResponseBody);
verify(1, postRequestedFor(urlEqualTo("/")).withRequestBody(equalTo(expectedReceivedBody)));
assertEquals(TestClientResponseFilter.getAndResetValue(),1);
assertEquals(TestClientRequestFilter.getAndResetValue(),1);
assertEquals(TestReaderInterceptor.getAndResetValue(),1);
assertEquals(TestWriterInterceptor.getAndResetValue(),1);
}
示例15: add
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Interceptors(CircuitBreaker.class)
public int add(int a, int b) {
JsonObject input = Json.createObjectBuilder().
add("a", a).
add("b", b).
build();
Response response = this.tut.
request(MediaType.APPLICATION_JSON).
post(json(input));
JsonObject jsonResult = response.readEntity(JsonObject.class);
this.counter.success();
return jsonResult.getJsonNumber("result").intValue();
}