當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。