Form bean to session variable - struts

If i can use
<td><textarea><bean:write name="smlMoverDetailForm" property="empFDJoiningDate"/>
</textarea></td>
to displace a value how can i use the struts tags to save a vaiable to the sesssion
in sudo code
session.setAttribute("test" , "<bean:write name="smlMoverDetailForm"
property="empFDJoiningDate"/>");
is this possible?

I don't think so.
Struts tags are only available in jsp pages.
But you can do something like this:
if the bean smlMoverDetailForm is in scope request
session.setAttribute("test",((THECLASSOFTHEBEAN)request.getAttribute("smlMoverDetailForm")).getEmpFDJoiningDate());
else if the bean smlMoverDetailForm is in scope session
session.setAttribute("test",((THECLASSOFTHEBEAN)request.getSession().getAttribute("smlMoverDetailForm")).getEmpFDJoiningDate());

Late but possible. You can set the session scope to your form bean in struts-config.xml file when you map the action.

Related

spring.sql.init.schema-locations Not Working

I'm using profiles to determine which data connector to use (dev=h2, prod=mySQL).
I'm attempting to use
spring.sql.init.schema-locations=
To set the location to the relevant path with properties from the active profile but I keep getting:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]:
Invocation of init method failed; nested exception is java.lang.IllegalStateException: No schema scripts found at location './database/h2/schema-h2.sql'
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.15.jar:5.3.15]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.15.jar:5.3.15]
and the same error no matter where I point the property to.
Is there any other special syntax for declaring which file or which directory under resources for this property? When I edit this property autocomplete in Idea happily shows the folder/file structure, but Spring can't see what I'm pointing to!
Answer as per #Andy Wilkinson's comment above:
Adding classpath: as a prefix resolved the issue.

CMS hippo property reading from .yaml file

I need to read the properties which are stated in my one of the .yaml file(eg banner.yaml). These properties should be read in a java class so that they can be accessed and the operation can be performed wisely.
This is my label.yaml file
/content/documents/administration/labels:
jcr:primaryType: hippostd:folder
jcr:mixinTypes: ['mix:referenceable']
jcr:uuid: 7ec0e757-373b-465a-9886-d072bb813f58
hippostd:foldertype: [new-resource-bundle, new-untranslated-folder]
/global:
jcr:primaryType: hippo:handle
jcr:mixinTypes: ['hippo:named', 'mix:referenceable']
jcr:uuid: 31e4796a-4025-48a5-9a6e-c31ba1fb387e
hippo:name: Global
How should I access the hippo:name property which should return me Global as value in one of the java class ?
Any help will be appreciated.
Create a class which extends BaseHstComponent, which allows you to make use of HST Content Bean's
Create a session Object, for this you need to have valid credentials of your repository.
Session session = repository.login("admin", "admin".toCharArray());
Now, create object of javax.jcr.Node, for this you require relPath to your .yaml file.
In your case it will be /content/documents/administration/labels/global
Node node = session.getRootNode().getNode("content/articles/myarticle");
Now, by using getProperty method you can access the property.
node.getProperty("hippotranslation:locale");
you can refere the link https://www.onehippo.org/library/concepts/content-repository/jcr-interface.html
you can't read a yaml file from within the application. The yaml file is bootstrapped in the repository. The data you show represents a resource bundle. You can access it programmatically using the utility class ResourceBundleUtils#getBundle
Or on a template use . Then you can use keys as normal.
I strongly suggest you follow our tutorials before continuing.
more details here:
https://www.onehippo.org/library/concepts/translations/hst-2-dynamic-resource-bundles-support.html

RHQ - JMX plugin - Update attribute value

I'm using RHQ JMX plugin to get operations and attributes of one custom Mbean.
It is working but I would like to add the possibility to update an attribute value and I can't use the setter function to update it as it's not recognized as an operation.
How can I update my plugin to add this possibility ?
If you're writing your own plugin, you can declare the bean attribute as a:
measurement, to get history of values
resource configuration property, to easily update the value from RHQ
Declaring an int MBean attribue in resource configuration works as follow:
<resource-configuration>
<c:simple-property name="MyAttributeName" type="integer"/>
</resource-configuration>

