本文整理汇总了Java中javax.jms.MessageNotWriteableException类的典型用法代码示例。如果您正苦于以下问题:Java MessageNotWriteableException类的具体用法?Java MessageNotWriteableException怎么用?Java MessageNotWriteableException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageNotWriteableException类属于javax.jms包,在下文中一共展示了MessageNotWriteableException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setBytes
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
@Override
public void setBytes(final String name, final byte[] value, final int offset, final int length) throws JMSException {
checkName(name);
if (bodyReadOnly) {
throw new MessageNotWriteableException("Message is ReadOnly !");
}
if (offset + length > value.length) {
throw new JMSException("Array is too small");
}
byte[] temp = new byte[length];
System.arraycopy(value, offset, temp, 0, length);
content.put(name, temp);
}
示例2: setObject
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
@Override
public void setObject(Serializable object) throws JMSException
{
if (bodyIsReadOnly)
throw new MessageNotWriteableException("Message body is read-only");
assertDeserializationLevel(MessageSerializationLevel.FULL);
if (object == null)
{
body = null;
return;
}
try
{
body = SerializationTools.toByteArray(object);
}
catch (Exception e)
{
throw new FFMQException("Cannot serialize object message body","MESSAGE_ERROR",e);
}
}
示例3: testResetMakesReadble
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
public void testResetMakesReadble() throws Exception
{
try
{
JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeInt(10);
bm.reset();
bm.writeInt(12);
fail("expected exception did not occur");
}
catch (MessageNotWriteableException m)
{
// ok
}
catch (Exception e)
{
fail("expected MessageNotWriteableException, got " + e);
}
}
示例4: testResetMakesReadble
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
public void testResetMakesReadble() throws Exception
{
try
{
JMSStreamMessage bm = TestMessageHelper.newJMSStreamMessage();
bm.writeInt(10);
bm.reset();
bm.writeInt(12);
fail("expected exception did not occur");
}
catch (MessageNotWriteableException m)
{
// ok
}
catch (Exception e)
{
fail("expected MessageNotWriteableException, got " + e);
}
}
示例5: testClearBody
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
@Test
public void testClearBody() throws JMSException, IOException {
JmsTextMessage textMessage = factory.createTextMessage();
textMessage.setText("string");
textMessage.clearBody();
assertFalse(textMessage.isReadOnlyBody());
assertNull(textMessage.getText());
try {
textMessage.setText("String");
textMessage.getText();
} catch (MessageNotWriteableException mnwe) {
fail("should be writeable");
} catch (MessageNotReadableException mnre) {
fail("should be readable");
}
}
示例6: testReadOnlyBody
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
@Test
public void testReadOnlyBody() throws JMSException {
JmsTextMessage textMessage = factory.createTextMessage();
textMessage.setText("test");
textMessage.setReadOnlyBody(true);
try {
textMessage.getText();
} catch (MessageNotReadableException e) {
fail("should be readable");
}
try {
textMessage.setText("test");
fail("should throw exception");
} catch (MessageNotWriteableException mnwe) {
}
}
示例7: testReceivedMessageIsReadOnlyAndThrowsMNWE
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
/**
* Test that we are not able to write to a received message without calling
* {@link JmsMapMessage#clearBody()}
*
* @throws Exception if an error occurs during the test.
*/
@Test
public void testReceivedMessageIsReadOnlyAndThrowsMNWE() throws Exception {
JmsMapMessageFacade facade = new JmsTestMapMessageFacade();
String myKey1 = "key1";
facade.put(myKey1, "value1");
JmsMapMessage mapMessage = new JmsMapMessage(facade);
mapMessage.onDispatch();
try {
mapMessage.setObject("name", "value");
fail("expected exception to be thrown");
} catch (MessageNotWriteableException mnwe) {
// expected
}
}
示例8: testClearPropertiesClearsReadOnly
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
@Test
public void testClearPropertiesClearsReadOnly() throws Exception {
JmsMessage msg = factory.createMessage();
msg.onDispatch();
try {
msg.setObjectProperty("test", "value");
fail("should throw exception");
} catch (MessageNotWriteableException e) {
// Expected
}
assertTrue(msg.isReadOnlyProperties());
msg.clearProperties();
msg.setObjectProperty("test", "value");
assertFalse(msg.isReadOnlyProperties());
}
示例9: testReceivedObjectMessageThrowsMessageNotWriteableExceptionOnSetObject
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
/**
* Test that attempting to write bytes to a received message (without calling {@link ObjectMessage#clearBody()} first)
* causes a {@link MessageNotWriteableException} to be thrown due to being read-only.
*
* @throws Exception if an error occurs during the test.
*/
@Test
public void testReceivedObjectMessageThrowsMessageNotWriteableExceptionOnSetObject() throws Exception {
String content = "myStringContent";
JmsObjectMessageFacade facade = new JmsTestObjectMessageFacade();
facade.setObject(content);
JmsObjectMessage objectMessage = new JmsObjectMessage(facade);
objectMessage.onDispatch();
try {
objectMessage.setObject("newObject");
fail("Expected exception to be thrown");
} catch (MessageNotWriteableException mnwe) {
// expected
}
}
示例10: convertToRuntimeException
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
public static JMSRuntimeException convertToRuntimeException(JMSException e) {
if (e instanceof javax.jms.IllegalStateException) {
return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof InvalidClientIDException) {
return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof InvalidDestinationException) {
return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof InvalidSelectorException) {
return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof JMSSecurityException) {
return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof MessageFormatException) {
return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof MessageNotWriteableException) {
return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof ResourceAllocationException) {
return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof TransactionInProgressException) {
return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof TransactionRolledBackException) {
return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
示例11: convertMessageNotWritableException
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
@Test
public void convertMessageNotWritableException() throws JMSException {
Message<String> message = createTextMessage();
MessageConverter messageConverter = mock(MessageConverter.class);
willThrow(MessageNotWriteableException.class).given(messageConverter).toMessage(eq(message), anyObject());
messagingTemplate.setJmsMessageConverter(messageConverter);
invokeMessageCreator("myQueue");
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
messagingTemplate.send("myQueue", message);
}
示例12: initializeWriting
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
private void initializeWriting() throws MessageNotWriteableException {
checkReadOnlyBody();
if (this.dataOut == null) {
this.bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
ActiveMQConnection connection = getConnection();
if (connection != null && connection.isUseCompression()) {
compressed = true;
os = new DeflaterOutputStream(os);
}
this.dataOut = new DataOutputStream(os);
}
}
示例13: createMessage
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination) {
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setMessageId(new MessageId(producerInfo, ++msgIdGenerator));
message.setDestination(destination);
message.setPersistent(false);
try {
message.setText("Test Message Payload.");
} catch (MessageNotWriteableException e) {
}
return message;
}
示例14: assertSendTextMessage
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
protected void assertSendTextMessage(ActiveMQDestination destination,
String text) throws MessageNotWriteableException {
large = true;
ActiveMQTextMessage expected = new ActiveMQTextMessage();
expected.setText(text);
expected.setDestination(destination);
try {
LOG.info("About to send message of type: " + expected.getClass());
producer.oneway(expected);
// lets send a dummy command to ensure things don't block if we
// discard the last one
// keepalive does not have a commandId...
// producer.oneway(new KeepAliveInfo());
producer.oneway(new ProducerInfo());
producer.oneway(new ProducerInfo());
Command received = assertCommandReceived();
assertTrue("Should have received an ActiveMQTextMessage but was: " + received, received instanceof ActiveMQTextMessage);
ActiveMQTextMessage actual = (ActiveMQTextMessage) received;
assertEquals("getDestination", expected.getDestination(), actual.getDestination());
assertEquals("getText", expected.getText(), actual.getText());
LOG.info("Received text message with: " + actual.getText().length() + " character(s)");
} catch (Exception e) {
LOG.info("Caught: " + e);
e.printStackTrace();
fail("Failed to send to transport: " + e);
}
}
示例15: testClearBody
import javax.jms.MessageNotWriteableException; //导入依赖的package包/类
public void testClearBody() throws JMSException, IOException {
ActiveMQTextMessage textMessage = new ActiveMQTextMessage();
textMessage.setText("string");
textMessage.clearBody();
assertFalse(textMessage.isReadOnlyBody());
assertNull(textMessage.getText());
try {
textMessage.setText("String");
textMessage.getText();
} catch (MessageNotWriteableException mnwe) {
fail("should be writeable");
} catch (MessageNotReadableException mnre) {
fail("should be readable");
}
}