Hi all,
I used Velocity as template engine for my application but it threw a
run-time security error.
This is my source code:
--------------------------------
public class velocity_tmpl extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
{
try {
Properties properties = new Properties();
properties.setProperty ("runtime.log.logsystem.class",
"org.apache.velocity.runtime.log.NullLogSystem");
properties.setProperty("file.resource.loader.path","../
velocity_example");
properties.setProperty("resource.loader", "file");
properties.setProperty
(
RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,"org.apache.velocity.runtime.log.Log4JLogChute"
);
Velocity.init(properties);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
VelocityContext context = new VelocityContext();
Template t = new Template();
context.put("name", "Velocity");
context.put("project", "Jakarta");
StringWriter w = new StringWriter();
try {
t = Velocity.getTemplate("template.vm");
//Velocity.mergeTemplate("template.vm", context, w);
//Velocity.mergeTemplate("template.vm", context, w );
t.merge(context, w);
} catch (ResourceNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ParseErrorException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (MethodInvocationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("template: " + w);
}
}
--------------------------------
Is it possible to solve this problem.
Thank all,
J
On Nov 21, 11:11 pm, Artem Kozarezov <[email protected]> wrote:
> Sorry I've been wrong about the need to use the classloader.
> Here's our velocity code:http://gist.github.com/240182
>
> We used a customized template loading from the start, cause it gives more
> control over caching and such.
>
> On Sat, Nov 21, 2009 at 18:43, vincwe <[email protected]> wrote:
> > Thanks to Artem and Toby..
> > Just solved implementing
> > org.apache.velocity.runtime.resource.loader.ResourceLoader interfaces.
> > And for security in appengine-web-wml i've added
>
> > <resource-files>
> > <include path="/**.vm" />
> > </resource-files>
>
> > Ciao
> > Vincenzo
>
> > package com.vincenzoamoruso.velocity;
>
> > import java.io.File;
> > import java.io.FileInputStream;
> > import java.io.FileNotFoundException;
> > import java.io.InputStream;
>
> > import org.apache.commons.collections.ExtendedProperties;
> > import org.apache.velocity.exception.ResourceNotFoundException;
> > import org.apache.velocity.runtime.resource.Resource;
> > import org.apache.velocity.runtime.resource.loader.ResourceLoader;
>
> > public class velocityResourceLoader extends ResourceLoader {
> > �...@override
> > public long getLastModified(Resource arg0) {
> > return arg0.getLastModified();
> > }
>
> > �...@override
> > public InputStream getResourceStream(String arg0)
> > throws ResourceNotFoundException {
> > InputStream is=null;
> > try {
> > is = new FileInputStream(arg0);
> > } catch (FileNotFoundException e) {
> > throw new ResourceNotFoundException(arg0);
> > }
> > // TODO Auto-generated method stub
> > return is;
> > }
>
> > �...@override
> > public void init(ExtendedProperties arg0) {
> > // TODO Auto-generated method stub
>
> > }
>
> > �...@override
> > public boolean isSourceModified(Resource arg0) {
> > // TODO Auto-generated method stub
> > return false;
> > }
>
> > }
>
> > On 20 Nov, 12:21, ArtemGr <[email protected]> wrote:
> > > Google App Engine does not provide a usual file systemaccess.
> > > You should implement certain Velocity interfaces to load the files via
> > > classloader.
> > > I have it working.
>
> > > On 19 ноя, 22:26, vincwe <[email protected]> wrote:
>
> > > > Hi to all,
> > > > i'm try to use Apache velocity template for mailing,
> > > > using the following code
>
> > > > <code>
> > > > VelocityEngine ve = new VelocityEngine();
> > > > try {
> > > > ve.setProperty("resource.loader", "file");
> > > > ve.setProperty
>
> > ("file.resource.loader.class","org.apache.velocity.runtime.resource.loader.FileResourceLoader");
>
> > ve.setProperty("file.resource.loader.path","/template/email/");
> > > > ve.setProperty(
> > RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
> > > > "org.apache.velocity.runtime.log.Log4JLogChute" );
>
> > > > ve.setProperty("runtime.log.logsystem.log4j.logger",
> > > > log.getName());
> > > > // ve.setApplicationAttribute
> > > > ("javax.servlet.ServletContext",this.servlet.getServletContext());
> > > > ve.init();
> > > > } catch (Exception e1) {
> > > > // TODO Auto-generated catch block
> > > > log.warning("EI:"+e1.getMessage());
> > > > }
>
> > > > VelocityContext context = new VelocityContext();
> > > > Template template = null;
>
> > > > try
> > > > {
> > > > template = ve.getTemplate("mail1.vm");
>
> > > > }
> > > > .....
>
> > > > </code>
>
> > > > But at runtime gives this exception :
>
> > > > 11-19 10:44AM 33.316 [wincheck123/4.337839622240022599].<stderr>:
> > > > [error] ResourceManager.getResource() load exception
> > > > W 11-19 10:44AM 33.316 [wincheck123/4.337839622240022599].<stderr>:
> > > >accessdenied(java.io.FilePermission/template/email/mail1.vm read)
> > > > W 11-19 10:44AM 33.316 [wincheck123/4.337839622240022599].<stderr>:
> > > > java.security.AccessControlException:accessdenied
> > > > (java.io.FilePermission/template/email/mail1.vm
> > > > W 11-19 10:44AM 33.316 [wincheck123/4.337839622240022599].<stderr>: at
> > > > java.security.AccessControlContext.checkPermission
> > > > (AccessControlContext.java:355)
> > > > ..
>
> > > > Are there some security configuration to set for reading files on
> > > >appengine? such as security policy or others
>
> > > > Thank in advance
> > > > Regards
> > > > Vincenzo- Nascondi testo citato
>
> > > - Mostra testo citato -
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Google App Engine for Java" group.
> > To post to this group, send email to
> > [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<google-appengine-java%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-appengine-java?hl=.
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.