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


Java Response.getEntity方法代码示例

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


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

示例1: testListEventsByCategory

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testListEventsByCategory() throws URISyntaxException {
    UriInfo ui = mock(UriInfo.class);
    when(ui.getBaseUriBuilder()).then(new UriBuilderFactory(URI.create("http://mock")));

    Request request = mock(Request.class);

    when(archivist.getEventsForCategory(Event.getCategory("some", "category"), Optional.empty()))
            .thenReturn(Collections.singletonList(new Event(new URI("customer-events/some-category/eventSID"),
                    "some-category", CurrentTime.now())));

    Response response = service.getByCategory(ui, request, "application/hal+json", "some-category", "");
    EventsRepresentation events = (EventsRepresentation) response.getEntity();

    assertEquals(1, events.getEvents().size());
    assertEquals("http://mock/customer-events", events.getSelf().getHref());

    response = service.getByCategory(ui, request, "application/hal+json;no-real-type", "some-category", "");
    assertEquals(415,response.getStatus());
}
 
开发者ID:psd2-in-a-box,项目名称:mid-tier,代码行数:21,代码来源:LocationEventServiceExposureTest.java

示例2: toString

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
protected static String toString(final Response r)
{
	try
	{
		try (final InputStream is = (InputStream) r.getEntity())
		{
			final byte[] b = new byte[1024];
			int read = 0;
			final StringBuffer buff = new StringBuffer();
			while ((read = is.read(b)) > 0)
				buff.append(new String(b, 0, read));
			return buff.toString();
		}
	}
	catch (final IOException e)
	{
		throw new ApiV4Exception(e);
	}
}
 
开发者ID:Cloud-Temple,项目名称:Mattermost-client,代码行数:20,代码来源:MatterMostBotClient.java

