Search in sources :

Example 1 with SockJsException

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) SockJsException(org.projectodd.sockjs.SockJsException) AsyncContext(javax.servlet.AsyncContext)

Example 2 with SockJsException

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());
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) SockJsException(org.projectodd.sockjs.SockJsException) IOException(java.io.IOException)

Aggregations

SockJsException (org.projectodd.sockjs.SockJsException)2 IOException (java.io.IOException)1 AsyncContext (javax.servlet.AsyncContext)1 ServletException (javax.servlet.ServletException)1 ServletInputStream (javax.servlet.ServletInputStream)1