use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class SendErrorFilterTests method setResponseCode.
@Test
public void setResponseCode() {
SendErrorFilter filter = createSendErrorFilter(new MockHttpServletRequest());
filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
int resCode = ctx.getResponse().getStatus();
int ctxCode = ctx.getResponseStatusCode();
assertEquals("invalid response code: " + resCode, HttpStatus.NOT_FOUND.value(), resCode);
assertEquals("invalid response code in RequestContext: " + ctxCode, resCode, ctxCode);
}
use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class SendErrorFilterTests method setTestRequestcontext.
@Before
public void setTestRequestcontext() {
MonitoringHelper.initMocks();
RequestContext context = new RequestContext();
RequestContext.testSetCurrentContext(context);
}
use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class SendErrorFilterTests method createSendErrorFilter.
private SendErrorFilter createSendErrorFilter(HttpServletRequest request) {
RequestContext context = new RequestContext();
context.setRequest(request);
context.setResponse(new MockHttpServletResponse());
context.setThrowable(new ZuulException(new RuntimeException(), HttpStatus.NOT_FOUND.value(), null));
RequestContext.testSetCurrentContext(context);
SendErrorFilter filter = new SendErrorFilter();
filter.setErrorPath("/error");
return filter;
}
use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class SendResponseFilterTests method closeResponseOutputStreamError.
@Test
public void closeResponseOutputStreamError() throws Exception {
HttpServletResponse response = mock(HttpServletResponse.class);
InputStream mockStream = spy(new ByteArrayInputStream("Hello\n".getBytes("UTF-8")));
RequestContext context = new RequestContext();
context.setRequest(new MockHttpServletRequest());
context.setResponse(response);
context.setResponseDataStream(mockStream);
Closeable zuulResponse = mock(Closeable.class);
context.set("zuulResponse", zuulResponse);
RequestContext.testSetCurrentContext(context);
SendResponseFilter filter = new SendResponseFilter();
ServletOutputStream zuuloutputstream = mock(ServletOutputStream.class);
doThrow(new IOException("Response to client closed")).when(zuuloutputstream).write(isA(byte[].class), anyInt(), anyInt());
when(response.getOutputStream()).thenReturn(zuuloutputstream);
try {
filter.run();
} catch (UndeclaredThrowableException ex) {
assertThat(ex.getUndeclaredThrowable().getMessage(), is("Response to client closed"));
}
verify(zuulResponse).close();
verify(mockStream).close();
}
use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class SendResponseFilterTests method setTestRequestcontext.
@Before
public void setTestRequestcontext() {
RequestContext context = new RequestContext();
RequestContext.testSetCurrentContext(context);
}
Aggregations