forked from awslabs/amazon-sqs-java-messaging-lib
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle binary and non-jms header names #1
Closed
Closed
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
target/ | ||
.tool-versions | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,10 +30,12 @@ | |
import javax.jms.MessageNotWriteableException; | ||
|
||
import com.amazon.sqs.javamessaging.SQSMessageConsumerPrefetch; | ||
import com.amazon.sqs.javamessaging.SQSMessageProducer; | ||
onyxraven marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import com.amazon.sqs.javamessaging.SQSMessagingClientConstants; | ||
import com.amazon.sqs.javamessaging.SQSQueueDestination; | ||
import com.amazon.sqs.javamessaging.acknowledge.Acknowledger; | ||
import com.amazonaws.services.sqs.model.MessageAttributeValue; | ||
import org.apache.commons.logging.LogFactory; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. temporary for now? |
||
|
||
import static com.amazon.sqs.javamessaging.SQSMessagingClientConstants.*; | ||
|
||
|
@@ -158,10 +160,26 @@ private void mapSystemAttributeToJmsMessageProperty(Map<String,String> systemAtt | |
writePermissionsForProperties = true; | ||
} | ||
|
||
// TODO: do something to handle unsupported DataTypes instead of Exception | ||
// TODO: Default: log a message, otherwise use a registered handler (future) | ||
private void addMessageAttributes(com.amazonaws.services.sqs.model.Message sqsMessage) throws JMSException { | ||
for (Entry<String, MessageAttributeValue> entry : sqsMessage.getMessageAttributes().entrySet()) { | ||
properties.put(entry.getKey(), new JMSMessagePropertyValue( | ||
entry.getValue().getStringValue(), entry.getValue().getDataType())); | ||
// transform Key to conform to `\w` (alphanum_) only. | ||
// TODO make this a userland transformer, or use a default | ||
String key = entry.getKey(); | ||
String sanitizedKey = key.replaceAll("[\\W$]", "_"); | ||
|
||
// getDataType: one of String, Number, and Binary. | ||
String type = entry.getValue().getDataType(); | ||
if (type != null && (type.startsWith(STRING) || type.startsWith(NUMBER))) { | ||
properties.put(sanitizedKey, new JMSMessagePropertyValue( | ||
entry.getValue().getStringValue(), entry.getValue().getDataType())); | ||
} else if (BINARY.equals(type)) { | ||
// if Binary, getBinaryValue() should be used but should require an userland mapper | ||
// it must map to one of Boolean, Byte, Short, Integer, Long, Float, Double, and String. | ||
// TODO userland mapper, but for now we're just going to log and skip it. The key won't be added | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see comments |
||
LogFactory.getLog(SQSMessage.class).warn("MessageAttribute with BINARY key: " + entry.getKey()); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -1128,7 +1146,7 @@ static public <T> T convert(Object value, Class<T> clazz) { | |
* attribute type and message attribute string value. | ||
*/ | ||
public static class JMSMessagePropertyValue { | ||
|
||
private final Object value; | ||
|
||
private final String type; | ||
|
@@ -1211,6 +1229,9 @@ private static Object getObjectValue(String value, String type) throws JMSExcept | |
return Short.valueOf(value); | ||
} else if (type != null && (type.startsWith(STRING) || type.startsWith(NUMBER))) { | ||
return value; | ||
} else if (BINARY.equals(type)) { | ||
// This is a safety catch for binary type | ||
return null; | ||
} else { | ||
throw new JMSException(type + " is not a supported JMS property type"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldn't get this plugin to behave, so commented for now