javax.ws.rs.core.GenericEntity#getEntity()源码实例Demo

下面列出了javax.ws.rs.core.GenericEntity#getEntity() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cxf   文件: JAXRS20ClientServerBookTest.java
private void doTestPostGetCollectionGenericEntityAndType(WebClient wc, MediaType mediaType) throws Exception {

        wc.accept(mediaType).type(mediaType);
        GenericEntity<List<Book>> collectionEntity = createGenericEntity();
        InvocationCallback<List<Book>> callback = new ListBookInvocationCallback();

        Future<List<Book>> future = wc.async().post(Entity.entity(collectionEntity, mediaType),
                                                    callback);

        List<Book> books2 = future.get();
        assertNotNull(books2);

        List<Book> books = collectionEntity.getEntity();
        assertNotSame(books, books2);
        assertEquals(2, books2.size());
        Book b11 = books.get(0);
        assertEquals(123L, b11.getId());
        assertEquals("CXF in Action", b11.getName());
        Book b22 = books.get(1);
        assertEquals(124L, b22.getId());
        assertEquals("CXF Rocks", b22.getName());
        assertEquals(200, wc.getResponse().getStatus());
    }
 
源代码2 项目: cxf   文件: JAXRS20ClientServerBookTest.java
@Test
public void testPostGetCollectionGenericEntityAndType2() throws Exception {

    String endpointAddress =
        "http://localhost:" + PORT + "/bookstore/collections";
    WebClient wc = WebClient.create(endpointAddress);
    wc.accept("application/xml").type("application/xml");
    GenericEntity<List<Book>> collectionEntity = createGenericEntity();
    GenericType<List<Book>> genericResponseType = new GenericType<List<Book>>() {
    };

    Future<List<Book>> future = wc.async().post(Entity.entity(collectionEntity, "application/xml"),
                                                genericResponseType);

    List<Book> books2 = future.get();
    assertNotNull(books2);

    List<Book> books = collectionEntity.getEntity();
    assertNotSame(books, books2);
    assertEquals(2, books2.size());
    Book b11 = books.get(0);
    assertEquals(123L, b11.getId());
    assertEquals("CXF in Action", b11.getName());
    Book b22 = books.get(1);
    assertEquals(124L, b22.getId());
    assertEquals("CXF Rocks", b22.getName());
    assertEquals(200, wc.getResponse().getStatus());
}
 
源代码3 项目: cxf   文件: JAXRS20ClientServerBookTest.java
@Test
public void testPostGetCollectionGenericEntityAndType3() throws Exception {

    String endpointAddress =
        "http://localhost:" + PORT + "/bookstore/collections";
    WebClient wc = WebClient.create(endpointAddress);
    wc.accept("application/xml").type("application/xml");
    GenericEntity<List<Book>> collectionEntity = createGenericEntity();
    GenericType<List<Book>> genericResponseType = new GenericType<List<Book>>() {
    };

    Future<Response> future = wc.async().post(Entity.entity(collectionEntity, "application/xml"));

    Response r = future.get();
    List<Book> books2 = r.readEntity(genericResponseType);
    assertNotNull(books2);

    List<Book> books = collectionEntity.getEntity();
    assertNotSame(books, books2);
    assertEquals(2, books2.size());
    Book b11 = books.get(0);
    assertEquals(123L, b11.getId());
    assertEquals("CXF in Action", b11.getName());
    Book b22 = books.get(1);
    assertEquals(124L, b22.getId());
    assertEquals("CXF Rocks", b22.getName());
    assertEquals(200, wc.getResponse().getStatus());
}
 
源代码4 项目: cxf   文件: WebClient.java
protected Response doInvoke(String httpMethod,
                            Object body,
                            Class<?> requestClass,
                            Type inGenericType,
                            Class<?> responseClass,
                            Type outGenericType) {
    Annotation[] inAnns = null;
    if (body instanceof Entity) {
        Entity<?> entity = (Entity<?>)body;
        setEntityHeaders(entity);
        body = entity.getEntity();
        requestClass = body.getClass();
        inGenericType = body.getClass();
        inAnns = entity.getAnnotations();
    }
    if (body instanceof GenericEntity) {
        GenericEntity<?> genericEntity = (GenericEntity<?>)body;
        body = genericEntity.getEntity();
        requestClass = genericEntity.getRawType();
        inGenericType = genericEntity.getType();
    }
    MultivaluedMap<String, String> headers = prepareHeaders(responseClass, body);
    resetResponse();
    Response r = null;
    try {
        r = doChainedInvocation(httpMethod, headers, body, requestClass, inGenericType,
                                         inAnns, responseClass, outGenericType, null, null);
    } finally {
        resetResponseStateImmediatelyIfNeeded();
    }

    int status = r.getStatus();
    if (status != 304 && status >= 300 && responseClass != Response.class) {
        throw convertToWebApplicationException(r);
    }
    return r;
}
 
源代码5 项目: cxf   文件: WebClient.java
protected void prepareAsyncClient(String httpMethod,
                               Object body,
                               Class<?> requestClass,
                               Type inType,
                               Class<?> respClass,
                               Type outType,
                               JaxrsClientCallback<?> cb) {
    Annotation[] inAnns = null;
    if (body instanceof Entity) {
        Entity<?> entity = (Entity<?>)body;
        setEntityHeaders(entity);
        body = entity.getEntity();
        requestClass = body.getClass();
        inType = body.getClass();
        inAnns = entity.getAnnotations();
    }
    if (body instanceof GenericEntity) {
        GenericEntity<?> genericEntity = (GenericEntity<?>)body;
        body = genericEntity.getEntity();
        requestClass = genericEntity.getRawType();
        inType = genericEntity.getType();
    }

    MultivaluedMap<String, String> headers = prepareHeaders(respClass, body);
    resetResponse();

    Message m = finalizeMessage(httpMethod, headers, body, requestClass, inType,
                              inAnns, respClass, outType, null, null);

    m.getExchange().setSynchronous(false);
    setAsyncMessageObserverIfNeeded(m.getExchange());
    m.getExchange().put(JaxrsClientCallback.class, cb);

    doRunInterceptorChain(m);
}
 
源代码6 项目: SciGraph   文件: JaxRsUtil.java
/***
 * Build a Response, optionally wrapped in a JSONP callback.
 * <p>The response will be wrapped in a JSONP callback if any of the following apply:
 * <ul>
 * <li> The requested media type is <em>application/javascript</em>
 * <li> The callback is not null or empty
 * </ul>
 * @param request The request
 * @param response The response to wrap
 * @param callback The callback
 * @return A Response object, wrapped if necessary.
 */
public static Object wrapJsonp(Request request, GenericEntity<?> response, @Nullable String callback) {
  if (JaxRsUtil.isVariant(request, CustomMediaTypes.APPLICATION_JSONP_TYPE) || !isNullOrEmpty(callback)) {
    callback = Optional.ofNullable(callback).orElse(DEFAULT_JSONP_CALLBACK);
    
    return new JSONWrappedObject(format("%s(", callback), ");", response.getEntity());
  } else {
    return Response.ok(response).build();
  }
}
 
 同类方法