org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException Java Examples
The following examples show how to use
org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceAuthenticationFilterTest.java From api-layer with Eclipse Public License 2.0 | 6 votes |
@Test public void givenValidJwt_whenCommandFailed_thenInternalError() { String jwtToken = "validJwtToken"; AuthenticationCommand cmd = createJwtValidationCommand(jwtToken); doThrow(new RuntimeException()).when(cmd).apply(null); doReturn(TokenAuthentication.createAuthenticated("user", jwtToken)).when(authenticationService).validateJwtToken(jwtToken); CounterFactory.initialize(new CounterFactory() { @Override public void increment(String name) { } }); try { serviceAuthenticationFilter.run(); fail(); } catch (ZuulRuntimeException zre) { assertTrue(zre.getCause() instanceof ZuulException); ZuulException ze = (ZuulException) zre.getCause(); assertEquals(500, ze.nStatusCode); } }
Example #2
Source File: CustomSendErrorFilter.java From heimdall with Apache License 2.0 | 6 votes |
public ZuulException getZuulException(Throwable throwable) { if (throwable.getCause() instanceof ZuulRuntimeException) { // this was a failure initiated by one of the local filters return (ZuulException) throwable.getCause().getCause(); } if (throwable.getCause() instanceof ZuulException) { // wrapped zuul exception return (ZuulException) throwable.getCause(); } if (throwable instanceof ZuulException) { // exception thrown by zuul lifecycle return (ZuulException) throwable; } // fallback, should never get here return new ZuulException(throwable, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null); }
Example #3
Source File: AbstractLimiterZuulFilter.java From onetwo with Apache License 2.0 | 6 votes |
@Override public Object run() { InvokeContext invokeContext = createInvokeContext(); for(InvokeLimiter limiter : limiters){ try { if(limiter.match(invokeContext)){ limiter.consume(invokeContext); } } catch (LimitInvokeException e) { ZuulException ze = new ZuulException(e, HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); throw new ZuulRuntimeException(ze); } } return null; }
Example #4
Source File: CustomErrorZuulFilter.java From api-gateway-old with Apache License 2.0 | 5 votes |
ZuulException findZuulException(Throwable throwable) { if (throwable.getCause() instanceof ZuulRuntimeException) { return (ZuulException) throwable.getCause().getCause(); } if (throwable.getCause() instanceof ZuulException) { return (ZuulException) throwable.getCause(); } if (throwable instanceof ZuulException) { return (ZuulException) throwable; } return new ZuulException(throwable, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null); }
Example #5
Source File: ServiceAuthenticationFilterTest.java From api-layer with Eclipse Public License 2.0 | 4 votes |
@Test public void testRun() { Mockito.when(serviceAuthenticationService.getAuthenticationCommand(anyString(), any())).thenReturn(command); HttpServletRequest request = mock(HttpServletRequest.class); RequestContext requestContext = mock(RequestContext.class); when(requestContext.getRequest()).thenReturn(request); when(requestContext.get(SERVICE_ID_KEY)).thenReturn("service"); RequestContext.testSetCurrentContext(requestContext); when(authenticationService.getJwtTokenFromRequest(any())).thenReturn(Optional.of("token")); serviceAuthenticationFilter.run(); verify(serviceAuthenticationService, times(1)).getAuthenticationCommand("service", "token"); verify(command, times(1)).apply(null); when(authenticationService.getJwtTokenFromRequest(any())).thenReturn(Optional.empty()); serviceAuthenticationFilter.run(); verify(serviceAuthenticationService, times(1)).getAuthenticationCommand("service", null); verify(serviceAuthenticationService, times(2)).getAuthenticationCommand(anyString(), any()); reset(requestContext); reset(authenticationService); CounterFactory.initialize(new CounterFactory() { @Override public void increment(String name) { } }); when(requestContext.get(SERVICE_ID_KEY)).thenReturn("error"); when(authenticationService.getJwtTokenFromRequest(any())).thenReturn(Optional.of("token")); when(serviceAuthenticationService.getAuthenticationCommand(eq("error"), any())) .thenThrow(new RuntimeException("Potential exception")); try { serviceAuthenticationFilter.run(); fail(); } catch (ZuulRuntimeException zre) { assertTrue(zre.getCause() instanceof ZuulException); ZuulException ze = (ZuulException) zre.getCause(); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), ze.nStatusCode); assertEquals(String.valueOf(new RuntimeException("Potential exception")), ze.errorCause); } }