How to send plain text JmsMessage with empty header - java

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.

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.

How to set additional authentication properties in apache camel DSL or inside the camel Processor?

Here I am trying to convert Json data to CSV format and finally send this file to Ofbiz server api but the api endpoint require some authentication content when I send parameter in URL I got the output below.
{"_ERROR_MESSAGE_":"Error calling event: org.apache.ofbiz.webapp.event.EventHandlerException: Found URL parameter [configId] passed to secure (https) request-map with uri [uploadAndImportFileFromCSVFile] with an event that calls service [uploadAndImportFile]; this is not allowed for security reasons! The data should be encrypted by making it part of the request body (a form field) instead of the request URL. Moreover it would be kind if you could create a Jira sub-task of https://issues.apache.org/jira/browse/OFBIZ-2330 (check before if a sub-task for this error does not exist). If you are not sure how to create a Jira issue please have a look before at https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Contributors+Best+Practices Thank you in advance for your help.","sessionId":"someId.jvm1","removePathAlias":false,"loggedIn":true,"USERNAME":"__","_LOGIN_PASSED_":"TRUE","webSiteId":"API"}
After that I used MultipartBuilder to send request below.
exchange.getIn().setHeader("bearer",token);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
File file =new File("//home/r2/Desktop/ofBizFile/orderFile.csv");
builder.addPart("configId",new StringBody("CON_ID"));
builder.addPart("fileTypeEnumId",new StringBody("CSV_FILE"));
builder.addPart("_uploadedFile_contentType",new StringBody("text/csv"));
builder.addPart("uploadedFile",new FileBody(file));
exchange.getIn().setBody(builder.build());
I also tried something like this.
exchange.setProperty(Exchange.CHARSET_NAME, "ISO-8859-1");
exchange.getIn().setHeader(Exchange.HTTP_QUERY,"USERNAME=abc&PASSWORD=bc69");
exchange.getIn().setBody("configId=CON_ID&fileTypeEnumId=CSV_FILE");
Here is my camel route
//Route 1
from("couchdb:http://localhost:5984/order")
.process(new JsonToCsvProcessor())
//Storing file into local directory
.to("file:/home/r2/Desktop/ofBizFile?fileExist=append&fileName=order-${date:now:yyyyMMdd}.csv");
.to("direct:jsonToCsv");
//Route 2
from("direct:jsonToCsv")
.setHeader(Exchange.HTTP_QUERY,constant("USERNAME=__&PASSWORD=__"))
//For get token
.to("https4://SomeAddress.com/centerAPI/getAuthenticationToken")
//Get the token and set required parameter for route 3
.process(new ProcessorGetToken())
.to("direct:hold");
//Route 3
from("direct:hold")
.setHeader(Exchange.HTTP_QUERY,constant("USERNAME=__&PASSWORD=__"))
.to("https4://SomeAddress.com/centerAPI/uploadAndImportFileFromCSVFile?throwExceptionOnFailure=false")
//How I know the file is submited successfuly ?
.to("stream:out").end();
So the problem is how I can send data inside the body in Route2 ProcessorGetToken for next Route3 ?
I'll give a shot into the dark here. Reading your error message:
The data should be encrypted by making it part of the request body (a form field) instead of the request URL
Don't you have a documentation about this integration? I think you need more clarification about this process and what's need to encrypt your data before sending it.
Also, try to set the Exchange.HTTP_METHOD to POST into your route, like this:
exchange.setProperty(Exchange.CHARSET_NAME, "ISO-8859-1");
exchange.getIn().setHeader(Exchange.HTTP_METHOD, "POST");
exchange.getIn().setHeader(Exchange.HTTP_QUERY,"USERNAME=abc&PASSWORD=bc69");
exchange.getIn().setBody("configId=CON_ID&fileTypeEnumId=CSV_FILE");
Take a look into this unit test to see more examples sending data over HTTP. There's also many other tests there.

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
});

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