Java JMX Message None UTF Body to String - java

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

Related

How to differentiate between the automatic reply and the normal mail received

I am working on receiving mails in my springboot application. In order to fetch and store the receive mails. I am using imap mail listener. There are two types of mails which I am storing. One is multipart payload type and the other is string payload type.
After receiving mail I am trying to send an auto-generated mails using java mail.
The issue which I am facing is worst case scenario of generating auto-reply from my application i.e infinite loop.
Can someone help ow can I differentiate between a normal mail received and auto-reply received in my mail box and generate auto-replies from my system only for those mails which are not auto-reply type.
It would be nice if explained via code for headers check. I came across through few headers like x-Autosubmitted. But they are returning null if I am trying to print the values in console.
The auto-submmitted markers are described below that you may find helpful:
auto-generated - Indicates that a message was generated by an automatic process, and is not a direct response to another message.
auto-replied - Indicates that a message was automatically generated as a direct response to another message.
auto-notified - Indicates that a message was generated by a Sieve notification system.
no - Indicates that a message was NOT automatically generated, but was created by a human. It is the equivalent to the absence of an Auto-Submitted header altogether.
The RFC 2822 states the following:
Though optional, every message SHOULD have a "Message-ID:" field.
Furthermore, reply messages SHOULD have "In-Reply-To:"
So, you may check for the "In-Reply-To:" value in the header.
Also you may add your own value to the outgoing email, so you may distinguish between an automatically generated reply from your system and manually created.

Failed to retrieve attachments from slack channel using Java

Let's say there is an attachment in the slack channel . And that attachment has some unique identifier So if I type the identifier i should get the attachment as response in the channel.
Example: if i type 45 and its related to an xml file attached in the slack channel, then it should reply with the uploaded attachment in the conversation.
I tried using GET method for https://slack.com/api/channels.history?&channel=<>&count=1&pretty=1&inclusive=true&token=<> and I obtained the history of the conversation in the channel.
Don't know how timestamp and unfurl can help in achieving this.
The API method channels.history returns a list of messages from a specific channel as a big JSON array. It will only return the 100 latest by default and you have to use paging if your channel contains more messages.
Messages are referenced by timestamp (ts). Attachments are elements of its message and references by ID (id), which represents the order their are shown on Slack.
So to access a specific attachment you first need to find the correct message by its timestamp and then you can find the attachment by its ID.
If you know the timestamp of the message you are interested in you can include latest=timestamp and oldest=timestamp in your API call to receive only that message.
If you do not know the timestamp of the message you will have to retrieve all messages within a reasonable timeframe and then detect your message based on some other criteria.
Btw. I would consider switching to conversations.history, which is the new and recommend API method for retrieving messages from all type of channels.

Send XML content to a JMS queue using 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)

Android - PubNub - Pass the UUID or Username of a user with each sent message

HelloI've built an Android application that uses PubNub to create a chat channel between each user. I would like to be able to identify which users have sent which messages. Currently the login of my app is handled by Parse so each user has a unique username. I found some documentation and example code where rather than sending just the message string, an object was set up that contained the UUID and message string as two different objects that could then be extracted on the subscribe side but from what I could tell this was only in the PubNub javascript code not the Java code for Android.Right now i'm thinking that the only way for me to do this is to attach the UUID/username to the beginning of my message string with a special character to seperate the UUID and the message and then split it up and read it in on the subscribe side. For example String message = "uuidhere_messagehere";. Is this the correct way to approach this or is there a better, more convenient way of doing this?thanks
Correct - PubNub does not inject anything into your messages so you will need to include the sender id within each message that is published. Here's is a simple example of a JSON message you might publish:
{'sender_id':'user_333', 'msg':'this is my msg to you-hoo-hoo'}
Of course, the JSON message can have any key/value pairs you require.

Web Socket - Spring : Confirm of message received

I am sending a message through WebSocket with Spring from Tomcat Server to a SockJSClient with the method:
WebSocketSession.sendMessage(WebSocketMessage<?> message)
and I would like to know when the message has been received (eventually with complementary information, for example whether the logic on client successfully processed), then go for next message.
This is an Activity diagram that explains the use case.
How can I receive confirmation of reception or result from client?
As Erwin pointed, you can adopt some higher protocol providing such feature like STOMP. However, if you are afraid to adopt it only for that feature, you can implement that feature by yourself.
The first thing is to give each message id to identify each message, type to recognize the purpose of each message, data to transport a message's content and reply which is a flag to see whether or not ACK is required and to use a format like JSON to serialize/deserialize an object containing these data into/from WebSocket message.
When sending a message, it creates an object by issuing a new id for that message, setting type to message and data to given message and reply to true if ACK is required or false if not. And it serializes it into JSON and sends it as a WebSocket message. - https://github.com/cettia/cettia-protocol/blob/1.0.0-Alpha1/lib/server.js#L88-L110
When receiving a message, it deserializes JSON to the above object. If reply is true, it sends a special message whose type is reply setting data to id of that message. Then, the counterpart can confirm that its counterpart has received a message whose id is id. - https://github.com/cettia/cettia-protocol/blob/1.0.0-Alpha1/lib/server.js#L46-L76
The above links point similar implementation in Cettia which is a real-time web application framework I wrote. Though that implementation is a little bit complex as it is designed to allow for user to handle callbacks with result, you are likely to get the basic idea.
API implemented by that link looks like the following.
A server or client which requires a result of event processing.
// Using Java server with lambda
socket.send("foo", "bar", result -> /* resolved */, reason -> /* rejected */);
The corresponding client or server which has a responsibility to submit the result.
// Using JavaScript client with arrow functions
socket.on("foo", (data, reply) => {
// data is 'bar'
// 'reply.resolve(result)' if it successes
// 'reply.reject(reason)' if it fails
});

Categories

Resources