[ https://issues.apache.org/jira/browse/ARTEMIS-1498?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16350979#comment-16350979 ]
ASF GitHub Bot commented on ARTEMIS-1498: ----------------------------------------- Github user michaelandrepearce commented on a diff in the pull request: https://github.com/apache/activemq-artemis/pull/1793#discussion_r165768705 --- Diff: artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireCoreConverter.java --- @@ -0,0 +1,572 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.artemis.core.protocol.openwire; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Arrays; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; +import java.util.zip.Deflater; +import java.util.zip.DeflaterOutputStream; +import java.util.zip.Inflater; +import java.util.zip.InflaterInputStream; +import java.util.zip.InflaterOutputStream; + +import org.apache.activemq.artemis.api.core.ActiveMQBuffer; +import org.apache.activemq.artemis.api.core.FilterConstants; +import org.apache.activemq.artemis.api.core.ICoreMessage; +import org.apache.activemq.artemis.api.core.SimpleString; +import org.apache.activemq.artemis.core.message.impl.CoreMessage; +import org.apache.activemq.artemis.core.message.impl.CoreMessageObjectPools; +import org.apache.activemq.artemis.reader.MessageUtil; +import org.apache.activemq.artemis.utils.DataConstants; +import org.apache.activemq.artemis.utils.collections.TypedProperties; +import org.apache.activemq.command.CommandTypes; +import org.apache.activemq.util.ByteArrayInputStream; +import org.apache.activemq.util.ByteSequence; +import org.apache.activemq.util.ByteSequenceData; +import org.apache.activemq.util.MarshallingSupport; +import org.fusesource.hawtbuf.UTF8Buffer; + +public class OpenWireCoreConverter { + public static final SimpleString JMS_GROUPSEQ = new SimpleString("JMSXGroupSequence"); + public static final SimpleString JMS_XGROUPSEQ = new SimpleString("JMSXGroupSeq"); + public static final SimpleString JMS_GROUPID = new SimpleString("JMSXGroupID"); + private static final SimpleString AMQP_REPLYTOGROUPID = new SimpleString("JMS_AMQP_ReplyToGroupID"); + public static final SimpleString JMS_CONTENT_TYPE = new SimpleString("JMS_AMQP_ContentType"); + private static final SimpleString AMQP_CONTETTYPE = new SimpleString("JMS_AMQP_CONTENT_TYPE"); + + public static ICoreMessage toCore(final OpenWireMessage openwireMessage, final CoreMessageObjectPools coreMessageObjectPools) + throws Exception { + CoreMessage coreMessage = new CoreMessage(-1, openwireMessage.getMessageSize(), coreMessageObjectPools); + final SimpleString type = openwireMessage.getSimpleStringProperty(OpenWireMessageConverter.JMS_TYPE_PROPERTY); + if (type != null) { + coreMessage.putStringProperty(OpenWireMessageConverter.JMS_TYPE_PROPERTY, type); + } + coreMessage.setDurable(openwireMessage.isDurable()); + coreMessage.setExpiration(openwireMessage.getExpiration()); + coreMessage.setPriority(openwireMessage.getPriority()); + coreMessage.setTimestamp(openwireMessage.getTimestamp()); + final ActiveMQBuffer openWireMessageBuffer = openwireMessage.getReadOnlyBodyBuffer(); + final boolean isCompressed = openwireMessage.getBooleanProperty(OpenWireMessageConverter.AMQ_MSG_COMPRESSED); + final byte coreType = openwireMessage.getType(); + coreMessage.setType(coreType); + openWireMessageBuffer.resetReaderIndex(); + final byte[] bytes; + bytes = readContentFromBody(openWireMessageBuffer, coreType, isCompressed); + if (bytes != null) { + ByteSequence content = new ByteSequence(bytes); + ActiveMQBuffer coreMessageBuffer = coreMessage.getBodyBuffer(); + writeContentIntoBody(coreMessageBuffer, content, coreType, isCompressed); + } + coreMessage.putObjectProperty(FilterConstants.NATIVE_MESSAGE_ID, + openwireMessage.getObjectProperty(FilterConstants.NATIVE_MESSAGE_ID)); + coreMessage.setMessageID(openwireMessage.getMessageID()); + final String corrId = openwireMessage.getStringProperty(OpenWireMessageConverter.JMS_CORRELATION_ID_PROPERTY); + if (corrId != null) { + coreMessage.putStringProperty(OpenWireMessageConverter.JMS_CORRELATION_ID_PROPERTY, corrId); + } + final String groupId = openwireMessage.getStringProperty(org.apache.activemq.artemis.api.core.Message.HDR_GROUP_ID); + if (groupId != null) { + coreMessage.putStringProperty(org.apache.activemq.artemis.api.core.Message.HDR_GROUP_ID, + new SimpleString(groupId)); + coreMessage.putStringProperty(JMS_GROUPID, new SimpleString(groupId)); + } + if (openwireMessage.containsProperty(JMS_GROUPSEQ)) { + coreMessage.putIntProperty(JMS_GROUPSEQ, openwireMessage.getIntProperty(JMS_GROUPSEQ)); + coreMessage.putIntProperty(JMS_XGROUPSEQ, openwireMessage.getIntProperty(JMS_GROUPSEQ)); + } + final SimpleString lastValueProperty = openwireMessage.getLastValueProperty(); + if (lastValueProperty != null) { + coreMessage.setLastValueProperty(lastValueProperty); + } + coreMessage.putObjectProperty(AMQP_CONTETTYPE, openwireMessage.getObjectProperty(JMS_CONTENT_TYPE)); + coreMessage.putObjectProperty(AMQP_REPLYTOGROUPID, openwireMessage.getObjectProperty(AMQP_REPLYTOGROUPID)); + coreMessage.setReplyTo(openwireMessage.getReplyTo()); + coreMessage.setUserID(openwireMessage.getUserID()); + coreMessage.setDurable(openwireMessage.isDurable()); + coreMessage.setAddress(openwireMessage.getAddress()); + coreMessage.putObjectProperty(org.apache.activemq.artemis.api.core.Message.HDR_GROUP_ID, + (SimpleString) openwireMessage + .getObjectProperty(org.apache.activemq.artemis.api.core.Message.HDR_GROUP_ID)); + copyAllProperties(openwireMessage, coreMessage); + return coreMessage; + } + + public static byte toCoreType(byte amqType) { + switch (amqType) { + case CommandTypes.ACTIVEMQ_BLOB_MESSAGE: + throw new IllegalStateException("We don't support BLOB type yet!"); + case CommandTypes.ACTIVEMQ_BYTES_MESSAGE: + return org.apache.activemq.artemis.api.core.Message.BYTES_TYPE; + case CommandTypes.ACTIVEMQ_MAP_MESSAGE: + return org.apache.activemq.artemis.api.core.Message.MAP_TYPE; + case CommandTypes.ACTIVEMQ_OBJECT_MESSAGE: + return org.apache.activemq.artemis.api.core.Message.OBJECT_TYPE; + case CommandTypes.ACTIVEMQ_STREAM_MESSAGE: + return org.apache.activemq.artemis.api.core.Message.STREAM_TYPE; + case CommandTypes.ACTIVEMQ_TEXT_MESSAGE: + return org.apache.activemq.artemis.api.core.Message.TEXT_TYPE; + case CommandTypes.ACTIVEMQ_MESSAGE: + return org.apache.activemq.artemis.api.core.Message.DEFAULT_TYPE; + default: + throw new IllegalStateException("Unknown ActiveMQ Artemis message type: " + amqType); + } + } + + public static void loadMapIntoProperties(TypedProperties props, Map<String, Object> map) { + for (Entry<String, Object> entry : map.entrySet()) { + SimpleString key = new SimpleString(entry.getKey()); + Object value = entry.getValue(); + if (value instanceof UTF8Buffer) { + value = ((UTF8Buffer) value).toString(); --- End diff -- @franz1981 as per other comment, if you're not dead against it, i personally merge this PR, and then we (me and you) can go through with some TLC on it. > [interop] Openwire internal headers should not be part of message properties > ---------------------------------------------------------------------------- > > Key: ARTEMIS-1498 > URL: https://issues.apache.org/jira/browse/ARTEMIS-1498 > Project: ActiveMQ Artemis > Issue Type: Bug > Components: OpenWire > Environment: interoperability between Openwire -> AMQP/Core > Reporter: Michal Toth > Priority: Minor > > Sending an empty message from Openwire JMS client to AMQP or Core receiver > client shows extra "internal" headers (__HDR_*) in message properties. > They should not be there, as these are internal for broker in my opinion. > Openwire sender > {noformat} > $ java -jar /var/dtests/node_data/clients/aoc7.jar sender --timeout 5 > --log-msgs interop --broker tcp://localhost:61616 --address queue_name_\$ > --count 1 --conn-username admin --conn-password admin > {'durable': True, 'priority': 4, 'ttl': 0, 'first-acquirer': False, > 'delivery-count': 0, 'id': > 'dhcp-145-96.lab.eng.brq.redhat.com-33646-1509702974536-1:1:1:1:1', > 'user-id':None, 'address': 'queue_name_$', 'subject': None, 'reply-to': None, > 'correlation-id': None, 'content-type': None, 'content-encoding': None, > 'absolute-expiry-time': 0, 'creation-time': 1509702974798, 'group-id': None, > 'group-sequence': 0, 'reply-to-group-id': None, 'properties': {}, 'content': > None, 'type': None} > {noformat} > AMQP/Core receiver > {noformat} > $ java -jar /var/dtests/node_data/clients/aac1.jar receiver --timeout 5 > --log-msgs interop --broker localhost:5672 --address queue_name_\$ --count 1 > --conn-username admin --conn-password admin > Unsupported object type org.apache.qpid.proton.amqp.Binary > \x00\x00\x00Jn\x02\xae\x02{\x00=ID:dhcp-145-96.lab.eng.brq.redhat.com-33646-1509702974536-1:1\x00\x01\x00\x01\x00\x01 > Unsupported object type org.apache.qpid.proton.amqp.Binary > \x00\x00\x00F{\x01+\x00=ID:dhcp-145-96.lab.eng.brq.redhat.com-33646-1509702974536-1:1\x00\x01\x00\x01 > {'durable': True, 'priority': 4, 'ttl': 0, 'first-acquirer': False, > 'delivery-count': 0, 'id': None, 'user-id': None, 'address': 'queue_name_$', > 'subject': None, 'reply-to': None, 'correlation-id': None, 'content-type': > None, 'content-encoding': None, 'absolute-expiry-time': 0, 'creation-time': > 1509702974798, 'group-id': None, 'group-sequence': 0, 'reply-to-group-id': > None, 'properties': {'__HDR_COMMAND_ID': 5, 'JMSXDeliveryCount': 1, > '__HDR_ARRIVAL': 0, '__HDR_MESSAGE_ID': > \x00\x00\x00Jn\x02\xae\x02{\x00=ID:dhcp-145-96.lab.eng.brq.redhat.com-33646-1509702974536-1:1\x00\x01\x00\x01\x00\x01, > '__HDR_GROUP_SEQUENCE': 0, '__HDR_PRODUCER_ID': > \x00\x00\x00F{\x01+\x00=ID:dhcp-145-96.lab.eng.brq.redhat.com-33646-1509702974536-1:1\x00\x01\x00\x01, > '__HDR_DROPPABLE': False, '__HDR_BROKER_IN_TIME': 1509702974800}, 'content': > None} > {noformat} -- This message was sent by Atlassian JIRA (v7.6.3#76005)