use of javax.servlet.ServletInputStream in project AngularBeans by bessemHmidi.
the class SockJsServletRequest method onDataAvailable.
@Override
public void onDataAvailable() throws IOException {
ServletInputStream inputStream = request.getInputStream();
do {
while (!inputStream.isReady()) {
//
}
byte[] buffer = new byte[1024 * 4];
int length = inputStream.read(buffer);
if (length > 0) {
if (onDataHandler != null) {
try {
onDataHandler.handle(Arrays.copyOf(buffer, length));
} catch (SockJsException e) {
throw new IOException(e);
}
}
}
} while (inputStream.isReady());
}
use of javax.servlet.ServletInputStream in project opennms by OpenNMS.
the class RTCPostServlet method doPost.
/**
* {@inheritDoc}
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// the path info will be the category name we need
String pathInfo = request.getPathInfo();
// info
if (pathInfo == null) {
LOG.error("Request with no path info");
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No Category name given in path");
return;
}
// remove the preceding slash if present
if (pathInfo.startsWith("/")) {
pathInfo = pathInfo.substring(1, pathInfo.length());
}
// since these category names can contain spaces, etc,
// we have to URL encode them in the URL
String categoryName = Util.decode(pathInfo);
org.opennms.netmgt.xml.rtc.Category category = null;
try (ServletInputStream inStream = request.getInputStream();
InputStreamReader isr = new InputStreamReader(inStream)) {
org.opennms.netmgt.xml.rtc.EuiLevel level = JaxbUtils.unmarshal(org.opennms.netmgt.xml.rtc.EuiLevel.class, isr);
// for now we only deal with the first category, they're only sent
// one
// at a time anyway
category = level.getCategory().get(0);
}
// for the categoryname in the path info
if (!categoryName.equals(category.getCatlabel())) {
LOG.error("Request did not supply information for category specified in path info");
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No category info found for " + categoryName);
return;
}
// update the category information in the CategoryModel
this.model.updateCategory(category);
// return a success message
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println("Category data parsed successfully.");
out.close();
LOG.info("Successfully received information for {}", categoryName);
}
use of javax.servlet.ServletInputStream in project Lucee by lucee.
the class HTTPServletRequestWrap method getInputStream.
@Override
public ServletInputStream getInputStream() throws IOException {
// if(ba rr!=null) throw new IllegalStateException();
if (barr == null) {
if (!firstRead) {
PageContext pc = ThreadLocalPageContext.get();
if (pc != null) {
return pc.formScope().getInputStream();
}
// throw new IllegalStateException();
return new ServletInputStreamDummy(new byte[] {});
}
firstRead = false;
if (isToBig(getContentLength())) {
return req.getInputStream();
}
InputStream is = null;
try {
barr = IOUtil.toBytes(is = req.getInputStream());
// Resource res = ResourcesImpl.getFileResourceProvider().getResource("/Users/mic/Temp/multipart.txt");
// IOUtil.copy(new ByteArrayInputStream(barr), res, true);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
barr = null;
return new ServletInputStreamDummy(new byte[] {});
} finally {
IOUtil.closeEL(is);
}
}
return new ServletInputStreamDummy(barr);
}
use of javax.servlet.ServletInputStream in project tomee by apache.
the class ServerServlet method service.
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!activated) {
response.getWriter().write("");
return;
}
ServletInputStream in = request.getInputStream();
ServletOutputStream out = response.getOutputStream();
try {
RequestInfos.initRequestInfo(request);
ejbServer.service(in, out);
} catch (ServiceException e) {
throw new ServletException("ServerService error: " + ejbServer.getClass().getName() + " -- " + e.getMessage(), e);
} finally {
RequestInfos.clearRequestInfo();
}
}
use of javax.servlet.ServletInputStream in project jetty.project by eclipse.
the class ClientConnectionCloseTest method test_ClientConnectionClose_ServerPartialResponse_ClientIdleTimeout.
@Test
public void test_ClientConnectionClose_ServerPartialResponse_ClientIdleTimeout() throws Exception {
long idleTimeout = 1000;
start(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
ServletInputStream input = request.getInputStream();
while (true) {
int read = input.read();
if (read < 0)
break;
}
response.getOutputStream().print("Hello");
response.flushBuffer();
try {
Thread.sleep(2 * idleTimeout);
} catch (InterruptedException x) {
throw new InterruptedIOException();
}
}
});
String host = "localhost";
int port = connector.getLocalPort();
HttpDestinationOverHTTP destination = (HttpDestinationOverHTTP) client.getDestination(scheme, host, port);
DuplexConnectionPool connectionPool = (DuplexConnectionPool) destination.getConnectionPool();
DeferredContentProvider content = new DeferredContentProvider(ByteBuffer.allocate(8));
CountDownLatch resultLatch = new CountDownLatch(1);
client.newRequest(host, port).scheme(scheme).header(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.asString()).content(content).idleTimeout(idleTimeout, TimeUnit.MILLISECONDS).onRequestSuccess(request -> {
HttpConnectionOverHTTP connection = (HttpConnectionOverHTTP) connectionPool.getActiveConnections().iterator().next();
Assert.assertFalse(connection.getEndPoint().isOutputShutdown());
}).send(result -> {
if (result.isFailed())
resultLatch.countDown();
});
content.offer(ByteBuffer.allocate(8));
content.close();
Assert.assertTrue(resultLatch.await(2 * idleTimeout, TimeUnit.MILLISECONDS));
Assert.assertEquals(0, connectionPool.getConnectionCount());
}
Aggregations