You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Manish <pr...@gmx.net> on 2009/04/30 14:45:48 UTC
A strange problem of ResourceNotFound
We are facing this strage problem in our code that uses standalone velocity
engine. So far it did send the emails correctly from this standalone program
running (this particular code doesn't reside under struts application) on our
server.
This is the part of teh code we use -
String result = null;
Reader r = null;
StringWriter writer = null;
try {
writer = new StringWriter();
r = new BufferedReader(new FileReader(new File(RESOURCE_PATH,
MAIL_TEMPLATE_FILE)));
boolean status = ve.evaluate(context, writer, "someEmail", r);
if (!status) throw new RuntimeException("Error in evaluation: ");
writer.close();
result = writer.toString();
} catch (ResourceNotFoundException e) {
throw new RuntimeException(e);
} catch (ParseErrorException e) {
throw new RuntimeException(e);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (r!= null) try {r.close();} catch (IOException ioe) {};
if (writer != null) try {writer.close();} catch (IOException ioe) {};
}
return result;
Now this resource path is not changed in last 3 yeas and it's working fine and
sending mails proeprly. Now the mail template (say someMail.vm) refers to 2 VTL
files within itself to parse header and footer for this mail (say header.vm and
footer.vm).
So I have these two new lines added to the the VTL template - "someMail.vm" -
#parse("header.vm")
.......
.......
.......
#parse("footer.vm")
bother these header and footer reside in the same directory to which this
"RESOURCE_PATH" points, the engine is able to parse the mail template correctly,
but it is not able to parse gheader and footer and it fails with
"ResourceNotFoundException ". I am wondering why and how can I fix this???? One
obvious way is to add it to the mail template itself but I don't want to do that
because header & footer will be referred by other pages on site as well.
Why this ResourceNotFoundException exception is thrown though both files reside
in the same RESOURCE_PATH directory? How can I fix this?
TIA,
- Manish
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: A strange problem of ResourceNotFound
Posted by Manish <pr...@gmx.net>.
The engine initialization code is simply this much (pretty old,
actually) -VelocityEngine ve = new VelocityEngine(); try { ve.init(); }
catch (Exception e) { throw new RuntimeException(e); }Is there something I
can do here?- Manish> Since you are just passing a Reader directly to the
evaluate() method,> your VelocityEngine knows absolutely nothing about the path
from which> it came. So, how are you configuring the VelocityEngine instance
you> are using here (ve)? I don't see that code here.>>On Thu, Apr 30, 2009 at
5:45 AM, Manish <pr...@gmx.net> wrote:>> We are facing this strage problem in
our code that uses standalone velocity>> engine. So far it did send the emails
correctly from this standalone program>> running (this particular code doesn't
reside under struts application) on>> our server.>>>> This is the part of teh
code we use ->>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: A strange problem of ResourceNotFound
Posted by Nathan Bubna <nb...@gmail.com>.
Since you are just passing a Reader directly to the evaluate() method,
your VelocityEngine knows absolutely nothing about the path from which
it came. So, how are you configuring the VelocityEngine instance you
are using here (ve)? I don't see that code here.
On Thu, Apr 30, 2009 at 5:45 AM, Manish <pr...@gmx.net> wrote:
> We are facing this strage problem in our code that uses standalone velocity
> engine. So far it did send the emails correctly from this standalone program
> running (this particular code doesn't reside under struts application) on
> our server.
>
> This is the part of teh code we use -
>
>
> String result = null;
> Reader r = null;
> StringWriter writer = null;
> try {
> writer = new StringWriter();
> r = new BufferedReader(new FileReader(new File(RESOURCE_PATH,
> MAIL_TEMPLATE_FILE)));
> boolean status = ve.evaluate(context, writer, "someEmail", r);
> if (!status) throw new RuntimeException("Error in evaluation: ");
>
> writer.close();
> result = writer.toString();
>
>
> } catch (ResourceNotFoundException e) {
> throw new RuntimeException(e);
> } catch (ParseErrorException e) {
> throw new RuntimeException(e);
> } catch (Exception e) {
> throw new RuntimeException(e);
> } finally {
> if (r!= null) try {r.close();} catch (IOException ioe) {};
> if (writer != null) try {writer.close();} catch (IOException ioe) {};
> }
> return result;
>
>
> Now this resource path is not changed in last 3 yeas and it's working fine
> and sending mails proeprly. Now the mail template (say someMail.vm) refers
> to 2 VTL files within itself to parse header and footer for this mail (say
> header.vm and footer.vm).
>
> So I have these two new lines added to the the VTL template - "someMail.vm"
> -
>
> #parse("header.vm")
> .......
> .......
> .......
> #parse("footer.vm")
>
> bother these header and footer reside in the same directory to which this
> "RESOURCE_PATH" points, the engine is able to parse the mail template
> correctly, but it is not able to parse gheader and footer and it fails with
> "ResourceNotFoundException ". I am wondering why and how can I fix this????
> One obvious way is to add it to the mail template itself but I don't want to
> do that because header & footer will be referred by other pages on site as
> well.
>
> Why this ResourceNotFoundException exception is thrown though both files
> reside in the same RESOURCE_PATH directory? How can I fix this?
>
> TIA,
> - Manish
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org