GCM Topic messaging error - java

I want to let my application to register for topic messaging, but each time I try to call Topic registration it is returning the error below
java.lang.IllegalArgumentException: Invalid topic name:
Using the method bellow
GcmPubSub.getInstance(context).subscribe(regToken, "/topics/testTopic", null);
I am using the tutorial on this link https://developers.google.com/cloud-messaging/topic-messaging. I will greatly appreciate your help on this error.

Please try this with the sample app. "/topics/testTopic" should be fine. As mentioned in the documentation, any topic name matching this regex should be fine: /topics/[a-zA-Z0-9-_.~%]+

For anyone running into this error: double check that you conform to the specification on the topic name: /topics/[a-zA-Z0-9-_.~%]+.
The original question actually does conform to the spec and I have no answer for why the error occurs. However another way to trigger the error is not conforming to the spec. In my case I mistakenly assumed path separator characters are allowed and used a topic like /topics/users/123 to mimic my REST API. The last slash is not allowed.

Related

Apache Camel and MQTT: How to use simple language for e.g. topics?

I am using Camel for wanting to push a resource to a topic.
The name of the topic is depending on the content of a resource.
For this one I've implemented the choice definition.
I've put the name of the generated topic in the header of the message:
final String resource = exchange.getIn().getBody(String.class);
String topic = resource + ".get.request";
exchange.getIn().setHeader("topic", topic);
When it comes to the endpoint part of the Camel route, then I wanted to read and re-use the topic out of the exchanged message:
// the logging shows everything up correctly, with both variants..
.log("${header.topic} : " + simple("${header.topic}").getText())
// this line is not woking, because the simple language fails here
.to("mqtt:camelMqtt?publishTopicName=${header.topic}?host=" + mqttHost);
If I am putting a hard coded topic instead of the ${header.topic}, then the message is published on the mqtt-topic.
As stated in the code, the to(...)sequence is not working with the Simple Language.
How to solve that kind of issue?
Ok, found it out by myself...
The Simple Language is only evaluated IF the endpoint method toDis used.
Makes totally sense, because this is a dynamic endpoint or at least the parameters of this endpoint are variable.
full line from above:
.toD("mqtt:camelMqtt?publishTopicName=${header.topic}?host=" + mqttHost);

Mule ESB - SMTP Subject from a variable

