Search in sources :

Example 1 with StompOutputHandler

use of com.sun.messaging.bridge.api.StompOutputHandler in project openmq by eclipse-ee4j.

the class StompMessageDispatchFilter method handleRead.

@Override
public NextAction handleRead(final FilterChainContext ctx) throws IOException {
    synchronized (this) {
        if (_bc == null || _jmsprop == null || _logger == null || _sbr == null) {
            if (_logger != null) {
                _logger.log(Level.WARNING, "Stomp service not ready yet");
            }
            throw new IOException("Stomp service not ready yet");
        }
    }
    StompProtocolHandlerImpl sph = null;
    try {
        final StompFrameMessage msg = ctx.getMessage();
        sph = (StompProtocolHandlerImpl) ctx.getAttributes().getAttribute(StompMessageFilter.STOMP_PROTOCOL_HANDLER);
        switch(msg.getCommand()) {
            case CONNECT:
            case STOMP:
                sph.onCONNECT(msg, this, ctx);
                break;
            case SEND:
                sph.onSEND(msg, this, ctx);
                break;
            case SUBSCRIBE:
                StompOutputHandler soh = new AsyncStompOutputHandler(ctx, sph);
                sph.onSUBSCRIBE(msg, this, soh, ctx);
                return ctx.getForkAction();
            case UNSUBSCRIBE:
                sph.onUNSUBSCRIBE(msg, this, ctx);
                break;
            case BEGIN:
                sph.onBEGIN(msg, this, ctx);
                break;
            case COMMIT:
                sph.onCOMMIT(msg, this, ctx);
                break;
            case ABORT:
                sph.onABORT(msg, this, ctx);
                break;
            case ACK:
                sph.onACK(msg, this, ctx);
                break;
            case DISCONNECT:
                sph.onDISCONNECT(msg, this, ctx);
                break;
            case ERROR:
                sendToClient(msg, sph, ctx);
                break;
            default:
                throw new IOException(((StompFrameMessageImpl) msg).getKStringX_UNKNOWN_STOMP_CMD(msg.getCommand().toString()));
        }
    } catch (Throwable t) {
        _logger.log(Level.SEVERE, t.getMessage(), t);
        try {
            StompFrameMessage err = sph.toStompErrorMessage("StompProtocolFilter", t, (t instanceof IOException));
            sendToClient(err, sph, ctx);
        } catch (Exception e) {
            _logger.log(Level.SEVERE, _sbr.getKString(_sbr.E_UNABLE_SEND_ERROR_MSG, t.toString(), e.toString()), e);
        }
    }
    return ctx.getInvokeAction();
}
Also used : StompOutputHandler(com.sun.messaging.bridge.api.StompOutputHandler) StompFrameMessage(com.sun.messaging.bridge.api.StompFrameMessage) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

StompFrameMessage (com.sun.messaging.bridge.api.StompFrameMessage)1 StompOutputHandler (com.sun.messaging.bridge.api.StompOutputHandler)1 IOException (java.io.IOException)1