Send XML content to a JMS queue using Java - java

Can anyone help me to send XML file (XML message) through JMS producer, I am trying to do it as ByteMessage, but still cannot do it.
I have a JMS produced which need to read XML file and send as a message. I was trying to do it from ByteMessage and did not succeed, I'm looking for a better method to do this correctly, Please see below code snippet.
ByteMessage textMessage = session.createByteMessage(message);

Just create a TextMessage and set the body of the message with setText(<your xml>) with your xml
Really straight forward...
ByteMessage is for ... binary data (eg zip files)

Related

How to send plain text JmsMessage with empty header

I want to send a message to an activeMQ and receive it via MQTT.js in the frontend.
jmsTemplate.convertAndSend("topic", "Hello World!");
I am getting the message, but with a header, that I can not decode.
S�A S�)�x-opt-jms-destQ�x-opt-jms-msg-typeQ Ss� f
�/ID:myID#�topic://myTopic####� j��< St�e Sw� Hello World!
Now I am trying to remove the header from my message.
This thread mentions the targetClient property, but this doesn't seam to work with a topic: Spring JMS Template - remove RFH Header information
I also found the MessageBuilder, where I should be able to set an empty header, but this MessageBuilder doesn't work with the jmsTemplate. jmsTemplate only supports the MessageCreator, which doesn't support an empty header.
How can I send a JMS Message in plain text without any header?
Thanks for any suggestions.
Updating the Queue Broker to work with JMS2 fixed this issue.

Java JMX Message None UTF Body to String

I am subscribed to AMQ. I am trying to receive and store specific messages as they come across the wire. Some of the message that I am receiving have garbage values in body and when I perform the toString() after casting to a TextMessage the text is null. The error that I received is a UTF exception. I fully expect the message to fail the .getText(). Is there a way in Message to get the text without having to validate the xml or validate the that it is UTF?
Thanks

add footer/signature to mail in Java

In one of my Java applications I have to forward e-mails. So, I get e-mails (plain text or multipart) with any content (maybe also attachments). I edit their subject, from- and to-header and send them via SMTP.
I already implemented this using Apache James Mime4j and Apache Commons Net but now I also have to append a footer/signature to the content of each e-mail.
Can I achieve this with Mime4j too? Would be great! How? If not: is there another way?
EDIT: Details after Wolfgang Fahl's comment:
Maybe I'm using the library the wrong way, but I am parsing the message as follows:
MessageBuilder messageBuilder = new DefaultMessageBuilder();
InputStream in = ...
Message m = messageBuilder.parseMessage(in);
Now I have an instance of Message and I can set it's subject, sender, etc. But Message does not provide a method setText() or something like that. Ok, there is getBody() but then I don't know how to manipulate the Body.

Missing body in JMS / websocket message

I'm trying to understand why serialized objects are being stripped out when received.
Here is the general layout :
1. Produce JMS messages and send to a topic on an external ActiveMQ broker. The code is based off the Spring boot JMS message and can be viewed at http://bit.ly/QECQ21 . In my example, I generate various types of messages (text , POJO, Map)
2. I have 2 JMS consumers that subscribe to this topic.
a. One is a java client. This client correctly identifies all the various message types.
b. The 2nd client is a javascript client based on websockets + stomp.js . This correctly identifies text messages but not messages that contain POJOs generated by my producer.
Here is the sample output from the web client (source at http://bit.ly/Od0noF ) .
What am I doing wrong? Something wrong with the the addressing or something else in the code? Something about the way I'm using (or misusing) STOMP? I had to use "tcp://localhost:61616" in the Application.java class to correctly contact the broker.
Thanks
MESSAGE priority:4 persistent:true subscription:sub-0 expires:0 timestamp:1396418227090 destination:/topic/greetings message-id:ID:blackbox-53461-1396418226684-1:1:2:1:1 content-length:4 ping
Body:ping
MESSAGE priority:4 persistent:true subscription:sub-0 expires:0 timestamp:1396418227117 destination:/topic/greetings message-id:ID:blackbox-53461-1396418226684-1:1:2:1:2
Body: ======> missing body
MESSAGE priority:4 persistent:true subscription:sub-0 expires:0 timestamp:1396418227122 destination:/topic/greetings message-id:ID:blackbox-53461-1396418226684-1:1:2:1:3
Body: ======> missing body
MESSAGE priority:4 persistent:true subscription:sub-0 expires:0 timestamp:1396418227125 destination:/topic/greetings message-id:ID:blackbox-53461-1396418226684-1:1:2:1:4 content-length:5 close
Body:close
No answers yet so I'll add my findings. STOMP is a text based protocol and as such the body needs to be converted to a text format (such as JSON). In my case, this can be done using the spring websockets framework (which internally uses Jackson) or by explicitly coding the object into JSON using Jackson and them transmitting as a text message

Outbound SOAP Handler to edit full SOAPMessage

Is there a way to retrieve the full SOAP message to handle it (envelope and all) when using the javax.xml.soap.SOAPMessage class?
I am using JMX-WS and want to edit the outbound SOAP Message from the server, in order to append two characters to the message AFTER the end closing tag of the envelope, as the client legacy code is expecting it. So ideally I would like to be able to edit the full message as a String, is this possible?
You can do this with cxf :
http://www.mastertheboss.com/web-interfaces/337-apache-cxf-interceptors.html
Take a look at the LogInterceptor example

Categories

Resources