Using smtp with recipientList in Camel - apache-camel

I am trying to use SMTP component inside recipientList.
.recipientList(simple("smtps://smtp.gmail.com?username=abc#gmail.com&password=RAW(abc)&to=${header.alertTo}&subject=RAW(alert)"));
When the value of ${header.alertTo} is just a single email address, this works. However, if it is comma separated list of address it throws exception.
No endpoint could be found for: def#gmail.com&subject=RAW(Alert), please check your classpath contains the needed Camel component jar. and the stracktrace is org.apache.camel.NoSuchEndpointException: No endpoint could be found for: def#gmail.com&subject=RAW(Alert), please check your classpath contains the needed Camel component jar.
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:65)
at org.apache.camel.util.ExchangeHelper.resolveEndpoint(ExchangeHelper.java:85)
at org.apache.camel.processor.RecipientListProcessor.resolveEndpoint(RecipientListProcessor.java:223)
at org.apache.camel.processor.RecipientListProcessor.createProcessorExchangePairs(RecipientListProcessor.java:163)
at org.apache.camel.processor.MulticastProcessor.process(MulticastProcessor.java:208)
at org.apache.camel.processor.RecipientList.sendToRecipientList(RecipientList.java:153)
at org.apache.camel.processor.RecipientList.process(RecipientList.java:112)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
I was earlier using "to" to send these mails. That works fine. But later due to a change involving configurable email addresses for different routes I have to use recipientList.

You can change the delimiter char in the recipient list to something else than comma.
See the documentation for how to do that
http://camel.apache.org/recipient-list.html

Related

PrettyPrint feature does not work in Apache Camel

I have been trying to leverage the PrettyPrint feature to display the result of my API that is using Apache Camel. Here is the context. I have this route in my code
// Route Definition for processing Health check request
from("direct:processHealthCheckRequest")
.routeId("health")
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(200))
.setBody(constant(healthCheckResponse));
When I'm using Postman to test my API, the display is in pretty mode even though it is not set to true, like so
{
"status": "UP"
}
Now when I'm using the following code to set the PrettyPrint to false, I'm still getting the same result. It looks like the PrettyPrint feature is not working as it is supposed to
// Route Definition for processing Health check request
from("direct:processHealthCheckRequest")
.routeId("health")
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(200))
.setBody(constant(healthCheckResponse))
.unmarshal()
.json(JsonLibrary.Jackson, HealthCheckResponse.class, false);
I'm expecting the result to be displayed on one line like here without changing the type from JSON to string.
{"status": "UP"}
Could someone please advice on this?
I've bumped into the same issue always when manually setting the HTTP_RESPONSE_CODE header. I don't know why it technically happens - without it the HTTP response always returns proper JSON for me.
Setting CONTENT_TYPE header to application/json has solved it:
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
The solution that finally worked was to set the following in my application.properties file.
camel.rest.data-format-property.prettyPrint=false
or not to provide that property at all.
Try this:
<removeHeaders id="removeHeaders_http*" pattern="CamelHttp*"/>
<setHeader headerName="Content-type" id="content_setHeader">
<constant>application/x-www-form-urlencoded</constant>
</setHeader>
Same with Java DSL:
.removeHeaders("CamelHttp*")
.setHeader("Content-type", constant("application/x-www-form-urlencoded"))

camel-exec : No endpoint could be found error

Below is the consumer endpoint. Trying to execute linux/unix command using camel exec process uri.
<recipientList>
<simple>exec:bash?args=-c CFTUTIL SEND IDF=${property[cftFlowIdentifier]}, PART=${property[cftParterName]}, FNAME=${property[cftFullFilePath]}, FNAME=${property[cftDestinationPath]}/${property[cftFileName]}</simple>
</recipientList>
Above endpoint resulting in below error..
org.apache.camel.NoSuchEndpointException: No endpoint could be found for: PART=
Kindly check if there is anything wrong in invoking above command using camel exec uri. Same command is getting executed successfully in normal java program.
Recipient List EIP accepts comma separated list of endpoints. If you need to use comma in URL, then disable or use another delimiter.
<recipientList delimiter="false">
<simple>...</simple>
</recipientList>
You can also switch to To D EIP, which is more suitable for your needs, as you call just one endpoint.
<toD uri="exec:bash?args=-c CFTUTIL SEND IDF=${property[cftFlowIdentifier]}, PART=${property[cftParterName]}, FNAME=${property[cftFullFilePath]}, FNAME=${property[cftDestinationPath]}/${property[cftFileName]}"/>