I'm working on a flow to send an attached file to a mail.
<smtp:outbound-endpoint host="${instance.smtp.host}" port="${instance.smtp.port}" user="${instance.smtp.user}" password="${instance.smtp.password}" responseTimeout="10000" doc:name="SMTP" connector-ref="SMTP" from="${instance.smtp.account}" to="${instance.smtp.user}" subject="Transaction ID #[flowVars.transactionId]"/>
Everything is working well, I already have tested my flow and the mails are arriving to the specified mail address, however, I'm trying to modify the subject dynamically, using a value stored in a variable, and then the problem appears, seems like it's not possible to use my expression to set the subject's mail.
subject="Transaction ID #[flowVars.transactionId]"
This is the error I'm getting.
Root Exception stack trace:
[Error: unresolvable property or identifier: Transaction]
[Near : {... Transaction ID #[flowVars.tran ....}]
^
Do you have any clue about this problem or how can I fix it?
Thanks in advance.
You need to rearrange the expression so all of it is within the #[....]
subject="#['Transaction ID ' + flowVars.transactionId]"
Some fields get parsed as MEL expressions and some are more like templated strings that allow expression substitutions.
(One of Mule's annoyances)
Please debug the application and test if your flow variable for "transactionId" is being set before reaching to the SMTP message source.

Topic name case sensitivity and `condition` || not working

I have built spring java service using API logic in firebase cloud messaging.
Here is the URL for sample spring service https://github.com/petya0111/firebase-spring-service
Reproduce: set the request
Run project
POST http://localhost:8080/notification/messages
Headers:
firebase-server-key : [your generated server key]
Body:
{
"condition": " 'topic' in topics",
"title": "Hello,Via Multiple Topics",
"body": "Hello,Via Multiple Topics"
}
To send messages to condition you must first create topic
Reproduce: create topic
POST https://iid.googleapis.com/iid/v1/{token}/rel/topics/{topic}
headers
Authorization : key=[firebase-server-key]
200 OK
According to the API's documentation, condition field is defined as case-insensitive.
But in practice, it is actually case sensitive.
I am doing two tests with the same topic name (using upper and lower case chars). The original name of the topic I'm trying to send a message is defined as "Topic". Since the field must be case-insensitive, I am trying to use "topiC" and it should still send the message. Unfortunately, it doesn't. The field is actually case-sensitive and this is a huge problem from my perspective.
My second question:
When a non-existent topic is presented. Exchange with URL https://fcm.googleapis.com/fcm/send doesn't return an error.
My third question on this topic is:
Condition OR '||'
"condition": " 'topicChrome' in topics || 'topicFirefox' in topics "
is not working, I have subscribed one token on topic 'topicChrome' and another token on topic 'topicFirefox'.
Gonna go on ahead and add an answer, details similar to my comments.
According to the API's documentation, condition field is defined as case-insensitive. But in practice, it is actually case sensitive.
The topic name always has been case sensitive. The case-insensitive mentioned in the docs refers to the condition parameter. In other words, using:
"condition": "'topicChrome' IN TOPICS || 'topicFirefox' in topics"
(see the upper and lower case words) would be fine.
When a non-existent topic is presented. Exchange with URL https://fcm.googleapis.com/fcm/send doesn't return an error
This is working as expected. It's the developer's responsibility to keep track of which topic exists or doesn't exist (i.e. which ones have subscribers or not), similar to a device group (see my answer here).
For your third question, I've tested the conditions and it was working as expected on my end. I would suggest posting more details (hopefully in a separate question, since multi-questions in a single post isn't really a good practice here), specially showing the response -- is it an error or a success?

Java Mail API: Callbacks

Context:
I am working on a piece of Java code where I am reading mails from an array (which works fine). I was wondering if someone can help me with the callback in order to show a fancy message like Your email was sent.
Questions:
How do I implement this?
Is there any way to get any Boolean type return value from javax.mail to check if the message was sent or not?
Maybe I should create a pool? If yes, how do I do that? Is there any signal to kill the pool?
Code:
// addressTo is the array.
Transport t = sesion.getTransport(this.beanMail.getProtocolo());
t.connect(this.beanMail.getUsuario(), this.beanMail.getPassword());
t.sendMessage(mensaje, addressTo);
t.close();
Quoting from the JavaMail API FAQ (in the context of tracking bounced messages):
While there is an Internet standard for reporting such errors (the multipart/report MIME type, see RFC1892), it is not widely implemented yet. RFC1211 discusses this problem in depth, including numerous examples.In Internet email, the existence of a particular mailbox or user name can only be determined by the ultimate server that would deliver the message. The message may pass through several relay servers (that are not able to detect the error) before reaching the end server. Typically, when the end server detects such an error, it will return a message indicating the reason for the failure to the sender of the original message. There are many Internet standards covering such Delivery Status Notifications but a large number of servers don't support these new standards, instead using ad hoc techniques for returning such failure messages. This makes it very difficult to correlate a "bounced" message with the original message that caused the problem. (Note that this problem is completely independent of JavaMail.)
Source

The security group 'gettingstartedgroup' does not exist

I am trying to learn Amazon AWS. I ran their tutorial package-"GettingStartedApp.java" after setting my access id and access key in the property file. But I see this exception.
Caught Exception: The security group 'gettingstartedgroup' does not exist
Reponse Status Code: 400
Error Code: InvalidGroup.NotFound
How should I correct this?
You are probably trying to use the string "gettingstartedgroup" as a security group.
If you just created your EC2 AWS instance, then you either add a security group with that name or use the default one.
For the latter, just change from gettingstartedgroup to default.
At first, please execute CreateSecurityGroupApp.java and then GettingStartedGroup will be creataed in Oregon region.

Categories