Java Code Examples for org.apache.activemq.artemis.api.core.SimpleString#toString()
The following examples show how to use
org.apache.activemq.artemis.api.core.SimpleString#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoCreateJmsDestinationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test (timeout = 30000) // QueueAutoCreationTest was created to validate auto-creation of queues // and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238 public void testAutoCreateOnAddressOnlyDuringProducerCreateQueueSucceed() throws Exception { server.getAddressSettingsRepository().clear(); AddressSettings settings = new AddressSettings().setAutoCreateAddresses(true).setAutoCreateQueues(true); server.getAddressSettingsRepository().addMatch("#", settings); ConnectionFactory factory = cf; try (Connection connection = factory.createConnection()) { SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID(); clientSession.createAddress(addressName, RoutingType.ANYCAST, true); // this will force the system to create the address only javax.jms.Queue queue = new ActiveMQQueue(addressName.toString()); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(queue); Assert.assertNotNull(server.locateQueue(addressName)); Assert.assertTrue(((ActiveMQDestination) queue).isCreated()); } }
Example 2
Source File: OpenWireConnection.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void tempQueueDeleted(SimpleString bindingName) { ActiveMQDestination dest = new ActiveMQTempQueue(bindingName.toString()); state.removeTempDestination(dest); if (!AdvisorySupport.isAdvisoryTopic(dest)) { AMQConnectionContext context = getContext(); DestinationInfo advInfo = new DestinationInfo(context.getConnectionId(), DestinationInfo.REMOVE_OPERATION_TYPE, dest); ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(dest); try { protocolManager.fireAdvisory(context, topic, advInfo); } catch (Exception e) { logger.warn("Failed to fire advisory on " + topic, e); } } }
Example 3
Source File: OpenWireMessageConverter.java From activemq-artemis with Apache License 2.0 | 6 votes |
private static void setAMQMsgObjectProperties(final ActiveMQMessage amqMsg, final ICoreMessage coreMessage, final Set<SimpleString> props, final AMQConsumer consumer) throws IOException { for (SimpleString s : props) { final String keyStr = s.toString(); if (!coreMessage.containsProperty(ManagementHelper.HDR_NOTIFICATION_TYPE) && (keyStr.startsWith("_AMQ") || keyStr.startsWith("__HDR_"))) { continue; } final Object prop = coreMessage.getObjectProperty(s); try { if (prop instanceof SimpleString) { amqMsg.setObjectProperty(keyStr, prop.toString()); } else { if (keyStr.equals(MessageUtil.JMSXDELIVERYCOUNT) && prop instanceof Long) { Long l = (Long) prop; amqMsg.setObjectProperty(keyStr, l.intValue()); } else { amqMsg.setObjectProperty(keyStr, prop); } } } catch (JMSException e) { throw new IOException("exception setting property " + s + " : " + prop, e); } } }
Example 4
Source File: QueueAutoCreationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) // QueueAutoCreationTest was created to validate auto-creation of queues // and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238 public void testAutoCreateOnTopicManySends() throws Exception { ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:5672"); Connection connection = factory.createConnection(); SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID(); instanceLog.debug("Address is " + addressName); clientSession.createAddress(addressName, RoutingType.ANYCAST, false); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); for (int i = 0; i < 10; i++) { Topic topic = new ActiveMQTopic(addressName.toString()); MessageProducer producer = session.createProducer(topic); producer.send(session.createTextMessage("hello")); producer.close(); Assert.assertTrue(((ActiveMQDestination) topic).isCreated()); } }
Example 5
Source File: ActiveMQCompatibleMessage.java From activemq-artemis with Apache License 2.0 | 6 votes |
static Destination findCompatibleReplyTo(ClientMessage message) { SimpleString address = MessageUtil.getJMSReplyTo(message); if (address != null) { final SimpleString checkedAddress = checkPrefix1X(address); if (checkedAddress != null) { return ActiveMQDestination.fromPrefixed1XName(address.toString(), checkedAddress.toString()); } String name = address.toString(); // swap the old prefixes for the new ones so the proper destination type gets created if (address.startsWith(OLD_QUEUE_QUALIFIED_PREFIX)) { name = address.subSeq(OLD_QUEUE_QUALIFIED_PREFIX.length(), address.length()).toString(); } else if (address.startsWith(OLD_TEMP_QUEUE_QUALIFED_PREFIX)) { name = address.subSeq(OLD_TEMP_QUEUE_QUALIFED_PREFIX.length(), address.length()).toString(); } else if (address.startsWith(OLD_TOPIC_QUALIFIED_PREFIX)) { name = address.subSeq(OLD_TOPIC_QUALIFIED_PREFIX.length(), address.length()).toString(); } else if (address.startsWith(OLD_TEMP_TOPIC_QUALIFED_PREFIX)) { name = address.subSeq(OLD_TEMP_TOPIC_QUALIFED_PREFIX.length(), address.length()).toString(); } return ActiveMQDestination.fromPrefixedName(address.toString(), name); } return null; }
Example 6
Source File: AutoCreateJmsDestinationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test (timeout = 30000) // QueueAutoCreationTest was created to validate auto-creation of queues // and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238 public void testAutoCreateOnAddressOnly() throws Exception { server.getAddressSettingsRepository().clear(); AddressSettings settings = new AddressSettings().setAutoCreateAddresses(true).setAutoCreateQueues(false); server.getAddressSettingsRepository().addMatch("#", settings); ConnectionFactory factory = new ActiveMQConnectionFactory(); try (Connection connection = factory.createConnection()) { SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID(); instanceLog.debug("Address is " + addressName); javax.jms.Queue queue = new ActiveMQQueue(addressName.toString()); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(null); try { producer.send(queue, session.createTextMessage("hello")); Assert.fail("Expected to throw exception here"); } catch (JMSException expected) { } Assert.assertFalse(((ActiveMQDestination) queue).isCreated()); } }
Example 7
Source File: AutoCreateJmsDestinationTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test //(timeout = 30000) // QueueAutoCreationTest was created to validate auto-creation of queues // and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238 public void testAutoCreateOnTopic() throws Exception { ConnectionFactory factory = new ActiveMQConnectionFactory(); Connection connection = factory.createConnection(); SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID(); instanceLog.debug("Address is " + addressName); clientSession.createAddress(addressName, RoutingType.ANYCAST, false); Topic topic = new ActiveMQTopic(addressName.toString()); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(topic); for (int i = 0; i < 10; i++) { producer.send(session.createTextMessage("hello")); } Assert.assertTrue((((ActiveMQDestination) topic).isCreated())); }
Example 8
Source File: SelectorTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public Object getProperty(SimpleString name) { String stringName = name.toString(); if ("JMSType".equals(stringName)) { return type; } if ("JMSMessageID".equals(stringName)) { return messageId; } return properties.get(stringName); }
Example 9
Source File: QueueControlImpl.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public String getUser() { if (AuditLogger.isEnabled()) { AuditLogger.getUser(queue); } checkStarted(); clearIO(); try { SimpleString user = queue.getUser(); return user == null ? null : user.toString(); } finally { blockOnIO(); } }
Example 10
Source File: PersistedDestination.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void decode(final ActiveMQBuffer buffer) { type = PersistedType.getType(buffer.readByte()); name = buffer.readSimpleString().toString(); SimpleString selectorStr = buffer.readNullableSimpleString(); selector = (selectorStr == null) ? null : selectorStr.toString(); durable = buffer.readBoolean(); }
Example 11
Source File: ConsumedMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
protected void buildHeaders(Response.ResponseBuilder builder) { for (SimpleString key : message.getPropertyNames()) { String k = key.toString(); String headerName = HttpHeaderProperty.fromPropertyName(k); if (headerName == null) { continue; } builder.header(headerName, message.getStringProperty(k)); ActiveMQRestLogger.LOGGER.debug("Adding " + headerName + "=" + message.getStringProperty(k)); } }
Example 12
Source File: ManagementHelper.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Used by ActiveMQ Artemis management service. */ public static Object[] retrieveOperationParameters(final Message message) throws Exception { SimpleString sstring = message.toCore().getReadOnlyBodyBuffer().readNullableSimpleString(); String jsonString = (sstring == null) ? null : sstring.toString(); if (jsonString != null) { JsonArray jsonArray = JsonUtil.readJsonArray(jsonString); return JsonUtil.fromJsonArray(jsonArray); } else { return null; } }
Example 13
Source File: ManagementHelper.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Returns the result of an operation invocation or an attribute value. * <br> * If an error occurred on the server, {@link #hasOperationSucceeded(Message)} will return {@code false}. * and the result will be a String corresponding to the server exception. */ public static Object[] getResults(final ICoreMessage message) throws Exception { SimpleString sstring = message.getReadOnlyBodyBuffer().readNullableSimpleString(); String jsonString = (sstring == null) ? null : sstring.toString(); if (jsonString != null) { JsonArray jsonArray = JsonUtil.readJsonArray(jsonString); return JsonUtil.fromJsonArray(jsonArray); } else { return null; } }
Example 14
Source File: ByteUtil.java From activemq-artemis with Apache License 2.0 | 5 votes |
public static String toSimpleString(byte[] bytes) { SimpleString simpleString = new SimpleString(bytes); String value = simpleString.toString(); for (char c : value.toCharArray()) { if (c < ' ' || c > 127) { return NON_ASCII_STRING; } } return value; }
Example 15
Source File: MessageUtil.java From activemq-artemis with Apache License 2.0 | 5 votes |
public static String getJMSType(Message message) { SimpleString ss = message.getSimpleStringProperty(TYPE_HEADER_NAME); if (ss != null) { return ss.toString(); } else { return null; } }
Example 16
Source File: CoreMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public String getStringProperty(final SimpleString key) throws ActiveMQPropertyConversionException { SimpleString str = getSimpleStringProperty(key); if (str == null) { return null; } else { return str.toString(); } }
Example 17
Source File: SimpleStringTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testToSimpleStringPoolStringArgument() throws Exception { final String s = "pooled"; final SimpleString ss = SimpleString.toSimpleString(s); final String s1 = ss.toString(); Assert.assertSame("SimpleString::toSimpleString is not pooling the given String", s, s1); }
Example 18
Source File: ClusterConnectionImpl.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Override public void stop() throws Exception { if (!started) { return; } stopping = true; if (logger.isDebugEnabled()) { logger.debug(this + "::stopping ClusterConnection"); } if (serverLocator != null) { serverLocator.removeClusterTopologyListener(this); } logger.debug("Cluster connection being stopped for node" + nodeManager.getNodeId() + ", server = " + this.server + " serverLocator = " + serverLocator); synchronized (this) { for (MessageFlowRecord record : records.values()) { try { record.close(); } catch (Exception ignore) { } } } if (managementService != null) { TypedProperties props = new TypedProperties(); props.putSimpleStringProperty(new SimpleString("name"), name); //nodeID can be null if there's only a backup SimpleString nodeId = nodeManager.getNodeId(); Notification notification = new Notification(nodeId == null ? null : nodeId.toString(), CoreNotificationType.CLUSTER_CONNECTION_STOPPED, props); managementService.sendNotification(notification); } executor.execute(new Runnable() { @Override public void run() { synchronized (ClusterConnectionImpl.this) { closeLocator(serverLocator); serverLocator = null; } } }); started = false; }
Example 19
Source File: AMQPMessage.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Override public final String getAddress() { SimpleString addressSimpleString = getAddressSimpleString(); return addressSimpleString == null ? null : addressSimpleString.toString(); }
Example 20
Source File: SecurityStoreImpl.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Override public void check(final SimpleString address, final SimpleString queue, final CheckType checkType, final SecurityAuth session) throws Exception { if (securityEnabled) { if (logger.isTraceEnabled()) { logger.trace("checking access permissions to " + address); } String user = session.getUsername(); if (checkCached(address, user, checkType)) { // OK return; } String saddress = address.toString(); Set<Role> roles = securityRepository.getMatch(saddress); // bypass permission checks for management cluster user if (managementClusterUser.equals(user) && session.getPassword().equals(managementClusterPassword)) { return; } final boolean validated; if (securityManager instanceof ActiveMQSecurityManager4) { final ActiveMQSecurityManager4 securityManager4 = (ActiveMQSecurityManager4) securityManager; validated = securityManager4.validateUserAndRole(user, session.getPassword(), roles, checkType, saddress, session.getRemotingConnection(), session.getSecurityDomain()) != null; } else if (securityManager instanceof ActiveMQSecurityManager3) { final ActiveMQSecurityManager3 securityManager3 = (ActiveMQSecurityManager3) securityManager; validated = securityManager3.validateUserAndRole(user, session.getPassword(), roles, checkType, saddress, session.getRemotingConnection()) != null; } else if (securityManager instanceof ActiveMQSecurityManager2) { final ActiveMQSecurityManager2 securityManager2 = (ActiveMQSecurityManager2) securityManager; validated = securityManager2.validateUserAndRole(user, session.getPassword(), roles, checkType, saddress, session.getRemotingConnection()); } else { validated = securityManager.validateUserAndRole(user, session.getPassword(), roles, checkType); } if (!validated) { if (notificationService != null) { TypedProperties props = new TypedProperties(); props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address); props.putSimpleStringProperty(ManagementHelper.HDR_CHECK_TYPE, new SimpleString(checkType.toString())); props.putSimpleStringProperty(ManagementHelper.HDR_USER, SimpleString.toSimpleString(user)); Notification notification = new Notification(null, CoreNotificationType.SECURITY_PERMISSION_VIOLATION, props); notificationService.sendNotification(notification); } Exception ex; if (queue == null) { ex = ActiveMQMessageBundle.BUNDLE.userNoPermissions(session.getUsername(), checkType, saddress); } else { ex = ActiveMQMessageBundle.BUNDLE.userNoPermissionsQueue(session.getUsername(), checkType, queue.toString(), saddress); } AuditLogger.securityFailure(ex); throw ex; } // if we get here we're granted, add to the cache ConcurrentHashSet<SimpleString> set = new ConcurrentHashSet<>(); ConcurrentHashSet<SimpleString> act = cache.putIfAbsent(user + "." + checkType.name(), set); if (act != null) { set = act; } set.add(address); } }