vertx rx.Observable.subscribe返回输入流

时间:2015-12-01 08:21:05

标签: rx-java vertx3

如何让HttpClientResponse返回一个InputStream而不是一个vertx.rx.Buffer?

HttpClientRequest req = client.requestAbs(HttpMethod.POST, endpointUrl);
        req.putHeader("Content-Type", "text/xml; charset=utf-8").
                putHeader("SOAPAction", "http://192.168.0.170/TT/BookingAPI/Search");

        req.toObservable().flatMap(resp -> {
            if (resp.statusCode() != HttpStatus.SC_OK) {
                throw new RuntimeException("Wrong status code " + resp.statusCode());
            }
            return resp.toObservable();
        }).subscribe(new Subscriber<InputStream>() {
            public void onNext(InputStream stream) {

//默认实现是Buffer,需要将InputStream传递给StaxReader。                 }                 public void onError(Throwable e){                 }

            public void onCompleted() {
                System.out.println("Start at :"+ st +" End at :"+ System.currentTimeMillis()+"Time taken: " + (System.currentTimeMillis() - st));
            }
        });
        req.end(request);

    }

0 个答案:

没有答案