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


Java Response.close方法代码示例

本文整理汇总了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("/")));
}
 
开发者ID:eclipse,项目名称:microprofile-rest-client,代码行数:22,代码来源:InvokeSimpleGetOperationTest.java

示例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;
}
 
开发者ID:DescartesResearch,项目名称:Pet-Supply-Store,代码行数:26,代码来源:NonBalancedCRUDOperations.java

示例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();
    }
}
 
开发者ID:eclipse,项目名称:microprofile-rest-client,代码行数:24,代码来源:DefaultExceptionMapperTest.java

示例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();
        }
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:25,代码来源:AlarmApisTest.java

示例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();
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:18,代码来源:RestClient.java

示例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();
        }
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:26,代码来源:AlarmApisTest.java

示例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);
}
 
开发者ID:eclipse,项目名称:microprofile-rest-client,代码行数:30,代码来源:InvokeWithRegisteredProvidersTest.java

示例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;
}
 
开发者ID:DescartesResearch,项目名称:Pet-Supply-Store,代码行数:11,代码来源:CacheManager.java

示例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;
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:10,代码来源:HttpBasedBinaryService.java

示例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();
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:16,代码来源:RestClient.java

示例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));
}
 
开发者ID:andreschaffer,项目名称:http-progressive-download-examples,代码行数:8,代码来源:VideoResourceIT.java

示例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();
        }
    }
}
 
开发者ID:Vedenin,项目名称:RestAndSpringMVC-CodingChallenge,代码行数:16,代码来源:OpenExchangeRestClient.java

示例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();
}
 
开发者ID:gaganis,项目名称:odoxSync,代码行数:14,代码来源:RestClient.java


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