1313import org .lognet .springboot .grpc .demo .DemoApp ;
1414import org .springframework .boot .test .context .SpringBootTest ;
1515import org .springframework .boot .test .context .SpringBootTest .WebEnvironment ;
16+ import org .springframework .context .annotation .Bean ;
1617import org .springframework .context .annotation .Configuration ;
18+ import org .springframework .core .Ordered ;
1719import org .springframework .core .annotation .Order ;
1820import org .springframework .test .context .junit4 .SpringRunner ;
1921
@@ -44,7 +46,7 @@ public void setup() {
4446
4547 @ Override
4648 protected void afterGreeting () {
47- assertThat (calledInterceptors ).containsExactly (1 , 2 , 3 , 4 , 10 , 100 );
49+ assertThat (calledInterceptors ).containsExactly (1 , 2 , 3 , 4 ,5 , 10 , 100 );
4850 }
4951
5052
@@ -101,7 +103,7 @@ public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
101103 }
102104
103105 @ GRpcGlobalInterceptor
104- @ Order // no value means lowest priority amongst all @Ordered, but higher priority than iceptors without the annot
106+ @ Order // no value means lowest priority amongst all @Ordered, but higher priority than interceptors without the annotation
105107 static class DefaultOrderedInterceptor implements ServerInterceptor {
106108
107109 @ Override
@@ -123,5 +125,25 @@ public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
123125 return next .startCall (call , headers );
124126 }
125127 }
128+
129+ @ Bean
130+ @ GRpcGlobalInterceptor
131+ public ServerInterceptor myInterceptor (){
132+ return new MyInterceptor ();
133+ }
134+
135+ class MyInterceptor implements ServerInterceptor ,Ordered {
136+ @ Override
137+ public <ReqT , RespT > Listener <ReqT > interceptCall (ServerCall <ReqT , RespT > call , Metadata headers , ServerCallHandler <ReqT , RespT > next ) {
138+ calledInterceptors .add (5 );
139+ return next .startCall (call , headers );
140+ }
141+
142+ @ Override
143+ public int getOrder () {
144+ return 5 ;
145+ }
146+ }
147+
126148 }
127149}
0 commit comments