Recently, I use apache velocity for view template in spring framework, and in order to escape the HTML entity, I introduced the "org.apache.velocity.tools.generic.EscapeTool", however, then I found the variable named with "$application" cannot work now, that any variable named with "$application" shows blank, e.g. "$!application.name".
When I removed the velocity tool configuration, "$application" can be read correctly. So anyone knows if the "$application" a reserved word in velocity escape tool or I make a mistake when configuration?
Toolbox config:
<toolbox>
<tool>
<key>esc</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.EscapeTool</class>
</tool>
</toolbox>
Config in spring-beans XML:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="cache" value="true" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="toolboxConfigLocation" value="/WEB-INF/toolbox.xml" />
</bean>
In template file:
<div class="description">
<h2>Application Name:$!application.name</h2>
</div>
Thanks in advance!
The EscapeTool does not put anything in the context, so it is not overriding your $application variable. To find out what is overriding any variable, you might try
$application.class.name
VelocityTools does automatically return the servletContext when $application is used in a template, but (in the case of Tools 2.0) you can configure whether you want to prefer user-set variables (the default) or the servlet api objects. I don't offhand recall if that can be configured in Tools 1.4, but i'm sure you can look it up.
In any case, in Tools 2.x, it is not reserved, but it is also does come with a default value. Since it is acting as those it's reserved, i'm guessing you either turned off userOverwrite or else are using Tools 1.4.
Related
Is there a way in mule to specify a configuration reference dynamically?
instead of having:
<a:connector config-ref="the_config_name" other-properties="here" />
Something like the following?
<a:connector config-ref="#[flowVars.configName]" other-properties="here" />
This is needed because the configuration used has some properties (URL) that does not allow dynamic values since they are instantiated at the start of the mule app.
No, config-refs are static. Instead, configurations themselves can be dynamic in Mule 4. This requires special handling of the parameters so that then can be re instantiated per configuration.
For more information on this, you can take a look here.
First, let me define what I mean by saying private property. Normally, properties can be set using scripting such as follows:
<Property Id="CHECKREGISTRY">
<RegistrySearch Id="CheckRegistryKey"
Root="HKLM"
Key="SOFTWARE\Foo"
Name="Bar"
Type="raw" />
</Property>
<Condition Message="You don't have the required permission to install this tool.">
<![CDATA[Installed OR CHECKREGISTRY]]>
</Condition>
But the problem is that you can bypass this check by simply running a script like this:
msiexec.exe /i FooInstaller.msi /quiet CHECKREGISTRY="#1"
and that is against the very first idea that you should have the registry key to be able to do what you want to do.
As you see, a private property -- if exists -- would prevent this and allow being able to set only from within the MSI installer itself.
I was thinking to go to CustomAction route, but for a very simple thing, it is overly complicated. Is there any simple solution to this problem, or how can we define private properties in the first place?
You can create a private property by naming it with a lowercase letter. Public properties are all-uppercase.
However, you can't use AppSearch to set private properties.
Remember that MSI databases can be inspected so there's no real security. Best you can get is to use custom actions to obfuscate.
By definition, a property consisting only of uppercase letters is public. To make it private use some lowercase characters.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa371245(v=vs.85).aspx
If you are worried about a public property being set in the command line, just explicitly set it to an empty value before AppSearch.
<sec:http auto-config="false" use-expressions="true" pattern="/**"
authentication-manager-ref="authenticationManager" entry-point-ref="authenticationEntryPoint">
<sec:custom-filter ref="myFilter" position="BASIC_AUTH_FILTER" />
<sec:intercept-url pattern="/**" access="permitAll" />
</sec:http>
HI,
What I'm trying to do seems like it would be so simple, yet i've been trying to figure out how to do it for hours. Hopefully someone can help.
I simply want to create an authentication filter that will intercept all incoming requests, do some processing, then pass it on to the next filter in the chain.
When I try and do that using a pttern of /, I keep getting that error "A universal match pattern ('/') is defined before other patterns in the filter chain, causing them to be ignored. Please check the ordering in your namespace or FilterChainProxy bean configuration" even though i've tried all kinds of things, like guaranteeing my filter is the very last one listed in the security.xml file. I've even attempted to specify the order with a filterChainProxy definition like this:
<beans:bean id="filterChainProxy"
class="org.springframework.security.web.FilterChainProxy">
<sec:filter-chain-map>
<sec:filter-chain pattern="/**"
filters="<filterlist, with mine being the very last!>" />
</sec:filter-chain-map>
</beans:bean>
Nothing seemed to work, despite spending hours researching and googling to try and figure that out, so I gave up, and created an entry in the web.xml file for my filter. Finally, I hit a breakpoint in the filter, so I knew it was getting invoked. But then the problem I ran into was, nothing was getting injected by Spring, I'm assuming because I went "outside the framework", and, I can't even pull the authenticated user, I get a Spring error saying i'm not authenticated, yet other filters defined inside the security.xml can pull it just fine.
I'm not sure what to do here; very suprised something so simply is so difficult.
Please advise, thanks
I have some entities with relationships:
component name="Store" persistent="true"
{
property name="Products" fieldtype="one-to-many" cfc="Product";
}
component name="Product" persistent="true"
{
property name="Store" fieldtype="many-to-one" cfc="Store";
}
The above code is simplified. My project resided in C:\ColdFusion9\wwwroot\StoreTracker, and everything worked great.
But then I had to move it to a virtual directory. I moved my project to C:\Projects\StoreTracker, but now the ORM does not work anymore with the following error:
Cannot load the target CFC Store for the relation property Store in CFC Product.
Could not find the ColdFusion component or interface Store.
If I fully qualify the name though by using:
property name="Store" fieldtype="many-to-one" cfc="entities.Store";
then the ORM works. Does anybody know why moving it to a virtual directory causes the ORM to search through the wrong folder for persistent entities, and if there's an easier way to change which folder it's searching through so I don't have to fully qualify every relationship?
Edit:
Here is the relevant part in Application.cfc:
this.ormSettings = { cfclocation="entities" };
And the folder structure for the model folder:
C:\Projects\StoreTracker\entities
There are no sub-folders under the entities folder and all my persistent entities are in there.
I was able to get it to work correctly if I add the following line to Application.cfc:
this.mappings["/entities"] = "C:\Projects\StoreTracker\entities";
Though I'm not sure why this works. Without it, CF ORM seems to read the entities just fine if they only have simple properties, but when there's a relationship, it bombs out saying that it can't find the related CFC. Perhaps a bug?
If by virtual directory you mean a virtual directory set up in Apache or IIS, then this makes sense. Those virtual directories exist in the web server, not in ColdFusion. CF has no knowledge of them.
You probably need to create a ColdFusion mapping to your application. I am not sure exactly how your app is structured or where you are putting your ORM objects, but you may want to add something like this to your Application.cfc in the pseudo-constructor area.
<cfset application.mappings["/StoreTracker"] = "C:\Projects\StoreTracker" />
Update: Oh and don't forget to ormReload()
Following are the two ways of calling an image in your webb application.
<img src="/myapp/img/world.gif" />
OR
<img src="http://www.example.com/myapp/img/world.gif" />
Which will be best to use or both have the same meaning. If both do not have the same meaning then why? and is there any performance constraints if I use the second method in my app to call all files (images, swf, flv etc..)
Generally speaking, the first method should be your preferred way of referencing any resources that are part of your application. It is called a relative URI reference and it allows you to transfer your application to another domain-name without changing all the links.
You may even consider using relative paths such as
<img src="img/world.gif" />
... assuming that the HTML above appears at some place like http://www.example.com/myapp/main.html
That way you are also not tied to the /myapp path prefix and could easily move your application to /superapp without changing a thing.
Most application frameworks and templating systems have a way of reporting the root URI of the current application. In such cases it may be most convenient to use something like
<img src="$(APPROOT)/img/world.gif" />
... depending on what specific replacement/expansion mechanism your particular envrionment has. Here it is assumed that $(APPROOT) will be replaced with the absolute base URI of the current application.
The former method is a relative URL that locates resources relative to the server’s root. The latter is an absolute URL that indicates not just the directory, but the host, subdomain, even protocol.
They each have their pros and cons. Using a relative path makes it easier to migrate to a new domain since the domain name is not part of the URL. Using an absolute path makes it easier to organize your files since you don’t have to use things like ../../images/ (which can makes things messy and difficult to read).
As for performance, the only issue is that the absolute URLs are a slightly longer (though not always), otherwise no.
There is no performance issues but many times you work and test in a development environment and if you use the second form it would imply to change something like this:
<img src="http://beta.example.com/myapp/img/world.gif" />
to
<img src="http://www.example.com/myapp/img/world.gif" />
So it's better to have always an absolute-relative URI for all the resources
Use your web application framework's HTML helper for generating URLs.
For example,
In Java Servlets: <c:url value='/img/word.gif' />
In CakePHP: <?php echo $html->url('/img/word.gif'); ?>
In Rails:`<%= link_to ... %>
The reason for using your framework's HTML helper is because moving your web application will not disrupt your URLs.