Apache camel how insert property in SetBody - apache

I am creating a message in my route, using:
<setBody id="_setBody1">
<constant>
<![CDATA[
<?xml version="1.0" encoding="UTF-8"?&>
..........
<mes:CalendarView MaxEntriesReturned="5" StartDate="(property.DateStart)" EndDate="(property.EndDate)"/>
But property doesn't work. In log I see:
<mes:CalendarView MaxEntriesReturned="5" StartDate="(property.DateStart)" EndDate="(property.EndDate)"/>
How I can insert property in message?

It looks like you want to set some properties inside a static content of XML. I suggest using one of the templates.. such as velocity. It will allow you to do property replacement and manage the static content outside of the route (which is handy for testing and other maintenance)

Yes, i created property before:
<setProperty id="_setProperty1" propertyName="DateStart">
<groovy>new java.text.SimpleDateFormat('yyyy-MM-dd').format(request.body.getStartDate())</groovy>
</setProperty>
But i want to insert this property in content of xml, inside Apache Camel route.

Related

Registering a Template within an intellij Plugin

I have created my Apache Velocity template under /resources/fileTemplates/internal/myTemplateClass.vm and would like to use it through:
final JavaDirectoryServiceImpl javaDirectoryService = new JavaDirectoryServiceImpl();
javaDirectoryService.createClass(myPsiDirectory,
"MyClassname",
"myTemplateClass");
So I added the following in my plugin.xml:
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
<internalFileTemplate name="myTemplateClass"/>
</extensions>
However when I run my plugin it claims that it did not find a template with the name "myTemplateClass". I assume it is cause I haven't linked to the file perse. Where should I link this?
Thanks
If you have an <internalFileTemplate> with the name of "myTemplateClass" and you want to use it to create a Java class, the template needs to be stored as fileTemplates/internal/myTemplateClass.java.ft. So you need to change the extension of your file.

How to set boolean in xml-action script

I am trying to set a flag so I do something like this:
<set field="existingFound" value="false" type="Boolean"/>
but the following line prints "true" in the log:
<log message="storeProperty, existingFound (0): ${existingFound}"/>
What is the best way to set flags?
The set.#value attribute is interpreted as a Groovy String (GString) so any non-empty value will be interpreted as true. The set.#from attribute is interpreted as a Groovy expression, so simply using from="false" instead of value="false" will get the desired result.
To see the generated Groovy code from an XML actions block you can write code that will cause an error and then the script will be logged, or you can change the log4j.xml file to turn on "debug" level logging for the XmlActions class (the latest log4j.xml file in the GitHub repository has an example of this). Looking at the Groovy code generated from the XML elements is a good way to track down issues when what is happening just doesn't make sense.

Variable in an attribute in Struts custom tag

I am trying to use a variable inside a custom Struts tag something like follows -
for(String currentMacro : (List<String>)(request.getAttribute("individualMacros"))) {
name = currentMacro.<some-operation>
<html:mce name = "hmtl_<%= name %>" />
Something like this. But <%=name%> is not replaced with the variable value. It works when I am using the variable with a pure HTML tags.
Is there any any way to accomplish this in this case?
Thanks.
Use JSP EL (assuming JSP 2.0, and you put "name" into scope). You could also check to the if the TLD allows rtexprs.
<html:mce name="html_${name}"/>
But why use scriptlets? There's rarely (ever?) a good reason.
Since we are taking about a custom tag, my guess is that in the TLD file there isn't the rtexprvalue option set to true for that particular tag attribute:
<attribute>
<name>name</name>
<rtexprvalue>true</rtexprvalue>
.......
</attribute>
The rtexprvalue specifies that the attribute value may be dynamically evaluated at runtime.
If set to "false" it means that the attribute has a static value which is evaluated at translation; if set to "true" it means the value can be determined dynamically at runtime. Default is "false".
If the scriptlet does not work, it most likely means rtexprvalue is false. If you don't have the liberty to change that, then expressions won't work on that particular attribute.

Struts 1.x tags usage question

I have a jsp page with the tags:
<logic:iterate id="var" ...
....
<bean:write name="var" property="p1" ...
etc.
And I need, on each iteration, to generate a href composed from the various bean's properties. I even need to URLEncode some of them so the link works.
Something like
<logic:iterate id="var" ...
....
<html:link action="otheraction.do?_X_
<bean:write name="var" property="p1" ...
etc
where X is generated by collecting the bean's properties; something like
String X="p1="+URLEncode(p1)+"&p2="+SimpleDateFormatof(p2)+"&p3="+p3;
How can I do that ?
Thanks in advance.
Better to make one POJO class.
1. Assign all your values to the object in Action which is being called before your jsp page comes in the picture.
2. Keep the object of POJO to request attribute.
3. Get the value from request attribtue on JSP using <bean:write> tag.

Problem with struts 2 and json plugin

I'm using the json plugin that comes with struts 2 (json-lib-2.1.jar) and trying to follow the website to set it up.
Here's my struts.xml
<struts>
<package name="example" extends="json-default">
<action name="AjaxRetrieveUser" class="actions.view.RetrieveUser">
<result type="json"/>
</action>
</package>
</struts>
but I get this warning:
SEVERE: Unable to find parent packages json-default
Is there something else I'm supposed to do?
Edit:
I added this method to my RetrieveUser:
public Map<String,Object> getJsonModel()
{
return jsonModel;
}
And my struts.xml looks like this:
<struts>
<package name="example" extends="json-default">
<action name="AjaxRetrieveUser" class="actions.view.RetrieveUser">
<result type="json"/>
<param name="root">jsonModel</param>
</action>
</package>
</struts>
However, I don't think the response is going from the RetrieveUser class to the javascript. I'm using firebug and no request gets sent.
I believe that net.sf.json-lib is just a toolset you can use in your Java to build up JSON-ready objects, suitable to be returned by actions such as you describe.
Probably, you need to include struts-json-plugin - make sure its version matches your struts version.
I notice also that as written, your action will attempt to return RetrieveUser, serialized. Most implementations I've done/seen specify the root object to be returned, by adding
<param name="root">jsonUser</param>
Under the tag, and define this method in RetrieveUser
public Map<String, Object> getJsonUser()
[This is mentioned in the Sruts2 doc]. Hope that helps.
[edit] I use Map - you could also use the object structures provided by json-lib instead.
Re: Your edit. Probably need to see your calling javascript. And probably I will suggest that you make sure you have both a success and an error handler. Can you debug/log to show that the method is being called in java ? Do your logs show anything ? This is usually some sort of error....