List of usage examples for javax.servlet ServletInputStream ServletInputStream
protected ServletInputStream()
From source file:com.nesscomputing.tracking.MockedHttpServletRequest.java
@Override public ServletInputStream getInputStream() throws IOException { final InputStream stream = new NullInputStream(getContentLength()); return new ServletInputStream() { @Override//from ww w . j a v a 2s. c o m public int read() throws IOException { return stream.read(); } }; }
From source file:com.opentable.requestid.MockedHttpServletRequest.java
@Override public ServletInputStream getInputStream() throws IOException { @SuppressWarnings("resource") final InputStream stream = new NullInputStream(getContentLength()); return new ServletInputStream() { @Override//from w w w . j a v a 2s .c om public int read() throws IOException { return stream.read(); } @Override public boolean isFinished() { throw new UnsupportedOperationException(); } @Override public boolean isReady() { return true; } @Override public void setReadListener(ReadListener readListener) { throw new UnsupportedOperationException(); } }; }
From source file:io.wcm.caravan.io.http.impl.servletclient.HttpServletRequestMapper.java
@Override public ServletInputStream getInputStream() throws IOException { return new ServletInputStream() { private int index; @Override/*from ww w. j ava2 s . c o m*/ public int read() throws IOException { return index < request.getBody().length ? -1 : request.getBody()[index++]; } }; }
From source file:eu.impact_project.iif.t2.client.HelperTest.java
/** * Test of parseRequest method, of class Helper. *///w w w . ja va2 s . c o m @Test public void testParseRequest() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); URL url = this.getClass().getResource("/prueba.txt"); File testFile = new File(url.getFile()); Part[] parts = new Part[] { new StringPart("user", "user"), new FilePart("file_workflow", testFile), new FilePart("comon_file", testFile) }; MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts, new PostMethod().getParams()); ByteArrayOutputStream requestContent = new ByteArrayOutputStream(); multipartRequestEntity.writeRequest(requestContent); final ByteArrayInputStream inputContent = new ByteArrayInputStream(requestContent.toByteArray()); when(request.getInputStream()).thenReturn(new ServletInputStream() { @Override public int read() throws IOException { return inputContent.read(); } }); when(request.getContentType()).thenReturn(multipartRequestEntity.getContentType()); Helper.parseRequest(request); }
From source file:com.sixt.service.framework.servicetest.mockservice.MockHttpServletRequest.java
@Override public ServletInputStream getInputStream() throws IOException { final ByteArrayInputStream stream = new ByteArrayInputStream(postBody); return new ServletInputStream() { @Override//from ww w. j a v a 2s. c o m public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public void setReadListener(ReadListener readListener) { } @Override public int read() throws IOException { return stream.read(); } }; }
From source file:eu.impact_project.iif.t2.client.WorkflowRunnerTest.java
/** * Test of doPost method, of class WorkflowRunner. *///from w w w . j a v a 2 s .c o m @Test public void testDoPost() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); ServletConfig config = mock(ServletConfig.class); ServletContext context = mock(ServletContext.class); RequestDispatcher dispatcher = mock(RequestDispatcher.class); ServletOutputStream stream = mock(ServletOutputStream.class); HttpSession session = mock(HttpSession.class); when(request.getSession(true)).thenReturn(session); ArrayList<Workflow> flowList = new ArrayList<>(); Workflow flow = new Workflow(); flow.setStringVersion("Esto es una prueba"); flow.setWsdls("<wsdl>http://www.ua.es</wsdl>"); flow.setUrls("http://www.ua.es"); ArrayList<WorkflowInput> flowInputs = new ArrayList<>(); WorkflowInput input = new WorkflowInput("pru0Input"); input.setDepth(1); flowInputs.add(input); input = new WorkflowInput("pru1Input"); input.setDepth(0); flowInputs.add(input); flow.setInputs(flowInputs); flowList.add(flow); when(session.getAttribute("workflows")).thenReturn(flowList); when(config.getServletContext()).thenReturn(context); URL url = this.getClass().getResource("/config.properties"); File testFile = new File(url.getFile()); when(context.getRealPath("/")).thenReturn(testFile.getParent() + "/"); Part[] parts = new Part[] { new StringPart("user", "user"), new StringPart("pass", "pass"), new StringPart("workflow0pru0Input", "prueba0"), new StringPart("workflow0pru0Input0", "prueba0.0"), new StringPart("workflow0pru1Input", "prueba1") }; MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts, new PostMethod().getParams()); ByteArrayOutputStream requestContent = new ByteArrayOutputStream(); multipartRequestEntity.writeRequest(requestContent); final ByteArrayInputStream inputContent = new ByteArrayInputStream(requestContent.toByteArray()); when(request.getInputStream()).thenReturn(new ServletInputStream() { @Override public int read() throws IOException { return inputContent.read(); } }); when(request.getContentType()).thenReturn(multipartRequestEntity.getContentType()); WorkflowRunner runer = new WorkflowRunner(); try { runer.init(config); runer.doPost(request, response); } catch (ServletException ex) { fail("Should not raise exception " + ex.toString()); } catch (IOException ex) { fail("Should not raise exception " + ex.toString()); } catch (NullPointerException ex) { //ok no funciona el server de taverna } }
From source file:de.micromata.genome.test.web.SimHttpServletRequest.java
protected void setInputStream(final InputStream servletIs) { this.servletIs = new ServletInputStream() { public int available() throws IOException { return servletIs.available(); }/* ww w. j a v a 2 s . c o m*/ public void close() throws IOException { servletIs.close(); } public boolean equals(Object obj) { return servletIs.equals(obj); } public int hashCode() { return servletIs.hashCode(); } public void mark(int readlimit) { servletIs.mark(readlimit); } public boolean markSupported() { return servletIs.markSupported(); } public int read(byte[] b, int off, int len) throws IOException { return servletIs.read(b, off, len); } public int read(byte[] b) throws IOException { return servletIs.read(b); } public void reset() throws IOException { servletIs.reset(); } public long skip(long n) throws IOException { return servletIs.skip(n); } public String toString() { return servletIs.toString(); } @Override public int read() throws IOException { throw new UnsupportedOperationException(); } }; }
From source file:com.google.jstestdriver.server.gateway.GatewayServletTest.java
License:asdf
public void testService_POST() throws Exception { expect(request.getMethod()).andStubReturn("POST"); expect(request.getRequestURI()).andStubReturn("/relativeUri"); final ByteArrayInputStream input = new ByteArrayInputStream("ASDF".getBytes()); ServletInputStream in = new ServletInputStream() { @Override//from w ww . j a v a 2 s.c o m public int read() throws IOException { return input.read(); } }; expect(request.getInputStream()).andStubReturn(in); expect(request.getHeaderNames()) .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(); ByteArrayOutputStream requestBody = new ByteArrayOutputStream(); ((EntityEnclosingMethod) methodCapture.getValue()).getRequestEntity().writeRequest(requestBody); assertEquals("POST", 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("ASDF", requestBody.toString()); assertEquals("", output.toString()); }
From source file:nl.armatiek.xslweb.web.servlet.XSLWebHttpServletRequest.java
@Override public ServletInputStream getInputStream() throws IOException { return new ServletInputStream() { @Override//w w w .ja va 2 s .c om public int read() throws IOException { return -1; } }; }
From source file:io.klerch.alexa.tellask.model.wrapper.AlexaSpeechletServletTest.java
private SpeechletResponseEnvelope doPost(final AlexaSpeechletServlet servlet, final SpeechletRequestEnvelope envelope) throws Exception { final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final InputStream stream = convertToStream(envelope); final ServletInputStream servletInputStream = new ServletInputStream() { @Override/*from www .j a v a 2s. c o m*/ public int read() throws IOException { return stream.read(); } }; when(request.getInputStream()).thenReturn(servletInputStream); when(request.getReader()).thenReturn(new BufferedReader(new InputStreamReader(stream))); final ByteArrayOutputStream responseStream = new ByteArrayOutputStream(); final HttpServletResponse response = givenServletResponse(responseStream); servlet.doPost(request, response); return convertToResponseEnvelope(responseStream); }