How to read properties from .properties file in Mule

I'm trying to use Mule Credentials Vault security feature.
I've created .properties file, Security Property Placeholder and defined the key and encryption algorithm.
Now I want to use some of the properties from the file when I return HTTP response.
I have the file src/main/resources/data.properties that contains for example:
In my canvas, under Configuration XML I added:
<secure-property-placeholder:config name="Secure_Property_Placeholder" key="24681357" location="data.properties" doc:name="Secure Property Placeholder" encryptionAlgorithm="DES"/>
<set-variable variableName="card.number" value="${number}" />
In my canvas I have message flow that builds xml 'Create XML response based on User'. The value in settings is:
This doesn't work. The error I get is:
-> org.mule.module.launcher.DeploymentInitException: IllegalArgumentException: Could not resolve placeholder 'key' in string value "${key}"
-> Caused by: org.mule.api.lifecycle.InitialisationException: Invalid bean definition with name 'org.mule.autogen.bean.13' defined in null: Could not resolve placeholder 'key' in string value "${key}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'key' in string value "${key}"
-> Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'key' in string value "${key}"
Does anyone know how can I read the properties from .properties file (credentials vault)? And then use it in my flow?
Thanks,
Keren
If you simply want to get the value for the property number and add it into the XML you can use ${number} from .properties. No need to define any other variables in Configuration XML.
<set-payload value="<user><name>Royal Bank of Canada</name><id>Royal_Bank_Of_Canada</id><cc><company>>Visa</company><number>${number}</number><secret>123</secret></cc></user>" doc:name="Set Payload"/>
However note that the property placeholder is resolved at startup so you will not be able to dynamically retrieve a property based on some user input. For this you will have to do some Java coding. This SO post gives you some hints on how this can be achieved. Based on those answers I have created a simple example on how this can be done with a very simple helper bean.
I'm afraid you just can't. The Mule Credentials Vault is an enterprise feature and therefore tipically you won't have access to the source code unless you are a MuleSoft customer.
Even if you were a customer, the api you'd use would be sort of unsupported. I suggest to manually create a custom java component levearing your code and Jasypt (not as a property placeholder but as a library).
The other option, if you are a customer (I guess you are given you are using the credentials vault) is to contact the official support so they take care of it for you.
The property placeholder is used resolve at startup so you will not be able to dynamically retrieve a property based on some user input.
Use ${propertyName} from .properties in MEL to access particular property
From Dataweave you can read it as given below
p('variablename')
where variablename is defined in property files ex: variablename = 15

Mule - Inject flow or session variable into Spring bean

I am trying to pass a variable to a Spring bean like so:
<component doc:name="Java">
<no-arguments-entry-point-resolver />
<prototype-object class="org.test.MyComponent">
<property key="fileName" value="#[sessionVars.filename]" />
</prototype-object>
</component>
But the expression never resolves? Is there a another way to do this?
This is a confusion with the spring configuration and Mule Expression language(MEL).
Point 1:
Even though the component is defined inside the Mule Config file. The elements (tags) <property/> is from the Springs Bean schema definition. So the attribute values of key and value are not interpreted by the MEL.
Point 2: As it is provided as setter injection which is invoked during loading(instantiation) the value of session variable(run time value) will not be available.
One possible solution to this would be to make the component implement Callable interface of Mule. So that you will have access to the MuleMessage which contains the session variable.
#Override
public Object onCall(MuleEventContext eventContext) throws Exception {
MuleMessage muleMessage = eventContext.getMessage();
muleMessage.getProperty("propertyName", PropertyScope.SESSION);
Hope this helps.
When the Mule server starts, each of the elements are loaded, and the component and spring-object are created. I don't think you can pass session variable or for that matter any variable other than context-properties to object creation happening at server start-up time.