使用spring mvc rest在spring boot中进行流响应

时间:2015-03-09 19:32:47

标签: spring-mvc spring-boot

我正在尝试在ResponseEntity中发送OutStream但是它给了我一个错误"无法找到可接受的表示"

OutputStream stream = new ByteArrayOutputStream();

        if (result.get(Orchestrator.SUCCESS_RESPONSE) != null) {
            logger.info("Received successful response [{}]", result.get(Orchestrator.SUCCESS_RESPONSE));
            try {
                GraphSONWriter.outputGraph((Graph) result.get(Orchestrator.SUCCESS_RESPONSE), stream);
            } catch (IOException e) {
                e.printStackTrace();
            }

            /*stream = outputStream -> {
                GraphSONWriter.outputGraph((Graph) result.get(Orchestrator.SUCCESS_RESPONSE), outputStream);
            };*/
            //return ResponseEntity.ok().header("Accept", "application/json").body(stream);
            httpHeaders.setContentType(MediaType.APPLICATION_JSON);
            return new ResponseEntity<OutputStream>(stream, httpHeaders, HttpStatus.OK);

我真的很感激你的帮助,谢谢你。

0 个答案:

没有答案