本文整理汇总了Java中javax.ws.rs.core.Response.close方法的典型用法代码示例。如果您正苦于以下问题:Java Response.close方法的具体用法?Java Response.close怎么用?Java Response.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.Response
的用法示例。
在下文中一共展示了Response.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetExecutionWithBuiltClient
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testGetExecutionWithBuiltClient() throws Exception{
String expectedBody = "Hello, MicroProfile!";
stubFor(get(urlEqualTo("/"))
.willReturn(aResponse()
.withBody(expectedBody)));
SimpleGetApi simpleGetApi = RestClientBuilder.newBuilder()
.baseUrl(getServerURL())
.build(SimpleGetApi.class);
Response response = simpleGetApi.executeGet();
String body = response.readEntity(String.class);
response.close();
assertEquals(body, expectedBody);
verify(1, getRequestedFor(urlEqualTo("/")));
}
示例2: testExecute_WithDeleteInspectionHook_ExpectNoContent
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testExecute_WithDeleteInspectionHook_ExpectNoContent() {
// Assume.
Response response = null;
try {
// Act.
response = target("controller/1.2.3.0/inspectionHooks/HookId")
.request()
.header(this.AUTHORIZATION_HEADER, this.AUTHORIZATION_CREDS)
.delete();
response.close();
// Assert.
assertThat(response.getStatus()).isEqualTo(Response.Status.NO_CONTENT.getStatusCode());
} finally {
if (response != null) {
response.close();
}
}
}
开发者ID:opensecuritycontroller,项目名称:sdn-controller-nsc-plugin,代码行数:24,代码来源:InspectionHookApisTest.java
示例3: deleteEntity
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
* Deletes the entity at the target id.
* @param id The ID of the entity to delete.
* @param client The REST client to use.
* @param <T> Type of entity to handle.
* @throws NotFoundException If 404 was returned.
* @throws TimeoutException If 408 was returned.
* @return True, if deletion succeeded; false otherwise.
*/
public static <T> boolean deleteEntity(RESTClient<T> client, long id) throws NotFoundException, TimeoutException {
Response response = client.getService().path(client.getApplicationURI()).path(client.getEndpointURI()).
path(String.valueOf(id)).request(MediaType.APPLICATION_JSON).delete();
if (response != null && response.getStatus() == 200) {
return true;
}
if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
throw new NotFoundException();
} else if (response.getStatus() == Status.REQUEST_TIMEOUT.getStatusCode()) {
throw new TimeoutException();
}
if (response != null) {
response.close();
}
return false;
}
示例4: testExecute_WithDeletePort_ExpectNoContent
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testExecute_WithDeletePort_ExpectNoContent() {
// Assume.
Response response = null;
try {
// Act.
response = target("controller/1.2.3.0/inspectionPorts/PortId")
.request()
.header(this.AUTHORIZATION_HEADER, this.AUTHORIZATION_CREDS)
.delete();
response.close();
// Assert.
assertThat(response.getStatus()).isEqualTo(Response.Status.NO_CONTENT.getStatusCode());
} finally {
if (response != null) {
response.close();
}
}
}
开发者ID:opensecuritycontroller,项目名称:sdn-controller-nsc-plugin,代码行数:24,代码来源:InspectionPortApisTest.java
示例5: testPropagationOfResponseDetailsFromDefaultMapper
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testPropagationOfResponseDetailsFromDefaultMapper() throws Exception {
stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(STATUS).withBody(BODY)));
SimpleGetApi simpleGetApi = RestClientBuilder.newBuilder()
.baseUrl(getServerURL())
.build(SimpleGetApi.class);
try {
simpleGetApi.executeGet();
fail("A "+WebApplicationException.class+" should have been thrown automatically");
}
catch (WebApplicationException w) {
Response response = w.getResponse();
// the response should have the response code from the api call
assertEquals(response.getStatus(), STATUS,
"The 401 from the response should be propagated");
String body = response.readEntity(String.class);
assertEquals(body, BODY,
"The body of the response should be propagated");
response.close();
}
}
示例6: testPostAlarm_withGoodRequest_expectStatusAccepted
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testPostAlarm_withGoodRequest_expectStatusAccepted() {
// Assume.
Response response = null;
try {
AlarmDto alarm = getAlarmDto();
Entity<AlarmDto> alarmEntity = Entity.entity(alarm, MediaType.APPLICATION_JSON);
// Act.
response = target("/api/server/v1/alarms")
.request()
.header(this.authorizationHeader, this.authorizationCreds)
.post(alarmEntity);
response.close();
// Assert.
assertThat(response.getStatus()).isEqualTo(202);
} finally {
if (response != null) {
response.close();
}
}
}
示例7: registerUser
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
private static void registerUser(String url, MediaType mediaType) {
System.out.println("Registering user via " + url);
User user = new User(1L, "larrypage");
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url);
Response response = target.request().post(Entity.entity(user, mediaType));
try {
if (response.getStatus() != 200) {
throw new RuntimeException("Failed with HTTP error code : " + response.getStatus());
}
System.out.println("Successfully got result: " + response.readEntity(String.class));
} finally {
response.close();
client.close();
}
}
示例8: testPutAlarm_withBadPathParam_expectErrorCode
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testPutAlarm_withBadPathParam_expectErrorCode() {
// Assume.
Response response = null;
try {
AlarmDto alarm = new AlarmDto();
Entity<AlarmDto> alarmEntity = Entity.entity(alarm, MediaType.APPLICATION_JSON);
String badParam = "textButShouldBeNumber";
// Act.
response = target("/api/server/v1/alarms/" + badParam)
.request()
.header(this.authorizationHeader, this.authorizationCreds)
.put(alarmEntity);
response.close();
// Assert.
assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
} finally {
if (response != null) {
response.close();
}
}
}
示例9: 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);
}
示例10: resetRemoteEMF
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
private String resetRemoteEMF(RESTClient<String> client) {
WebTarget target = client.getEndpointTarget().path("emf");
Response response = target.request(MediaType.TEXT_PLAIN).delete();
String message = null;
if (response.getStatus() == 200) {
message = response.readEntity(String.class);
}
response.close();
return message;
}
示例11: exists
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
public Boolean exists(final IRI identifier) {
requireNonNull(identifier, NON_NULL_IDENTIFIER);
final Response res = httpClient.target(identifier.getIRIString()).request().head();
final Boolean status = res.getStatusInfo().getFamily().equals(SUCCESSFUL);
LOGGER.info("HTTP HEAD request to {} returned status {}", identifier, res.getStatus());
res.close();
return status;
}
示例12: getUser
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
private static void getUser(String url) {
System.out.println("Getting user via " + url);
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url);
Response response = target.request().get();
try {
if (response.getStatus() != 200) {
throw new RuntimeException("Failed with HTTP error code : " + response.getStatus());
}
System.out.println("Successfully got result: " + response.readEntity(String.class));
} finally {
response.close();
client.close();
}
}
示例13: returnVideoNotFound
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void returnVideoNotFound() throws Exception {
String wrongVideoId = "wrong-video.mp4";
Response response = client.getVideo(wrongVideoId);
response.close();
assertThat(response.getStatus(), equalTo(404));
}
示例14: getEntity
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
private static <T> T getEntity(String url, String api, Class<T> entityClass) {
Response response = null;
try {
Client client = ClientBuilder.newBuilder().build();
response = client.target(url + API_ID_PRM + api).request().get();
return response.readEntity(entityClass);
} catch (Exception exp) {
throw new RestClientException(ERROR_WHILE_GATHERING_INFORMATION + ", error: " +
(response != null? response.getStatusInfo(): exp.getMessage()));
} finally {
if (response != null) {
response.close();
}
}
}
示例15: postSlowDigestMessageBatch
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public void postSlowDigestMessageBatch(List<ClientSlowDigestMessage> batch) {
logger.fine("Posting batch of ClientSlowDigestMessages");
WebTarget webTarget = restClient.target(SERVER_PATH + "clientslowdigestmessages");
Invocation.Builder invocationBuilder =
webTarget.request();
Entity<List<ClientSlowDigestMessage>> entity = Entity.entity(batch, MediaType.APPLICATION_JSON_TYPE);
Response post = invocationBuilder.post(entity);
if(!Response.Status.Family.SUCCESSFUL.equals(post.getStatusInfo().getFamily())){
logger.severe(post.getStatusInfo().toString());
}
post.close();
}