R
R
relgames2013-05-10 17:17:53
Java
relgames, 2013-05-10 17:17:53

How to disable buffering in Jetty?

I am developing a REST HTTP API, some calls take quite a long time (hours), there was a need for a control protocol.

I planned as follows: run a task in the background, periodically write lines like CONTROL_MESSAGE:Status 42% to the HttpOutputStream, read them in the client and display them on the screen.

In fact, I came across an unpleasant moment: Embedded Jetty 8.1.5 buffers output, flush() does not help.
On so they write that the matter is in chunk encoding, I tried to bypass it through Connection: close and setContentLength (MAX_INT), it does not work.

Am I missing something, should it work? Somehow, after all, Comet works through http streaming, there is exactly the same task - to periodically write to HttpOutputStream, but messages are delivered there immediately. Or am I misunderstanding the technology?

UPD, it looks like I need to somehow manually break messages into chunks (chunks), but it's not clear how yet.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
relgames, 2013-05-19
@relgames

In general, as it turned out, the problem was not in Jetty, but in Apache CXF.

1
1nd1go, 2013-05-10
@1nd1go

Like Transfer-encoding: chuncked and setContentLength() should not be together, i.e. if the second is, then it is assumed that it is not chuncked.
Then, accordingly, you send some kind of buffer to the outputStream and do a flush. You can also rest.setBufferSize() to determine the chunk size.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question