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); } }
@Override public String getDetailedReport(String delimiter) { Map<String, String> tags = new HashMap<String, String>(); tags.put(LF, delimiter); if (!propertiesToModify.isEmpty()) { StringBuilder sb = new StringBuilder(); for (Entry<String, String> entry : propertiesToModify.entrySet()) { sb.append(BULLET) .append(BUNDLE.getString("upgrade.instance")) .append(": ") .append(entry.getKey()) .append(' '); sb.append(BUNDLE.getString("upgrade.modattr")).append(": ").append(entry.getValue()); if (entry.getKey().equals(ServerConfiguration.DEFAULT_SERVER_CONFIG)) { sb.append(' ').append(BUNDLE.getString("upgrade.default.update")); } sb.append(delimiter); } sb.append(BULLET) .append(BUNDLE.getString("upgrade.delattr")) .append(": ") .append(CTS_STORE_PORT) .append(delimiter); tags.put(MOD_ATTRS, sb.toString()); } else { tags.put(MOD_ATTRS, BUNDLE.getString("upgrade.none")); } return tagSwapReport(tags, "upgrade.cts.propertiesreport"); }
public void acknowledge(String messageID, String subscriptionID) throws Exception { long id = Long.parseLong(messageID); Pair<Long, Integer> pair = messagesToAck.remove(id); if (pair == null) { throw BUNDLE.failToAckMissingID(id); } long consumerID = pair.getA(); int credits = pair.getB(); StompSubscription sub = subscriptions.get(consumerID); if (subscriptionID != null) { if (!sub.getID().equals(subscriptionID)) { throw BUNDLE.subscriptionIDMismatch(subscriptionID, sub.getID()); } } if (this.consumerCredits != -1) { session.receiveConsumerCredits(consumerID, credits); } if (sub.getAck().equals(Stomp.Headers.Subscribe.AckModeValues.CLIENT_INDIVIDUAL)) { session.individualAcknowledge(consumerID, id); } else { session.acknowledge(consumerID, id); } session.commit(); }
@Override public String getShortReport(String delimiter) { StringBuilder sb = new StringBuilder(); sb.append(BUNDLE.getString("upgrade.cts.property")).append(": "); if (!propertiesToModify.isEmpty()) { sb.append(BUNDLE.getString("upgrade.updated")) .append(" (") .append(propertiesToModify.size()) .append(')'); } sb.append(delimiter); return sb.toString(); }
// reject if the host doesn't match public void setHost(String host) throws ActiveMQStompException { if (host == null) { ActiveMQStompException error = BUNDLE.nullHostHeader().setHandler(frameHandler); error.setBody(BUNDLE.hostCannotBeNull()); throw error; } String localHost = manager.getVirtualHostName(); if (!host.equals(localHost)) { ActiveMQStompException error = BUNDLE.hostNotMatch().setHandler(frameHandler); error.setBody(BUNDLE.hostNotMatchDetails(host)); throw error; } }
public ConnectionEntry createConnectionEntry( final Acceptor acceptorUsed, final Connection connection) { StompConnection conn = new StompConnection(acceptorUsed, connection, this); // Note that STOMP 1.0 has no heartbeat, so if connection ttl is non zero, data must continue to // be sent or connection // will be timed out and closed! String ttlStr = (String) acceptorUsed.getConfiguration().get(TransportConstants.CONNECTION_TTL); Long ttl = ttlStr == null ? null : Long.valueOf(ttlStr); if (ttl != null) { if (ttl > 0) { return new ConnectionEntry(conn, null, System.currentTimeMillis(), ttl); } throw BUNDLE.negativeConnectionTTL(ttl); } ttl = server.getConfiguration().getConnectionTTLOverride(); if (ttl != -1) { return new ConnectionEntry(conn, null, System.currentTimeMillis(), ttl); } else { // Default to 1 minute - which is same as core protocol return new ConnectionEntry(conn, null, System.currentTimeMillis(), 1 * 60 * 1000); } }
public void commitTransaction(String txID) throws ActiveMQStompException { try { manager.commitTransaction(this, txID); } catch (Exception e) { throw BUNDLE.errorCommitTx(txID, e).setHandler(frameHandler); } }
public void addSubscription( long consumerID, String subscriptionID, String clientID, String durableSubscriptionName, String destination, String selector, String ack) throws Exception { SimpleString queue = SimpleString.toSimpleString(destination); int receiveCredits = consumerCredits; if (ack.equals(Stomp.Headers.Subscribe.AckModeValues.AUTO)) { receiveCredits = -1; } if (destination.startsWith("jms.topic")) { // subscribes to a topic if (durableSubscriptionName != null) { if (clientID == null) { throw BUNDLE.missingClientID(); } queue = SimpleString.toSimpleString(clientID + "." + durableSubscriptionName); QueueQueryResult query = session.executeQueueQuery(queue); if (!query.isExists()) { session.createQueue( SimpleString.toSimpleString(destination), queue, SimpleString.toSimpleString(selector), false, true); } } else { queue = UUIDGenerator.getInstance().generateSimpleStringUUID(); session.createQueue( SimpleString.toSimpleString(destination), queue, SimpleString.toSimpleString(selector), true, false); } ((ServerSessionImpl) session) .createConsumer(consumerID, queue, null, false, false, receiveCredits); } else { ((ServerSessionImpl) session) .createConsumer( consumerID, queue, SimpleString.toSimpleString(selector), false, false, receiveCredits); } StompSubscription subscription = new StompSubscription(subscriptionID, ack); subscriptions.put(consumerID, subscription); session.start(); }
public void checkDestination(String destination) throws ActiveMQStompException { if (autoCreateQueueIfPossible(destination)) { return; } if (!manager.destinationExists(destination)) { throw BUNDLE.destinationNotExist(destination).setHandler(frameHandler); } }
public void acknowledge(String messageID, String subscriptionID) throws ActiveMQStompException { try { manager.acknowledge(this, messageID, subscriptionID); } catch (ActiveMQStompException e) { throw e; } catch (Exception e) { throw BUNDLE.errorAck(messageID, e).setHandler(frameHandler); } }
protected void beginTransaction(String txID) throws ActiveMQStompException { try { manager.beginTransaction(this, txID); } catch (ActiveMQStompException e) { throw e; } catch (Exception e) { throw BUNDLE.errorBeginTx(txID, e).setHandler(frameHandler); } }
public void unsubscribe(String subscriptionID, String durableSubscriberName) throws ActiveMQStompException { try { manager.unsubscribe(this, subscriptionID, durableSubscriberName); } catch (ActiveMQStompException e) { throw e; } catch (Exception e) { throw BUNDLE.errorUnsubscrib(subscriptionID, e).setHandler(frameHandler); } }
void subscribe( String destination, String selector, String ack, String id, String durableSubscriptionName, boolean noLocal) throws ActiveMQStompException { autoCreateQueueIfPossible(destination); if (noLocal) { String noLocalFilter = CONNECTION_ID_PROP + " <> '" + getID().toString() + "'"; if (selector == null) { selector = noLocalFilter; } else { selector += " AND " + noLocalFilter; } } if (ack == null) { ack = Stomp.Headers.Subscribe.AckModeValues.AUTO; } String subscriptionID = null; if (id != null) { subscriptionID = id; } else { if (destination == null) { throw BUNDLE.noDestination().setHandler(frameHandler); } subscriptionID = "subscription/" + destination; } try { manager.createSubscription( this, subscriptionID, durableSubscriptionName, destination, selector, ack, noLocal); } catch (ActiveMQStompException e) { throw e; } catch (Exception e) { throw BUNDLE.errorCreatSubscription(subscriptionID, e).setHandler(frameHandler); } }
public StompSession getSession(String txID) throws ActiveMQStompException { StompSession session = null; try { if (txID == null) { session = manager.getSession(this); } else { session = manager.getTransactedSession(this, txID); } } catch (Exception e) { throw BUNDLE.errorGetSession(e).setHandler(frameHandler); } return session; }
@Override public String execute(HttpServletRequest request) { String url = BUNDLE.getString("edit_issue"); String summary = request.getParameter(PARAM_SUMMARY); String issueID = request.getParameter(PARAM_ISSUE_ID); try { if (summary != null) { Issue issue = new Issue(); request.setAttribute("issueUpdated", true); request.setAttribute("formNotFilled", false); issue = initIssue(request, issueID); updateIssue(request, issue, issueID); } else { setFieldsToRequest(request); request.setAttribute("formNotFilled", true); } } catch (LogicException ex) { LOG.error(ex); request.setAttribute("exception", ex); url = BUNDLE.getString(ERROR); } return url; }
protected void sendServerMessage(ServerMessageImpl message, String txID) throws ActiveMQStompException { StompSession stompSession = getSession(txID); if (stompSession.isNoLocal()) { message.putStringProperty(CONNECTION_ID_PROP, getID().toString()); } if (enableMessageID()) { message.putStringProperty("amqMessageId", "STOMP" + message.getMessageID()); } try { if (minLargeMessageSize == -1 || (message.getBodyBuffer().writerIndex() < minLargeMessageSize)) { stompSession.sendInternal(message, false); } else { stompSession.sendInternalLarge(message, false); } } catch (Exception e) { throw BUNDLE.errorSendMessage(message, e).setHandler(frameHandler); } }
/* * 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 void sendInternalLarge(ServerMessageImpl message, boolean direct) throws Exception { int headerSize = message.getHeadersAndPropertiesEncodeSize(); if (headerSize >= connection.getMinLargeMessageSize()) { throw BUNDLE.headerTooBig(); } StorageManager storageManager = ((ServerSessionImpl) session).getStorageManager(); long id = storageManager.generateUniqueID(); LargeServerMessage largeMessage = storageManager.createLargeMessage(id, message); byte[] bytes = new byte[message.getBodyBuffer().writerIndex() - MessageImpl.BODY_OFFSET]; message.getBodyBuffer().readBytes(bytes); largeMessage.addBytes(bytes); largeMessage.releaseResources(); largeMessage.putLongProperty(Message.HDR_LARGE_BODY_SIZE, bytes.length); session.send(largeMessage, direct); largeMessage = null; }
protected void validate() throws ActiveMQStompException { if (!this.valid) { throw BUNDLE.invalidConnection().setHandler(frameHandler); } }
public String getInfoWindow() { return BUNDLE.getString("register.transaction.isPossibilityDeleteTransaction"); }
/** * Return a new pointer with another pointer appended * * @param other the other pointer * @return a new pointer * @throws NullPointerException other pointer is null */ public JsonPointer append(final JsonPointer other) { BUNDLE.checkNotNull(other, "nullInput"); final List<TokenResolver<JsonNode>> list = Lists.newArrayList(tokenResolvers); list.addAll(other.tokenResolvers); return new JsonPointer(list); }