示例3: apply_ReturnQueryRepresentation_WhenGraphQueryResult

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void apply_ReturnQueryRepresentation_WhenGraphQueryResult() {
  // Arrange
  when(representation.getInformationProduct()).thenReturn(informationProduct);
  GraphQueryResult queryResult = mock(GraphQueryResult.class);
  when(informationProduct.getResult(ImmutableMap.of())).thenReturn(queryResult);
  when(informationProduct.getResultType()).thenReturn(ResultType.GRAPH);

  UriInfo uriInfo = mock(UriInfo.class);
  when(containerRequestContext.getUriInfo()).thenReturn(uriInfo);
  when(uriInfo.getPath()).thenReturn("/");

  // Act
  Response response = getRequestHandler.apply(containerRequestContext);

  // Assert
  assertThat(response.getStatus(), equalTo(200));
  assertThat(response.getEntity(), instanceOf(GraphEntity.class));
  GraphEntity entity = (GraphEntity) response.getEntity();
  assertThat(entity.getQueryResult(), equalTo(queryResult));
  assertThat(entity.getRepresentation(), equalTo(representation));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:23,代码来源:RepresentationRequestHandlerTest.java

示例4: testList

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testList() {
    Request request = mock(Request.class);

    UriInfo ui = mock(UriInfo.class);
    when(ui.getBaseUriBuilder()).then(new UriBuilderFactory(URI.create("http://mock")));

    when(archivist.listCustomers())
        .thenReturn(Arrays.asList(new Customer("Hans", "Peter", "Hansen"), new Customer("Anders", "P", "Dinesen")));

    Response response = service.list(ui, request, "application/hal+json");
    CustomersRepresentation customers = (CustomersRepresentation) response.getEntity();

    assertEquals(2, customers.getCustomers().size());
    assertEquals("http://mock/customers", customers.getSelf().getHref());

    response = service.list(ui, request, "application/hal+json;concept=non.existing;type");
    assertEquals(415,response.getStatus());

}
 
开发者ID:psd2-in-a-box,项目名称:mid-tier,代码行数:21,代码来源:CustomerServiceExposureTest.java

示例5: testUpdateWebServer

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testUpdateWebServer() {
    final JsonUpdateWebServer jsonUpdateWebServer = mock(JsonUpdateWebServer.class);
    when(Config.mockWebServerService.updateWebServer(any(UpdateWebServerRequest.class), any(User.class))).thenReturn(webServer);

    final Response response = webServerServiceRest.updateWebServer(jsonUpdateWebServer, Config.mockAuthenticatedUser);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

    final ApplicationResponse applicationResponse = (ApplicationResponse) response.getEntity();

    final Object content = applicationResponse.getApplicationResponseContent();
    assertTrue(content instanceof WebServer);

    final WebServer received = (WebServer) content;
    assertEquals(webServer, received);
}
 
开发者ID:cerner,项目名称:jwala,代码行数:17,代码来源:WebServerServiceRestImplTest.java

示例6: testListEventsByCategory

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testListEventsByCategory() throws URISyntaxException {
    UriInfo ui = mock(UriInfo.class);
    when(ui.getBaseUriBuilder()).then(new UriBuilderFactory(URI.create("http://mock")));

    Request request = mock(Request.class);

    when(archivist.getEventsForCategory(Event.getCategory("5479", "123456"), Optional.empty()))
            .thenReturn(Collections.singletonList(new Event(new URI("account-events/5479-1234567/eventSID"),
                    "5479-123456", CurrentTime.now())));

    Response response = service.getByCategory(ui, request, "application/hal+json", "5479-123456", "");
    EventsRepresentation events = (EventsRepresentation) response.getEntity();

    assertEquals(1, events.getEvents().size());
    assertEquals("http://mock/account-events", events.getSelf().getHref());

    response = service.getByCategory(ui, request, "application/hal+json;no-real-type", "5479-123456", "");
    assertEquals(415,response.getStatus());
}
 
开发者ID:psd2-in-a-box,项目名称:mid-tier,代码行数:21,代码来源:EventServiceExposureTest.java

示例7: shouldPassthroughErrorIdAndExceptionType

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void shouldPassthroughErrorIdAndExceptionType() throws Exception {
    UUID errorId = UUID.randomUUID();
    final ExceptionType exceptionType = ExceptionType.IDA_SOAP;
    ApplicationException applicationException = createUnauditedException(exceptionType, errorId);

    final Response response = samlEngineExceptionMapper.toResponse(applicationException);
    assertThat(response.hasEntity()).isTrue();
    ErrorStatusDto errorStatusDto = (ErrorStatusDto) response.getEntity();
    assertThat(errorStatusDto.getErrorId()).isEqualTo(errorId);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(exceptionType);

    checkLogLevel(applicationException.getExceptionType().getLevel());
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:15,代码来源:SamlEngineExceptionMapperTest.java

示例8: getApplicationsFromResponse

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private List<Application> getApplicationsFromResponse(Response resp) {
    assertNotNull(resp.getEntity());
    ApplicationResponse appResponse = (ApplicationResponse) resp.getEntity();
    Object entity = appResponse.getApplicationResponseContent();
    assertTrue(entity instanceof List<?>);

    return (List<Application>) entity;
}
 
开发者ID:cerner,项目名称:jwala,代码行数:10,代码来源:ApplicationServiceRestImplTest.java

示例9: shouldCreateAuditedErrorResponseForInvalidSaml

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void shouldCreateAuditedErrorResponseForInvalidSaml() throws Exception {
    Response response = exceptionMapper.handleException(new TestSamlTransformationErrorException("error", new RuntimeException(), Level.DEBUG));

    ErrorStatusDto responseEntity = (ErrorStatusDto) response.getEntity();
    assertThat(response.getStatus()).isEqualTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    assertThat(responseEntity.isAudited()).isTrue();
    assertThat(responseEntity.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:10,代码来源:SamlProxySamlTransformationErrorExceptionMapperTest.java

示例10: testVersionedMetadata

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testVersionedMetadata(){
    UriInfo ui = mock(UriInfo.class);
    when(ui.getBaseUriBuilder()).then(new UriBuilderFactory(URI.create("http://mock")));
    Request request = mock(Request.class);
    Response response = service.getCustomerServiceMetadata(ui, request, "application/hal+json;concept=metadata;v=1");
    EventsMetadataRepresentation info = (EventsMetadataRepresentation) response.getEntity();
    assertNotNull(info);
    assertTrue(info.getMetadata().contains("purpose"));
    assertEquals("http://mock/customer-events-metadata", info.getSelf().getHref());
}
 
开发者ID:psd2-in-a-box,项目名称:mid-tier,代码行数:12,代码来源:CustomerEventMetadataServiceExposureTest.java

示例11: write

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public void write(
        final MinijaxRequestContext context,
        final Response response,
        final HttpServletResponse servletResponse)
                throws IOException {

    servletResponse.setStatus(response.getStatus());

    for (final Entry<String, List<Object>> entry : response.getHeaders().entrySet()) {
        final String name = entry.getKey();
        for (final Object value : entry.getValue()) {
            servletResponse.addHeader(name, value.toString());
        }
    }

    if (context.getMethod().equals("OPTIONS")) {
        return;
    }

    final MediaType mediaType = response.getMediaType();
    if (mediaType != null) {
        servletResponse.setContentType(mediaType.toString());
    }

    final Object obj = response.getEntity();
    if (obj == null) {
        return;
    }

    final MessageBodyWriter writer = providers.getMessageBodyWriter(obj.getClass(), null, null, mediaType);
    if (writer != null) {
        writer.writeTo(obj, obj.getClass(), null, null, mediaType, null, servletResponse.getOutputStream());
        return;
    }

    // What to do
    servletResponse.getWriter().println(obj.toString());
}
 
开发者ID:minijax,项目名称:minijax,代码行数:40,代码来源:MinijaxApplication.java

示例12: testSearchPage

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testSearchPage() {
    final Response response = target("/owners/search").request().get();
    assertNotNull(response);
    assertEquals(200, response.getStatus());

    final View page = (View) response.getEntity();
    assertEquals("search", page.getTemplateName());
}
 
开发者ID:minijax,项目名称:minijax,代码行数:10,代码来源:OwnersResourceTest.java

示例13: testMetadata

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testMetadata(){
    UriInfo ui = mock(UriInfo.class);
    when(ui.getBaseUriBuilder()).then(new UriBuilderFactory(URI.create("http://mock")));
    Request request = mock(Request.class);
    Response response = service.getMetadata(ui, request, "application/hal+json");
    EventsMetadataRepresentation info = (EventsMetadataRepresentation) response.getEntity();
    assertNotNull(info);
    assertTrue(info.getMetadata().contains("purpose"));
    assertEquals("http://mock/account-events-metadata", info.getSelf().getHref());

    response = service.getMetadata( ui, request, "application/hal+json;concept=metadata");
    assertEquals(415,response.getStatus());
}
 
开发者ID:psd2-in-a-box,项目名称:mid-tier,代码行数:15,代码来源:EventMetadataServiceExposureTest.java

示例14: toResponse_shouldReturnAnUnauditedErrorStatusIfExceptionIsNotAudited

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void toResponse_shouldReturnAnUnauditedErrorStatusIfExceptionIsNotAudited() throws Exception {
    when(servletRequest.getParameter(Urls.SharedUrls.SESSION_ID_PARAM)).thenReturn("requestId");
    ApplicationException exception = createUnauditedExceptionThatShouldNotBeAudited();

    final Response response = mapper.toResponse(exception);

    final ErrorStatusDto errorStatus = (ErrorStatusDto) response.getEntity();
    assertThat(errorStatus.isAudited()).isEqualTo(false);
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:11,代码来源:PolicyApplicationExceptionMapperTest.java

示例15: testDeleteExternalProperties

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testDeleteExternalProperties() {
    String[] externalPropertiesArray = new String[]{"external.properties"};
    ResourceHierarchyParam param = new ResourceHierarchyParam();

    when(impl.deleteExternalProperties()).thenReturn(1);

    Response result = cut.deleteResources(externalPropertiesArray, param, authenticatedUser);
    Assert.assertEquals(200, result.getStatus());
    verify(impl).deleteExternalProperties();
    ApplicationResponse entity = (ApplicationResponse) result.getEntity();
    int recCount = (int) entity.getApplicationResponseContent();
    Assert.assertEquals(1, recCount);
}
 
开发者ID:cerner,项目名称:jwala,代码行数:15,代码来源:ResourceServiceRestImplTest.java


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