使用 Wildfly 的 JAX-RS ChunkedOutput 和 ChunkedInput
JAX-RS ChunkedOutput and ChunkedInput with Wildfly
请帮助使此 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;
}
}
(代码片段属于作者MEMORYNOTFOUND。我已经添加了它以防万一侧面因任何原因关闭)
我已经将它部署在 GlassFish 上,一切正常。但是现在,我需要将此功能移植到 Wildfly 上。从进口
import org.glassfish.jersey.server.ChunkedOutput;
class ChunkedOutput 属于 GlassFish us 功能。换句话说,从 Wildfly jars 导入是否有类似我们的功能,或者我不知道...?
P.S。请在响应中提供一个简单的例子。
提前致谢!
@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();
}
请帮助使此 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;
}
}
(代码片段属于作者MEMORYNOTFOUND。我已经添加了它以防万一侧面因任何原因关闭) 我已经将它部署在 GlassFish 上,一切正常。但是现在,我需要将此功能移植到 Wildfly 上。从进口
import org.glassfish.jersey.server.ChunkedOutput;
class ChunkedOutput 属于 GlassFish us 功能。换句话说,从 Wildfly jars 导入是否有类似我们的功能,或者我不知道...?
P.S。请在响应中提供一个简单的例子。 提前致谢!
@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();
}