use of javax.servlet.ServletInputStream in project nutz by nutzam.
the class UploadingUnitTest method test_cast_dt01.
@Test
public void test_cast_dt01() throws UploadException {
MockHttpServletRequest req = Mock.servlet.request();
req.setHeader("content-type", "multipart/form-data; boundary=----ESDT-321271401654cc6d669eef664aac");
Uploading up = UploadUnit.TYPE.born();
ServletInputStream ins = Mock.servlet.ins("org/nutz/mvc/upload/files/cast_dt01");
req.setInputStream(ins);
req.init();
Map<String, Object> map = up.parse(req, UploadingContext.create(tmps));
assertEquals(1, map.size());
assertEquals("Shapes100.jpg", ((TempFile) map.get("fileData")).getSubmittedFileName());
}
use of javax.servlet.ServletInputStream in project OpenRefine by OpenRefine.
the class RefineBrokerTests method call.
private JSONObject call(boolean successful, RefineBroker broker, HttpServletRequest request, HttpServletResponse response, String service, String... params) throws Exception {
if (params != null) {
for (int i = 0; i < params.length; ) {
String name = params[i++];
String value = params[i++];
if ("data".equals(name)) {
final ByteArrayInputStream inputStream = new ByteArrayInputStream(value.getBytes("UTF-8"));
when(request.getInputStream()).thenReturn(new ServletInputStream() {
public int read() throws IOException {
return inputStream.read();
}
});
} else {
when(request.getParameter(name)).thenReturn(value);
}
}
}
StringWriter writer = new StringWriter();
when(response.getWriter()).thenReturn(new PrintWriter(writer));
broker.process(service, request, response);
JSONObject result = new JSONObject(writer.toString());
if (successful) {
assertJSON(result, "status", "ok");
} else {
assertJSON(result, "status", "error");
}
logger.info(result.toString());
return result;
}
use of javax.servlet.ServletInputStream in project undertow by undertow-io.
the class ServletWebSocketHttpExchange method readRequestData.
@Override
public IoFuture<byte[]> readRequestData() {
final ByteArrayOutputStream data = new ByteArrayOutputStream();
try {
final ServletInputStream in = request.getInputStream();
byte[] buf = new byte[1024];
int r;
while ((r = in.read(buf)) != -1) {
data.write(buf, 0, r);
}
return new FinishedIoFuture<>(data.toByteArray());
} catch (IOException e) {
final FutureResult<byte[]> ioFuture = new FutureResult<>();
ioFuture.setException(e);
return ioFuture.getIoFuture();
}
}
use of javax.servlet.ServletInputStream in project undertow by undertow-io.
the class BlockingInputStreamServlet method doPost.
@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ServletInputStream inputStream = req.getInputStream();
byte[] buf = new byte[1024];
int read;
while ((read = inputStream.read(buf)) != -1) {
out.write(buf, 0, read);
}
resp.getOutputStream().write(out.toByteArray());
}
use of javax.servlet.ServletInputStream in project undertow by undertow-io.
the class EarlyCloseClientServlet method doPost.
@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
try {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ServletInputStream inputStream = req.getInputStream();
byte[] buf = new byte[1024];
int read;
while ((read = inputStream.read(buf)) != -1) {
out.write(buf, 0, read);
}
resp.getOutputStream().write(out.toByteArray());
completedNormally = true;
} catch (IOException e) {
exceptionThrown = true;
} finally {
latch.countDown();
}
}
Aggregations