use of javax.servlet.ReadListener in project lucene-solr by apache.
the class SolrRequestParserTest method testParameterIncompatibilityException1.
@Test
public void testParameterIncompatibilityException1() throws Exception {
HttpServletRequest request = getMock("/solr/select", "application/x-www-form-urlencoded", 100);
// we emulate Jetty that returns empty stream when parameters were parsed before:
when(request.getInputStream()).thenReturn(new ServletInputStream() {
@Override
public int read() {
return -1;
}
@Override
public boolean isFinished() {
return true;
}
@Override
public boolean isReady() {
return true;
}
@Override
public void setReadListener(ReadListener readListener) {
}
});
FormDataRequestParser formdata = new FormDataRequestParser(2048);
try {
formdata.parseParamsAndFillStreams(request, new ArrayList<ContentStream>());
fail("should throw SolrException");
} catch (SolrException solre) {
assertTrue(solre.getMessage().startsWith("Solr requires that request parameters"));
assertEquals(500, solre.code());
}
verify(request).getInputStream();
}
use of javax.servlet.ReadListener in project solo by b3log.
the class MetaWeblogAPITestCase method metaWeblog.
/**
* 手动构造rpc请求
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "init")
public void metaWeblog() throws Exception {
final HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getServletContext()).thenReturn(mock(ServletContext.class));
when(request.getRequestURI()).thenReturn("/apis/metaweblog");
when(request.getMethod()).thenReturn("POST");
// Date date = (Date) DateFormatUtils.ISO_DATETIME_FORMAT.parseObject("2004-05-03T17:30:08");
Date date = DateUtils.parseDate("20040503T17:30:08", new String[] { "yyyyMMdd'T'HH:mm:ss", "yyyyMMdd'T'HH:mm:ss'Z'" });
final class MockServletInputStream extends ServletInputStream {
private ByteArrayInputStream stream;
public MockServletInputStream(byte[] data) {
stream = new ByteArrayInputStream(data);
}
public int read() throws IOException {
return stream.read();
}
@Override
public boolean isFinished() {
return false;
}
@Override
public boolean isReady() {
return false;
}
@Override
public void setReadListener(ReadListener readListener) {
}
}
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>").append("<methodCall>").append("<methodName>metaWeblog.newPost</methodName>").append("<params>").append("<param>").append("<value><int>11</int></value>").append("</param>").append("<param>").append("<value><string>test@gmail.com</string></value>").append("</param>").append("<param>").append("<value><string>pass</string></value>").append("</param>").append("<param>").append("<value>").append("<struct>").append("<member>").append("<name>dateCreated</name>").append("<value><dateTime.iso8601>20040503T17:30:08</dateTime.iso8601></value>").append("</member>").append("<member>").append("<name>title</name>").append("<value><string>title</string></value>").append("</member>").append("<member>").append("<name>description</name>").append("<value><string>description</string></value>").append("</member>").append("</struct>").append("</value>").append("</param>").append("<param>").append("<value><boolean>1</boolean></value>").append("</param>").append("</params>").append("</methodCall>");
when(request.getInputStream()).thenReturn(new MockServletInputStream(sb.toString().getBytes()));
final MockDispatcherServlet dispatcherServlet = new MockDispatcherServlet();
dispatcherServlet.init();
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
final HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getWriter()).thenReturn(printWriter);
dispatcherServlet.service(request, response);
final String content = stringWriter.toString();
System.out.println("xxxxxcontent:" + content);
Assert.assertTrue(StringUtils.startsWith(content, "<?xml version=\"1.0\""));
}
use of javax.servlet.ReadListener in project wicket by apache.
the class MockHttpServletRequest method getInputStream.
/**
* Returns an input stream if there has been added some uploaded files. Use
* {@link #addFile(String, File, String)} to add some uploaded files.
*
* @return The input stream
* @throws IOException
* If an I/O related problem occurs
*/
@Override
public ServletInputStream getInputStream() throws IOException {
byte[] request = buildRequest();
// Ok lets make an input stream to return
final ByteArrayInputStream bais = new ByteArrayInputStream(request);
return new ServletInputStream() {
private boolean isFinished = false;
private boolean isReady = true;
@Override
public boolean isFinished() {
return isFinished;
}
@Override
public boolean isReady() {
return isReady;
}
@Override
public void setReadListener(ReadListener readListener) {
}
@Override
public int read() {
isFinished = true;
isReady = false;
return bais.read();
}
};
}
use of javax.servlet.ReadListener in project teiid by teiid.
the class TestGzipMessageRequest method prepareRequest.
@Before
public void prepareRequest() throws IOException {
streamBytes = new ByteArrayInputStream(TestGzipMessageResponse.TEST_STRING_IN_GZIP);
stream = new ServletInputStream() {
@Override
public boolean isReady() {
return true;
}
@Override
public boolean isFinished() {
return false;
}
@Override
public void setReadListener(ReadListener readListener) {
}
@Override
public int read() throws IOException {
return streamBytes.read();
}
};
request = new GzipMessageRequest(mockRequest(stream));
}
use of javax.servlet.ReadListener in project shijie by tengxing.
the class XssHttpServletRequestWrapper method getInputStream.
public ServletInputStream getInputStream() throws IOException {
if (!"application/json".equalsIgnoreCase(super.getHeader("Content-Type"))) {
return super.getInputStream();
} else {
String json = IOUtils.toString(super.getInputStream(), "utf-8");
if (StringUtils.isBlank(json)) {
return super.getInputStream();
} else {
json = this.xssEncode(json);
final ByteArrayInputStream bis = new ByteArrayInputStream(json.getBytes("utf-8"));
return new ServletInputStream() {
public boolean isFinished() {
return true;
}
public boolean isReady() {
return true;
}
public void setReadListener(ReadListener readListener) {
}
public int read() throws IOException {
return bis.read();
}
};
}
}
}
Aggregations