Hi

Many thanks for this! I have just one more bit to add, I think that in code
of JmsMessageHelper there should be something like this:

        case Message:
            if (allowNullBody && payload == null) {
                answer = session.createMessage();
            } else if(payload != null) {
                throw new JMSException("Unsupported message body");
            }
            else {
                throw new JMSException("Null body is not allowed");
            }

You can get to this situation:
          else if(payload != null) {
                throw new JMSException("Unsupported message body");
            }

if you add test from below to JMSMessageHelperTypeConversionTest: 
@Test
    public void testJMSMessageHelperUnknownType() throws
InterruptedException, FileNotFoundException {
        class TestAnonymousClass {
            private String testValue = "Hello Camel";
            
            public String getTestValue() {
                return testValue;
            }            
        };        
        try {
            template.sendBody(SJMS_QUEUE_URI, new TestAnonymousClass());
        } catch (Exception e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            assertFalse(sw.toString().contains("Null body is not allowed"));
//            assertStringContains(sw.toString(), "Unsupported message body"
);
        }        
    }

And it looks strange when you send non empty message body and get stacktrace
like this:
        at
org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:137)
        ... 30 more
Caused by: javax.jms.JMSException: Null body is not allowed
        at
org.apache.camel.component.sjms.jms.JmsMessageHelper.createMessage(JmsMessageHelper.java:202)
        at
org.apache.camel.component.sjms.jms.JmsMessageHelper.createMessage(JmsMessageHelper.java:156)

Kind regards,
Stan



--
View this message in context: 
http://camel.465427.n5.nabble.com/Camel-SJMS-Null-pointer-exception-when-sending-a-message-proposed-patch-tp5764093p5764186.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to