org.apache.cxf.jaxrs.client.WebClient.postCollection()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中org.apache.cxf.jaxrs.client.WebClient.postCollection()方法的一些代码示例,展示了WebClient.postCollection()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClient.postCollection()方法的具体详情如下:
包路径:org.apache.cxf.jaxrs.client.WebClient
类名称:WebClient
方法名:postCollection

WebClient.postCollection介绍

[英]Posts a collection of typed objects
[中]发布类型化对象的集合

代码示例

代码示例来源:origin: stackoverflow.com

WebClient client = WebClient.create("http://myserver/services/test/postdata3"); 
 client.type("multipart/mixed").accept("application/json"); 
 List<Attachment> atts = new LinkedList<Attachment>(); 
 atts.add(new Attachment("testItem1", "application/json", t1)); 
 atts.add(new Attachment("testItem2", "application/json", t2)); 
 javax.ws.rs.core.Response s = client.postCollection(atts, Attachment.class); 
 System.out.println(s.getStatus());

代码示例来源:origin: apache/cxf

private void doTestNullPart(String address) throws Exception {
  WebClient client = WebClient.create(address);
  client.type("multipart/form-data").accept("text/plain");
  List<Attachment> atts = new LinkedList<>();
  atts.add(new Attachment("somepart", "text/plain", "hello there"));
  Response r = client.postCollection(atts, Attachment.class);
  assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
  assertEquals("nobody home", IOUtils.readStringFromStream((InputStream)r.getEntity()));
}

代码示例来源:origin: apache/cxf

@Test
public void testThatValidationConstraintsAreViolatedWithBooks()  {
  final Response r = createWebClient("/bookstore/books/directmany").type("text/xml").postCollection(
     Collections.singletonList(new BookWithValidation("BeanVal")), BookWithValidation.class);
  assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus());
}

代码示例来源:origin: apache/cxf

@Test
public void testNullableParamsPrimitive() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/books/testnullpartprimitive";
  WebClient client = WebClient.create(address);
  client.type("multipart/form-data").accept("text/plain");
  List<Attachment> atts = new LinkedList<>();
  atts.add(new Attachment("somepart", "text/plain", "hello there"));
  Response r = client.postCollection(atts, Attachment.class);
  assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
  assertEquals((Integer)0, Integer.valueOf(IOUtils.readStringFromStream((InputStream)r.getEntity())));
}

代码示例来源:origin: apache/cxf

@Test
public void testPostCollectionGetBooksWebClient() throws Exception {
  String endpointAddress =
    "http://localhost:" + PORT + "/bookstore/collections3";
  WebClient wc = WebClient.create(endpointAddress);
  wc.accept("application/xml").type("application/xml");
  Book b1 = new Book("CXF in Action", 123L);
  Book b2 = new Book("CXF Rocks", 124L);
  List<Book> books = new ArrayList<>();
  books.add(b1);
  books.add(b2);
  Book book = wc.postCollection(books, Book.class, Book.class);
  assertEquals(200, wc.getResponse().getStatus());
  assertNotSame(b1, book);
  assertEquals(b1.getName(), book.getName());
}

相关文章

WebClient类方法