splitResults option shows unknown in apache camel google-sheets-stream component

I'm using apache camel google-sheets-stream component to read google sheet and it is working fine, but I want to split the body into rows and columns, there is an option called "splitResults" given in camel doc, but when I'm using that option it throws "unknown parameters" error.
Does anybody have any idea about this?
Below is my camel route:
from uri="google-sheets-stream://spreadsheets?accessToken=MY_TOKEN_HERE&clientId=MY_CLIENT_ID&clientSecret=MY_CLIENT_SECRET&applicationName=CamelGoogleApp&refreshToken=1/zwgy73W-pcNoCtbOxs_t4b0&spreadsheetId=1hkw_0oOaQDIRZVX_19LpywE&range=Form Responses 1"
Camel Doc that I followed :
https://github.com/apache/camel/blob/master/components/camel-google-sheets/src/main/docs/google-sheets-stream-component.adoc
Camel google-sheet Version: 2.24.1
Log:
There are 1 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{splitResults=true}]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:209)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1143)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3729)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3443)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:209)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3251)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3247)

Exchange body substring in log message

How to log exchange body substring as message attribute of log component?
I have tried these:
<log message="SEND RESPONSE TO WEB SERVICE: Headers:[${headers}]\nBody:[${bodyAs(String).substring(0,1000)}]"/>
<log message="SEND RESPONSE TO WEB SERVICE: Headers:[${headers}]\nBody:[${body.toString().substring(0,1000)}]"/>
but none works. First variant is marked as mistake by IDE Camel plugin and does not allow application to start, and the second one throws the exception about calling toString() at null (although body is not).
ps body is really instance of String.
Read this page, particularly the section "Full Customization of the Logged Output"

Apache Camel route with no "to" endpoint

I am using Apache Camel to assist with capturing message data emitted by a third party software package. In this particular instance, I only need to capture what is produced by the software, there is no receiver on the other end (really no "end" to go to).
So, I tried to set up a route with just the "from" endpoint and no "to" endpoint. Apparently this is incorrect usage as I received the following exception:
[2018-08-15 11:08:03.205] ERROR: string.Launcher:191 - Exception
org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> From[mina:udp://localhost:9877?sync=false] <<< in route: Route(route1)[[From[mina:udp://localhost:9877?sync=false]] -... because of Route route1 has no output processors. You need to add outputs to the route such as to("log:foo").
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1063)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:196)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:974)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3301)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3024)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:175)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2854)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2850)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2873)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2850)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2819)
at {removed}.Launcher.startCamel(Launcher.java:189)
at {removed}.Launcher.main(Launcher.java:125)
Caused by: java.lang.IllegalArgumentException: Route route1 has no output processors. You need to add outputs to the route such as to("log:foo").
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1061)
... 13 more
How do I set up a camel route that allows me to intercept (capture) the message traffic coming from the source, and not send it "to" anything? There is no need for a receiver. What would be an appropriate "to" endpoint that just drops everything it receives?
The exception suggestion of to("log:foo"). What does this do?
You can see if the Stub component can help
http://camel.apache.org/stub.html
Example:
from("...")
.to("stub:nowhere");
The exception suggestion of to("log:foo"). What does this do?
It sends your route messages to an endpoint with a component of type log:
(http://camel.apache.org/log.html) - component which basically dumps message contents (body and/or headers and/or properties) to your log file using appropriate log category.
If you just want to drop everything received, it's a good choice:
to("log:com.company.camel.sample?level=TRACE&showAll=true&multiline=true")
Apparently if you're under Linux or Unix, you can also redirect to /dev/null like in this example:
to( "file:/dev?fileName=null")
I am not sure it can be used on Windows but I don't think so.
Note that the syntax: to( "file:/dev/null") does not work as it point to a directory called null but with the fileName option it will work.

Resources