2
2
3
3
import io .netty .buffer .ByteBuf ;
4
4
import io .netty .handler .codec .http .HttpResponseStatus ;
5
- import io .reactivex .lab .services .common .RxNettySSE ;
5
+ import io .reactivex .netty .RxNetty ;
6
+ import io .reactivex .netty .pipeline .PipelineConfigurators ;
6
7
import io .reactivex .netty .protocol .http .server .HttpServer ;
7
8
import io .reactivex .netty .protocol .http .server .HttpServerRequest ;
8
9
import io .reactivex .netty .protocol .http .server .HttpServerResponse ;
9
- import io .reactivex .netty .protocol .text .sse .ServerSentEvent ;
10
+ import io .reactivex .netty .protocol .http .sse .ServerSentEvent ;
10
11
11
12
import java .util .List ;
12
13
@@ -16,17 +17,17 @@ public abstract class MiddleTierService {
16
17
17
18
public HttpServer <ByteBuf , ServerSentEvent > createServer (int port ) {
18
19
System .out .println ("Start " + getClass ().getSimpleName () + " on port: " + port );
19
- return RxNettySSE .createHttpServer (port , (request , response ) -> {
20
+ return RxNetty .createHttpServer (port , (request , response ) -> {
20
21
// System.out.println("Server => Request: " + request.getPath());
21
22
try {
22
23
return handleRequest (request , response );
23
24
} catch (Throwable e ) {
24
25
e .printStackTrace ();
25
26
System .err .println ("Server => Error [" + request .getPath () + "] => " + e );
26
27
response .setStatus (HttpResponseStatus .BAD_REQUEST );
27
- return response .writeAndFlush ( new ServerSentEvent ( "1" , " data:" , " Error 500: Bad Request\n " + e .getMessage () + "\n " ) );
28
+ return response .writeStringAndFlush ( " data: Error 500: Bad Request\n " + e .getMessage () + "\n " );
28
29
}
29
- });
30
+ }, PipelineConfigurators .< ByteBuf > serveSseConfigurator () );
30
31
}
31
32
32
33
protected abstract Observable <Void > handleRequest (HttpServerRequest <?> request , HttpServerResponse <ServerSentEvent > response );
0 commit comments