hi am working with wso2esb4.9.0,
I have a service which generates email in that i have property as mailbody which am using to pass as body of the email.
<property name="mailbody"
expression="fn:concat('You have received a new Ticket',':','TicketID-',get-property('Ticketid'),', ','TicketDetails-',get-property('Details'))"
scope="default"
type="STRING"/>
when am passing this property in my service am getting a mail and mail body looks like as shown below.
You have received a new Ticket: TicketID-3021668982752443, TicketDetails-Test ticket details
I want to add a new line in the value so that the mail body can look like below instead of a single line.
You have received a new Ticket:
TicketID-3021668982752443,
TicketDetails-Test ticket details
Is there any Xpath function or way to add new line to my string value.
I have tried to include \n and
in fn-concat of mailbody property but it is not working.
As the XPath expression is inside of an XML document doing expression="fn:concat('You have received a new Ticket',':
','TicketID-',get-property('Ticketid'),', ','TicketDetails-',get-property('Details'))" should suffice.
If you really use XPath 2.0 then you can also use expression="fn:concat('You have received a new Ticket',':', codepoints-to-string(10),'TicketID-',get-property('Ticketid'),', ','TicketDetails-',get-property('Details'))".
Related
I am using mailgun Templates with Go to send emails. However when the text in my template fields contain \n no newline is added. My basic code looks like the following:
message := m.mg.NewMessage(sender, subject, body, recipient)
message.SetTemplate("my-template")
_ = message.AddTemplateVariable("myText", event.Text)
// ... Code for sending
I saw this answer about sending mail with newlines, however when I implement it like the following:
_ = message.AddTemplateVariable("myText", strings.ReplaceAll(event.Text, "\\n", "<br />"))
The email contains <br /> text in the body but no newlines.
I also tried adding the following field in the css of my template: white-space: pre-wrap; but still there was no break. Thanks for any help with adding a newline to a Mailgun Template with Golang.
Try to use triple-stash in your template instead of double-stash
{{var1}} -> {{{var1}}}
I have a field in a bean that is failing 2 validations, as such 2 messages are being inserted in ActionMessages with the following command:
validationErrors.add("field1", new ActionMessage("Phone number is greater than 10 digits", false));
validationErrors.add("field1", new ActionMessage("Phone number has invalid characters", false));
Although I see the errors in the ActionMessages object (by setting a breakpoint in the debugger), only the first one gets displayed in my JSP, where I have:
<logic:messagesPresent message="true">
<html:messages id="message" property="field1" message="true">
<logic:present name="message">
<c:out value="${message}"/>
</logic:present>
</html:messages>
</logic:messagesPresent>
Why is only the first message displayed, when <html:messages> should loop through all the messages where the property is "field1"?
I ended up figuring out my issue and it had to do with how I am creating the new ActionMessage.
When you use:
public ActionMessage(<error message>, false)
While it allows you to display a literal value by using the <html:messages> tag in conjunction with either a <bean:write> or <c:out>, it won't iterate over multiple messages for a given property, why I don't know.
I tested and found that if I use a resource bundle and create the ActionMessage with a standard:
public ActionMessage(<key in resource bundle>)
I am able to display multiple messages for a single property.
Unfortunately, because I am using hibernate validator I don't want to use a resource bundle and struts to replace the values (would rather have the hibernate validator annotation replace values) and will likely just display a single message at a time for now.
Struts <logic:messagesPresent> tag checks that the messages exist on the current request.
Messages are found in the request under the key Globals.MESSAGE_KEY. If you use attribute message only messages are checked.
By default the tag will retrieve the request scope bean it will
iterate over from the Globals.ERROR_KEY constant string, but if this
attribute is set to true the request scope bean will be retrieved
from the Globals.MESSAGE_KEY constant string. Also if this is set to
true, any value assigned to the name attribute will be ignored.
The <html:messages> tag is used to display the messages if specified attribute message is true.
Now you have used a property attribute that filters messages for the given property.
Name of the property for which messages should be displayed. If not
specified, all messages (regardless of property) are displayed.
If you have only one message with the field1 property, then only one message will be displayed.
Look here how can you use action messages object
ActionMessages messages = new ActionMessages();
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.common.field1.required");
saveMessages(request, messages); // storing messages as request attributes
Properties file:
error.common.field1.required = Field1 is required.
And display messages
<logic:messagesPresent message="true">
<html:messages id="message" message="true">
<bean:write name="message"/><br/>
</html:messages>
</logic:messagesPresent>
It will loop all massages under the global message key. If you want to use custom key you can use it with the parameter of ActionMessage
messages.add("field1", new ActionMessage("error.common.field1.required");
to retrieve the message
<logic:messagesPresent message="true">
<html:messages id="message" property="field1" message="true">
<bean:write name="message"/><br/>
</html:messages>
</logic:messagesPresent>
I am using the following format for my xpath expression in VB.Net workflow:
String(xpath)
which returns me the expected string value, but also a new line charac after the value which is breaking my logic.
How do I get rid of that new line?
Any pointers?
More Info as requested:
The normalize-space is still returning the new line.
The xml is too big, so pasting the snippet under its immediate parent here:
<Characteristic_Value_Population_Rule_SpecChar_Value_Population_Rule ID="f0baf095-5e84-4146-9c72-7691205df16b" xsi:type="SpecChar_Value_Population_Rule" Pattern="T_RelatedEntityRule">
<Entity_T_RelatedEntityGroup_AND ID="a9adc94f-615b-477b-8841-94887429a83e" xsi:type="T_RelatedEntityGroup_AND" Pattern="TRelated_EntityGroup">
<Entities_TRule_Value_EntityRef ID="f521569f-41a3-42ad-9974-3aea9557460b" xsi:type="TRule_Value_EntityRef" Pattern="TRule_Complex_Value">
<Name>Modem ADSL/VDSL/TV/PSTN b-box 3 0</Name>
<Entity>000006,000069,000078</Entity>
</Entities_TRule_Value_EntityRef>
<Entities_TRule_Value_EntityRef ID="9025dfc0-bd7d-4252-8dad-f95a818b8688" xsi:type="TRule_Value_EntityRef" Pattern="TRule_Complex_Value">
<Name>Modem ADSL/VDSL2/TV/Italk/off b-box 2 039</Name>
<Entity>000006,000069,000077</Entity>
</Entities_TRule_Value_EntityRef>
<Name>Acquisition Type is Rent in the context of Belgacom Internet</Name>
</Entity_T_RelatedEntityGroup_AND>
<Name>Acquisition Type is Rent in the context of Belgacom Internet</Name>
<Characteristic ID="ae3f9304-31a7-4c0b-8723-c553b136410e" Pattern="TSpecChar" OrigType="SpecCharItem">
<Specification_Characteristic ID="c5dec18e-806c-46d1-8294-e83117650b5b" Pattern="TSpecCharValue" OrigType="SpecCharValueItem">
<Value>Rent</Value>
<IsUserDefinedValue>false</IsUserDefinedValue>
</Specification_Characteristic>
<Name>Acquisition Type</Name>
</Characteristic>
</Characteristic_Value_Population_Rule_SpecChar_Value_Population_Rule>
</Package>
I am trying to get the value c5dec18e-806c-46d1-8294-e83117650b5b which the xpath expression does return but with the new line.
i am now using the xpath:
string(normalize-space(//Package/Characteristic_Value_Population_Rule_SpecChar_Value_Population_Rule/Characteristic/Specification_Characteristic/#ID))
Try String(normalize-space(xpath)). If that does not help then show us more context.
Given a Camel route that is supposed to extract some inner parts of an XML message, create a new message from it then pass it on.
from(SUB_EXTRACT_XML)
.setExchangePattern(ExchangePattern.InOut)
.setBody().xpath("//mmsg:MyMessage/mmsg:AnyPayload/*", namespaces)
.setBody().simple("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n${in.body}")
.to(...)
For correct input messages like this (an "embedded" xml message is inside defined in schema by xs:any), it's working since the message is what I expect it to be:
<mmsg:MyMessage>
<mmsg:RandomTags/>
...
<mmsg:AnyPayload> <!-- xs:any in xsd -->
<some><xml/><here/></some>
</mmsg:AnyPayload>
</mmsg:MyMessage>
Given there is some issues with the XML message, such as the mmsg:AnyPayload tag is missing, so that the XPATH can't do its job:
<mmsg:MyMessage>
<mmsg:RandomTags/>
...
<some><xml/><here/></some>
</mmsg:MyMessage>
The XPATH will fail to extract the data and the entire XML message (including mmsg:MyMessage) is passed on, which is not intended. I rather throw some exception at this stage.
Question:
Is there a way to check if the xpath expression actually found the element refered to later in the route or if it failed to extract the given element(s)?
I know I could have done some schema validation of the message before and reject rubbish messages, but are there any way to see if a XPath expression fails?
A solution would be to use the choice() DSL in the route like this:
from(SUB_EXTRACT_XML)
.setExchangePattern(ExchangePattern.InOut)
.choice()
.when(xpath("//mmsg:MyMessage/mmsg:AnyPayload", namespaces))
.setHeader("Status", "OK") // just for another example how to transmit some variable between two routes
.setBody().simple("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n${in.body}")
.endChoice()
.otherwise()
.log(LoggingLevel.ERROR, "LoggerName", "Error message; Stop the processing")
.stop()
.endChoice()
.end()
// Just to show the headers are following the route...
.to("DIRECT_GO_FORWARD");
from("DIRECT_GO_FORWARD")
.setExchangePattern(ExchangePattern.InOut)
.choice()
.when(header("Status").isEqualTo("OK"))
.bean(new SampleProcessor())
...
.end()
...
.to("...");
the second route is just there to show you can use the header set in the first route (and the body too).
I have a text box to enter description
If i submits that need to be send through ajax and store in db.
Problem:-
Example text in textbox:- "Hi all & solve my problem"
in the next page i am getting till "Hi all"
Remaining text is missing, If I pass through get or post method using ajax.
Give me the solution. How to get all the content I placed in text box along with "&"
You need to urlencode string with escape or encodeURIComponent functions.
Yes, I have faced same type issue and find out solution that we need to pass data as a key value pair,
I had passed data in Ajax like:
data : email=" + email + "&name='" + name
But right way for passing data in Ajax is :
data: {
email : email,
name : name
}