如何将Pojos列表(Jersey)列为输出流,同时仅获取一次Jersey RESTful客户端连接

时间:2018-07-20 17:03:37

标签: java web-services jersey jax-rs jersey-client

这是我的OrderDTO pojo课

public class OrderDTO implements Serializable {




 private static final long serialVersionUID = -4500200949047532187L;

    @JsonProperty("id")
    private Long id;

    @JsonProperty("tin")
    private String tin;


    @JsonProperty("amount")
    private BigDecimal amount;

    @JsonProperty("status")
    private TicketStatus status;

    @JsonProperty("customerInfo")
    private CustomerDTO customerDTO;



    @JsonProperty("oldTicketIdReference")
    private String oldTicketIdReference;

    @JsonProperty("newTicketIdReference")
    private String newTicketIdReference;

    @JsonProperty("cancellationTermsInfo")
    private CancellationTermsDTO cancellationTermsDTO;

    @JsonProperty("cartId")
    private Long cartId;

    @JsonProperty("transactionNumber")
    private Long transactionNumber;


    @JsonProperty("umsUserId")
    private Integer umsUserId;

}

如果我有如下所示的orderDTO列表,并且想一次获得客户端连接,然后只想流式传输orderDTO列表,该怎么办?你能告诉我吗。 目前,我的代码是这样的

final Client client = new Client();

List<OrderDTO> listOrderDto = getListOfOrders(cartId);

listOrderDto.parallelStream().forEach(orderDto->{

 client.target(
"http://localhost:8080/orders/writeAndIncrementOrder").
            header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).
            request.post(Entity.json(orderDto));

});

但是我不想多次休息,我只想获得一次客户端连接,然后将listOrderDto作为输出流发布到客户端。

0 个答案:

没有答案