forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging message body fix, hostname verification fix and bug fixes fro…
…m master branch (Azure#315) * Test improvements (Azure#309) * Adding a large message test. Adding duplicate tests for partitioned entities. Minor tweaks to make message handler tests more reliable. * Invalid merge. * Removed merge conflict files * Some test fixes. * Adding ARM deployment template for CI (Azure#218) build/azuredeploy.json * Test reliability fixes. And RequestResponseLimitTest is modified to drastically reduce its runtime. * More test reliability fixes. * More tweaks. # Conflicts: # azure-servicebus/src/test/java/com/microsoft/azure/servicebus/ClientValidationTests.java # azure-servicebus/src/test/java/com/microsoft/azure/servicebus/primitives/ConnectionStringBuilderTests.java * Adding retry to RequestResponse link when idle connection is closed. (Azure#305) * Adding retry to RequestResponse link when idle connection is closed. Otherwise CBS token sending will fail if a SEND request comes in right at the time of connnection closing. * Minor tweaks to fix 15 minute timeout bug. * Another fix to handle connection while the links are being opened. * Another fix to retry sending SAS token if it times out. There are cases when client sending SAS token and server closing the connection happen at the same time and response never arrives. * More fixes to request-response link to retry on connection close. * A test fix. # Conflicts: # azure-servicebus/src/main/java/com/microsoft/azure/servicebus/amqp/AmqpErrorCode.java # azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/CoreMessageReceiver.java # azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/CoreMessageSender.java # azure-servicebus/src/main/java/com/microsoft/azure/servicebus/primitives/RequestResponseLink.java * Adding support for multiple message body types. (Azure#296) * Adding support for multiple message body types. Deprecated getBody and setBody methods. * Changes to MessageBody class API to support AMQP spec of multiple data sections or sequence sections in a message. * Adding a minor null check. * Change to handle Messages constructed with string body as binary messages to preserve backward compatibility. * Adding message body tests. # Conflicts: # azure-servicebus/src/main/java/com/microsoft/azure/servicebus/Message.java # azure-servicebus/src/test/java/com/microsoft/azure/servicebus/SendReceiveTests.java # azure-servicebus/src/test/java/com/microsoft/azure/servicebus/SessionTests.java * Merging the fix for man-in-the-middle vulnerability from master branch.
- Loading branch information
Showing
39 changed files
with
1,320 additions
and
361 deletions.
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
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
112 changes: 112 additions & 0 deletions
112
azure-servicebus/src/main/java/com/microsoft/azure/servicebus/MessageBody.java
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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.microsoft.azure.servicebus; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* This class encapsulates the body of a message. Body types map to AMQP message body types. | ||
* It has getters and setters for multiple body types. | ||
* Client should test for body type before calling corresponding get method. | ||
* Get methods not corresponding to the type of the body return null. | ||
*/ | ||
public class MessageBody { | ||
private MessageBodyType bodyType; | ||
private Object valueData; | ||
private List<List<Object>> sequenceData; | ||
private List<byte[]> binaryData; | ||
|
||
private MessageBody() {} | ||
|
||
/** | ||
* Creates message body of AMQPValue type. | ||
* @param value AMQPValue content of the message. It must be of a type supported by AMQP. | ||
* @return MessageBody instance wrapping around the value data. | ||
*/ | ||
public static MessageBody fromValueData(Object value) | ||
{ | ||
if(value == null) | ||
{ | ||
throw new IllegalArgumentException("Value data is null."); | ||
} | ||
|
||
MessageBody body = new MessageBody(); | ||
body.bodyType = MessageBodyType.VALUE; | ||
body.valueData = value; | ||
body.sequenceData = null; | ||
body.binaryData = null; | ||
return body; | ||
} | ||
|
||
/** | ||
* Creates a message body from a list of AMQPSequence sections.Each AMQPSequence section is in turn a list of objects. | ||
* Please note that this version of the SDK supports only one AMQPSequence section in a message. It means only a list of exactly one sequence in it is accepted as message body. | ||
* @param sequenceData a list of AMQPSequence sections. Each AMQPSequence section is in turn a list of objects. Every object in each list must of a type supported by AMQP. | ||
* @return MessageBody instance wrapping around the sequence data. | ||
*/ | ||
public static MessageBody fromSequenceData(List<List<Object>> sequenceData) | ||
{ | ||
if(sequenceData == null || sequenceData.size() == 0 || sequenceData.size() > 1) | ||
{ | ||
throw new IllegalArgumentException("Sequence data is null or has more than one collection in it."); | ||
} | ||
|
||
MessageBody body = new MessageBody(); | ||
body.bodyType = MessageBodyType.SEQUENCE; | ||
body.valueData = null; | ||
body.sequenceData = sequenceData; | ||
body.binaryData = null; | ||
return body; | ||
} | ||
|
||
/** | ||
* Creates a message body from a list of Data sections.Each Data section is a byte array. | ||
* Please note that this version of the SDK supports only one Data section in a message. It means only a list of exactly one byte array in it is accepted as message body. | ||
* @param binaryData a list of byte arrays. | ||
* @return MessageBody instance wrapping around the binary data. | ||
*/ | ||
public static MessageBody fromBinaryData(List<byte[]> binaryData) | ||
{ | ||
if(binaryData == null || binaryData.size() == 0 || binaryData.size() > 1) | ||
{ | ||
throw new IllegalArgumentException("Binary data is null or has more than one byte array in it."); | ||
} | ||
|
||
MessageBody body = new MessageBody(); | ||
body.bodyType = MessageBodyType.BINARY; | ||
body.valueData = null; | ||
body.sequenceData = null; | ||
body.binaryData = binaryData; | ||
return body; | ||
} | ||
|
||
/** | ||
* Returns the content of message body. | ||
* @return value of message body only if the MessageBody is of Value type. Returns null otherwise. | ||
*/ | ||
public Object getValueData() { | ||
return valueData; | ||
} | ||
|
||
/** | ||
* Returns the content of message body. | ||
* @return a list of AMQPSequence sections only if the MessageBody is of Sequence type. Returns null otherwise. Each AMQPSequence section is in turn a list of objects. | ||
*/ | ||
public List<List<Object>> getSequenceData() { | ||
return sequenceData; | ||
} | ||
|
||
/** | ||
* Returns the content of message body. | ||
* @return message body as list of byte arrays only if the MessageBody is of Binary type. Returns null otherwise. | ||
*/ | ||
public List<byte[]> getBinaryData() { | ||
return binaryData; | ||
} | ||
|
||
/** | ||
* Return the type of content in this message body. | ||
* @return type of message content | ||
*/ | ||
public MessageBodyType getBodyType() { | ||
return bodyType; | ||
} | ||
} |
Oops, something went wrong.