use of org.projectodd.sockjs.SockJsException in project AngularBeans by bessemHmidi.
the class SockJsServlet method service.
@Override
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
res.setHeader("Access-Control-Allow-Origin", "true");
log.log(Level.FINE, "SockJsServlet#service for {0} {1}", new Object[] { req.getMethod(), req.getPathInfo() });
AsyncContext asyncContext = req.startAsync();
// no timeout
asyncContext.setTimeout(0);
SockJsServletRequest sockJsReq = new SockJsServletRequest(req);
SockJsServletResponse sockJsRes = new SockJsServletResponse(res, asyncContext);
try {
sockJsServer.dispatch(sockJsReq, sockJsRes);
} catch (SockJsException ex) {
throw new ServletException("Error during SockJS request:", ex);
}
if ("application/x-www-form-urlencoded".equals(req.getHeader("Content-Type"))) {
// Let the servlet parse data and just pretend like we did
sockJsReq.onAllDataRead();
} else if (req.isAsyncStarted()) {
req.getInputStream().setReadListener(sockJsReq);
}
}
use of org.projectodd.sockjs.SockJsException 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());
}
Aggregations