【问题标题】:JAX-RS ChunkedOutput and ChunkedInput with Wildfly带有 Wildfly 的 JAX-RS ChunkedOutput 和 ChunkedInput
【发布时间】:2018-01-31 14:15:13
【问题描述】:

请帮助将此simple example 部署到 Wildfly(首选版本 10.1.0)。 示例代码:

import org.glassfish.jersey.server.ChunkedOutput;
import javax.ws.rs.*;
import java.io.*;

@Path("/numbers")
public class NumbersResource {

    @GET
    public ChunkedOutput<String> streamExample(){
        final ChunkedOutput<String> output = new ChunkedOutput<String>(String.class);

        new Thread() {
            @Override
            public void run() {
                try {
                    for (int i = 0; i < 100000 ; i++){
                        output.write(i + " ");
                    }
                } catch (IOException e){
                    e.printStackTrace();
                } finally {
                    try {
                        output.close();
                    } catch (IOException e){
                        e.printStackTrace();
                    }
                }
            }
        }.start();
        return output;
    }

}

(代码的sn-p属于作者MEMORYNOTFOUND。我在这里添加它以防万一侧面因任何原因被关闭) 我已将其部署在 GlassFish 上,一切正常。但是现在,我需要将此功能移植到 Wildfly 上。并从导入

import org.glassfish.jersey.server.ChunkedOutput;

它表明 ChunkedOutput 类属于 GlassFish us 功能。换句话说,从 Wildfly jar 导入是否有类似我们的功能,或者我不知道...?

附:请在回复中提供一个简单的例子。 提前致谢!

【问题讨论】:

    标签: java jakarta-ee glassfish jax-rs wildfly


    【解决方案1】:

    改用StreamingOutput

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/<your-path>")
    public Response hello() {
        StreamingOutput stream = new StreamingOutput() {
            @Override
            public void write(OutputStream os) throws IOException, WebApplicationException {
                Writer writer = new BufferedWriter(new OutputStreamWriter(os));
    
                for (...) {
                    writer.write(...);
                }
                writer.flush();
            }
        };
        return Response.ok(stream).build();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-06
      • 1970-01-01
      • 2014-07-14
      • 1970-01-01
      • 1970-01-01
      • 2018-08-16
      • 2017-09-08
      相关资源
      最近更新 更多