List of usage examples for javax.servlet ServletOutputStream ServletOutputStream
protected ServletOutputStream()
From source file:kziomek.filter.logging.TeeResponseWrapper.java
@Override public ServletOutputStream getOutputStream() throws IOException { return new ServletOutputStream() { @Override//from w ww .j a v a 2 s. c o m public boolean isReady() { return false; } @Override public void setWriteListener(WriteListener listener) { } private TeeOutputStream tee = new TeeOutputStream(TeeResponseWrapper.super.getOutputStream(), bos); @Override public void write(int b) throws IOException { tee.write(b); } }; }
From source file:appengine_commons.logger_filter.ResponseWrapper.java
@Override public ServletOutputStream getOutputStream() throws IOException { return new ServletOutputStream() { private TeeOutputStream tee = new TeeOutputStream(ResponseWrapper.super.getOutputStream(), bos); @Override//from www .j av a2s. co m public void write(int b) throws IOException { tee.write(b); } }; }
From source file:com.du.order.dist.log.ResponseWrapper.java
@Override public ServletOutputStream getOutputStream() throws IOException { return new ServletOutputStream() { @Override/*from w ww. j a va 2s. c o m*/ public boolean isReady() { return false; } @Override public void setWriteListener(WriteListener writeListener) { } private TeeOutputStream tee = new TeeOutputStream(ResponseWrapper.super.getOutputStream(), bos); @Override public void write(int b) throws IOException { tee.write(b); } }; }
From source file:eu.freme.broker.tools.loggingfilter.ResponseWrapper.java
@Override public ServletOutputStream getOutputStream() throws IOException { return new ServletOutputStream() { private TeeOutputStream tee = new TeeOutputStream(ResponseWrapper.super.getOutputStream(), bos); @Override/* w ww . jav a 2s .c o m*/ public void write(int b) throws IOException { tee.write(b); } @Override public void setWriteListener(WriteListener w) { } @Override public boolean isReady() { return true; } }; }
From source file:io.klerch.alexa.tellask.model.wrapper.AlexaSpeechletServletTest.java
private HttpServletResponse givenServletResponse(final OutputStream stream) throws Exception { final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); final ServletOutputStream servletOutputStream = new ServletOutputStream() { @Override/*from w ww. jav a 2s .c o m*/ public void write(int b) throws IOException { stream.write(b); } }; when(response.getOutputStream()).thenReturn(servletOutputStream); return response; }
From source file:org.esigate.servlet.impl.HttpServletSessionTest.java
/** * Ensure there is no exception when trying to create a session outside of a request (during background * revalidation). Expected behavior is no exception, but value not set. * /*from www. j a v a 2 s . c om*/ * @see "http://www.esigate.org/mantisbt/view.php?id=229" * @throws Exception */ public void testSetAttributeNoSession() throws Exception { HttpServletRequest request = new MockHttpServletRequestBuilder().protocolVersion("HTTP/1.0").method("GET") .session(null).build(); HttpServletResponse response = mock(HttpServletResponse.class); ServletOutputStream outputStream = new ServletOutputStream() { private ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); @Override public void write(int b) { this.byteOutputStream.write(b); } }; when(response.getOutputStream()).thenReturn(outputStream); ServletContext context = mock(ServletContext.class); RequestFactory requestFactory = new RequestFactory(context); IncomingRequest incomingRequest = requestFactory.create(request, response, null); ResponseSender renderer = new ResponseSender(); renderer.sendResponse(new HttpResponseBuilder().entity("Response").build(), incomingRequest, response); incomingRequest.getSession().setAttribute("test", "value"); // Previous method should have no effect since session cannot be // created. Assert.assertNull(incomingRequest.getSession().getAttribute("test")); }
From source file:com.fengduo.bee.commons.core.WebResponseWrapper.java
public ServletOutputStream getOutputStream() { if (isWriterUsed) { logger.error(// w w w . j a va 2 s. c om "Unexpected internal error during import: Target servlet called getOutputStream(), then getWriter()"); throw new IllegalStateException( "Unexpected internal error during import: Target servlet called getOutputStream(), then getWriter()"); } isStreamUsed = true; if (bos == null) { bos = new ByteArrayOutputStream(); } ServletOutputStream sos = new ServletOutputStream() { public void write(int b) throws IOException { bos.write(b); } @Override public boolean isReady() { return false; } @Override public void setWriteListener(WriteListener writeListener) { } }; return sos; }
From source file:org.apache.hadoop.gateway.dispatch.HttpClientDispatchTest.java
@Test public void testJiraKnox58() throws URISyntaxException, IOException { URI uri = new URI("http://unreachable-host"); BasicHttpParams params = new BasicHttpParams(); HttpUriRequest outboundRequest = EasyMock.createNiceMock(HttpUriRequest.class); EasyMock.expect(outboundRequest.getMethod()).andReturn("GET").anyTimes(); EasyMock.expect(outboundRequest.getURI()).andReturn(uri).anyTimes(); EasyMock.expect(outboundRequest.getParams()).andReturn(params).anyTimes(); HttpServletRequest inboundRequest = EasyMock.createNiceMock(HttpServletRequest.class); HttpServletResponse outboundResponse = EasyMock.createNiceMock(HttpServletResponse.class); EasyMock.expect(outboundResponse.getOutputStream()).andAnswer(new IAnswer<ServletOutputStream>() { @Override/*from w ww .j av a 2 s. c o m*/ public ServletOutputStream answer() throws Throwable { return new ServletOutputStream() { @Override public void write(int b) throws IOException { throw new IOException("unreachable-host"); } }; } }); EasyMock.replay(outboundRequest, inboundRequest, outboundResponse); HttpClientDispatch dispatch = new HttpClientDispatch(); try { dispatch.executeRequest(outboundRequest, inboundRequest, outboundResponse); fail("Should have thrown IOException"); } catch (IOException e) { assertThat(e.getMessage(), not(containsString("unreachable-host"))); assertThat(e, not(instanceOf(UnknownHostException.class))); assertThat("Message needs meaningful content.", e.getMessage().trim().length(), greaterThan(12)); } }
From source file:edu.utah.further.i2b2.hook.further.web.CapturedResponseWrapper.java
@Override public ServletOutputStream getOutputStream() throws IOException { return new ServletOutputStream() { @Override/*from www. j a v a 2 s . co m*/ public void write(final int b) throws IOException { baos.write(b); } }; }
From source file:com.google.jstestdriver.server.gateway.GatewayServletTest.java
License:asdf
public void testService_GET() throws Exception { expect(request.getMethod()).andStubReturn("GET"); expect(request.getRequestURI()).andStubReturn("/relativeUri"); expect(request.getHeaderNames())/*from w ww .jav a2 s .c om*/ .andStubReturn(Iterators.asEnumeration(ImmutableList.of("Host").iterator())); expect(request.getHeaders("Host")) .andStubReturn(Iterators.asEnumeration(ImmutableList.of("jstd:80").iterator())); expect(request.getQueryString()).andStubReturn("id=123"); // TODO(rdionne): Feed fake response values into the captured HttpMethod and assert they are // properly converted to equivalent HttpServletResponse fields. Capture<HttpMethodBase> methodCapture = new Capture<HttpMethodBase>(); expect(client.executeMethod(EasyMock.capture(methodCapture))).andStubReturn(200); /* expect */ response.setStatus(200); expect(request.getHeaders("Pragma")).andStubReturn(Iterators.asEnumeration(Iterators.emptyIterator())); final ByteArrayOutputStream output = new ByteArrayOutputStream(); ServletOutputStream out = new ServletOutputStream() { @Override public void write(int b) throws IOException { output.write(b); } }; expect(response.getOutputStream()).andStubReturn(out); control.replay(); gateway.handleIt(); assertEquals("GET", methodCapture.getValue().getName()); assertEquals("http://hostname/relativeUri?id=123", methodCapture.getValue().getURI().toString()); assertEquals("hostname:80", methodCapture.getValue().getRequestHeader("Host").getValue()); assertEquals("id=123", methodCapture.getValue().getQueryString()); assertEquals("", output.toString()); }