public void handleFrame(StompFrame request) { StompFrame reply = null; if (stompListener != null) { stompListener.requestAccepted(request); } System.out.println("Frame::" + request); String cmd = request.getCommand(); try { if (isDestroyed()) { throw BUNDLE.connectionDestroyed().setHandler(frameHandler); } if (!initialized) { if (!(Stomp.Commands.CONNECT.equals(cmd) || Stomp.Commands.STOMP.equals(cmd))) { throw BUNDLE.connectionNotEstablished().setHandler(frameHandler); } // decide version negotiateVersion(request); } reply = frameHandler.handleFrame(request); } catch (ActiveMQStompException e) { reply = e.getFrame(); } if (reply != null) { sendFrame(reply); } if (Stomp.Commands.DISCONNECT.equals(cmd)) { this.disconnect(false); } }
public StompFrame decode(ActiveMQBuffer buffer) throws ActiveMQStompException { StompFrame frame = null; try { frame = frameHandler.decode(buffer); } catch (ActiveMQStompException e) { switch (e.getCode()) { case ActiveMQStompException.INVALID_EOL_V10: if (version != null) throw e; frameHandler = new StompFrameHandlerV12(this); buffer.resetReaderIndex(); frame = decode(buffer); break; case ActiveMQStompException.INVALID_COMMAND: frameHandler.onError(e); break; default: throw e; } } return frame; }
/* * accept-version value takes form of "v1,v2,v3..." * we need to return the highest supported version */ public void negotiateVersion(StompFrame frame) throws ActiveMQStompException { String acceptVersion = frame.getHeader(Stomp.Headers.ACCEPT_VERSION); if (acceptVersion == null) { this.version = StompVersions.V1_0; } else { StringTokenizer tokenizer = new StringTokenizer(acceptVersion, ","); Set<String> requestVersions = new HashSet<String>(tokenizer.countTokens()); while (tokenizer.hasMoreTokens()) { requestVersions.add(tokenizer.nextToken()); } if (requestVersions.contains(StompVersions.V1_2.toString())) { this.version = StompVersions.V1_2; } else if (requestVersions.contains(StompVersions.V1_1.toString())) { this.version = StompVersions.V1_1; } else if (requestVersions.contains(StompVersions.V1_0.toString())) { this.version = StompVersions.V1_0; } else { // not a supported version! ActiveMQStompException error = BUNDLE.versionNotSupported(acceptVersion).setHandler(frameHandler); error.addHeader(Stomp.Headers.Error.VERSION, manager.getSupportedVersionsAsErrorVersion()); error.addHeader(Stomp.Headers.CONTENT_TYPE, "text/plain"); error.setBody("Supported protocol versions are " + manager.getSupportedVersionsAsString()); error.setDisconnect(true); throw error; } } if (this.version != (StompVersions.V1_0)) { VersionedStompFrameHandler newHandler = VersionedStompFrameHandler.getHandler(this, this.version); newHandler.initDecoder(this.frameHandler); this.frameHandler = newHandler; } this.initialized = true; }
public StompFrame createStompMessage( ServerMessage serverMessage, StompSubscription subscription, int deliveryCount) throws Exception { return frameHandler.createMessageFrame(serverMessage, subscription, deliveryCount); }
public boolean hasBytes() { return frameHandler.hasBytes(); }