You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Christophe Gimenez <an...@yahoo.fr> on 2005/02/25 10:49:41 UTC

Problem integrating with Cactus

Hello, this is my first post on the list... 
 
I have a problem using Cactus test suites with my servlet (which is 
inherited from VelocityViewServlet) and I wonder if it could be due to the 
way I'm using Velocity API.
I've summarized some informations below.
 
1) Servlet get a reference to a context object from handleRequest 
method.
2) Servlet instanciate a "module" class, call my init(Context ctx) 
method which hold a reference of that Context : this.innerContext = 
(VelocityContext)ctx;
3) Context is used as usual (put() calls)
4) When work is done, the produce() method is called with writer = 
response.getWriter():
public void produce(java.io.Writer writer)
{
  Velocity.mergeTemplate(templateDir + 
this.innerTemplateFileName,"Cp1252",this.innerContext,writer);
}
 
5) Return to servlet code, which return NULL to the caller 
 
Problem is : when running under Cactus (as a Cactus test) the 
Velocity.mergeTemplate call throws a NullPointerException.
I step debugged, everything is ok (I've checked : writer object, 
innerContext object,filenames) 
 
Stepping into Velocity API I can go as far as this method 
(RuntimeInstance.java)
public Template getTemplate(String name, String  encoding) throws 
ResourceNotFoundException, ParseErrorException, Exception
{
    return (Template) resourceManager.getResource(name, 
ResourceManager.RESOURCE_TEMPLATE, encoding);
}
 
Stepping into getResource method is not possible...
 
So I have no idea of what is going wrong...
 
Any help appreciated, thank you


Note : I'm having problem to enable logging from velocity.properties (opposed to loadConfiguration) so I can't provide a log trace.

 

		
---------------------------------
 Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
Créez votre Yahoo! Mail

Re: Enabling logging

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Christophe,

> In my effort to find a solution to the problem I mentioned in another post I'm trying to setup minimal Velocity logging...
> 
> There must be something wrong with my setup (or with me :-)).

## snip

> 4) velocity.properties content is
> 
> runtime.log = velocity.log
> directive.foreach.counter.name = velociCount
> directive.foreach.counter.initial.value = 0
> resource.manager.logwhenfound = false
> file.resource.loader.cache = true
> file.resource.loader.modificationCheckInterval = 2
> velocimacro.library.autoreload = false
> velocimacro.permissions.allow.inline = true
> velocimacro.permissions.allow.inline.to.replace.global = true
> 
> 5) the velocity.log file is nowhere... Before I had it created under my Eclipse home directory (I'm running Tomcat from Eclipse with Sysdeo plugin).. No matter if I run Tomcat under Eclipse OR standalone the log is nowhere.
> 
> So, to clarify : with this setup, being under cactus or not, with Tomcat standalone or not I have no log at all...

The VVS outputs the log via the Servlet API by default.
   http://jakarta.apache.org/velocity/tools/view/
So you should see it in $CATALINA_HOME/logs/stdout.log for Tomcat.

To configure, take a look at the developer guide.
   http://jakarta.apache.org/velocity/developer-guide.html#Configuring%20the%20Log%20System

Best regards,
-- Shinobu

--
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Problem integrating with Cactus

Posted by Nathan Bubna <nb...@gmail.com>.
On Sat, 26 Feb 2005 10:34:21 +0100, anaema_ml@yahoo.fr
<an...@yahoo.fr> wrote:
> On 25 Feb 2005 at 10:33, Nathan Bubna wrote:
> 
> >
> > anyway, the VelocityViewServlet requires a good bit more than just the
> > handleRequest() method to run.  first it will need to be init'ed
> > (going thru init(), initToolbox(), initVelocity() and
> > loadConfiguration()), then it calls createContext() to get the
> > context, sets the content type, gets the Template from handleRequest()
> > and then it finally does the merge.  unless you are making sure it
> > goes through all (or most) of  those steps, i wouldn't expect it to
> > work.
> >
> 
> I've followed your advice and just added servlet.init(this.config); in my
> setupServletAndRun method and voila... Everything is right !

glad to hear it!  yeah, from a first glance at the stack trace you
gave, it looks like velocity was probably not getting init'ed properly
before.

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Problem integrating with Cactus

Posted by an...@yahoo.fr.
On 25 Feb 2005 at 10:33, Nathan Bubna wrote:

> 
> anyway, the VelocityViewServlet requires a good bit more than just the
> handleRequest() method to run.  first it will need to be init'ed
> (going thru init(), initToolbox(), initVelocity() and
> loadConfiguration()), then it calls createContext() to get the
> context, sets the content type, gets the Template from handleRequest()
> and then it finally does the merge.  unless you are making sure it
> goes through all (or most) of  those steps, i wouldn't expect it to
> work.
> 

I've followed your advice and just added servlet.init(this.config); in my 
setupServletAndRun method and voila... Everything is right !

Thanks 


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Problem integrating with Cactus

Posted by Nathan Bubna <nb...@gmail.com>.
i don't really know anything about Cactus, but this code snippet
hardly seems representative of a sensible way to test a servlet. 
surely they must have a better setup than this?  or am i just getting
the wrong impression because you've posted so little code?

anyway, the VelocityViewServlet requires a good bit more than just the
handleRequest() method to run.  first it will need to be init'ed
(going thru init(), initToolbox(), initVelocity() and
loadConfiguration()), then it calls createContext() to get the
context, sets the content type, gets the Template from handleRequest()
and then it finally does the merge.  unless you are making sure it
goes through all (or most) of  those steps, i wouldn't expect it to
work.

i'm also fairly confused by all that was in your first post (probably
at least in part due to ignorance of Cactus).  but it seems to me that
a NPE could be caused by any number of things.  without a stack trace
or a better idea of what your code is doing, i'm not sure we'll be
able to help you much.

if you can't get logging to work yet, have you tried just catching the
exception and printing the stack trace to sysout? (sometimes the old
hacks are still the best in a pinch :)

On Fri, 25 Feb 2005 18:02:36 +0100 (CET), Christophe Gimenez
<an...@yahoo.fr> wrote:
> Hello
> 
> I'm using the latest stable releases of Velocity and Velocitools.
> To avoid being to verbose on cutting & pasting tons of source code here, this is just the way the servlet is invoked under cactus :
> 
> public void setupServletAndRun() throws Exception
>     {
>         AnaemServlet servlet = new AnaemServlet();
>         VelocityContext context=new VelocityContext();
>         Template result=servlet.handleRequest(request, response, context);
>     }
> 
> The only difference with "normal" servlet invocation is the loadConfiguration() that is not beeing called... I presume it does not matter ?
> 
> If it's the class loader, what should I try to do ?
> 
> Thanks
> 
> PS : Sorry for html posting I must setup my yahoo acount as a pop/smtp ... asap !
> 
> 
> Shinobu Kawai <sh...@gmail.com> wrote:
> Hi Christophe,
> 
> > Hello, this is my first post on the list...
> 
> Welcome to the gang! :)
> 
> > I have a problem using Cactus test suites with my servlet (which is
> > inherited from VelocityViewServlet) and I wonder if it could be due to the
> > way I'm using Velocity API.
> > I've summarized some informations below.
> 
> Not being so familiar with Cactus, some minimal sample code to
> reproduce your problem would be nice.
> ## Gotta look into Cactus some day, though.
> 
> Also, which version of Velocity/VelocityTools are you using?
> 
> > Problem is : when running under Cactus (as a Cactus test) the
> > Velocity.mergeTemplate call throws a NullPointerException.
> > I step debugged, everything is ok (I've checked : writer object,
> > innerContext object,filenames)
> >
> > Stepping into Velocity API I can go as far as this method
> > (RuntimeInstance.java)
> > public Template getTemplate(String name, String encoding) throws
> > ResourceNotFoundException, ParseErrorException, Exception
> > {
> > return (Template) resourceManager.getResource(name,
> > ResourceManager.RESOURCE_TEMPLATE, encoding);
> > }
> >
> > Stepping into getResource method is not possible...
> 
> Might be a ClassLoader issue...
> 
> Best regards,
> -- Shinobu
> 
> --
> Shinobu Kawai
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> ---------------------------------
>  Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
> Créez votre Yahoo! Mail
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Enabling logging

Posted by Christophe Gimenez <an...@yahoo.fr>.
In my effort to find a solution to the problem I mentioned in another post I'm trying to setup minimal Velocity logging...

There must be something wrong with my setup (or with me :-)).

1) loadConfiguration is called (see above for source code) but NOT under cactus (it's normal I should find a way to do it manually), so I need to rely on velocity.properties to enable simple logging
No matter if under Cactus or not, the log file is not created

2) velocity.properties file is located under my WEB-INF directory

3) this entry is in my web.xml file

 <context-param>
  <param-name>org.apache.velocity.properties</param-name>
  <param-value>/WEB-INF/velocity.properties</param-value>
 </context-param>
 

4) velocity.properties content is 

runtime.log = velocity.log
directive.foreach.counter.name = velociCount
directive.foreach.counter.initial.value = 0
resource.manager.logwhenfound = false
file.resource.loader.cache = true
file.resource.loader.modificationCheckInterval = 2
velocimacro.library.autoreload = false
velocimacro.permissions.allow.inline = true
velocimacro.permissions.allow.inline.to.replace.global = true

5) the velocity.log file is nowhere... Before I had it created under my Eclipse home directory (I'm running Tomcat from Eclipse with Sysdeo plugin).. No matter if I run Tomcat under Eclipse OR standalone the log is nowhere.

So, to clarify : with this setup, being under cactus or not, with Tomcat standalone or not I have no log at all...

Any help greatly appreciated ! 

Thank you in advance

 

protected ExtendedProperties loadConfiguration(ServletConfig config ) throws IOException, FileNotFoundException
    {
        ExtendedProperties  p = new ExtendedProperties ();
        
        // Obtiens la valeur de la propriété org.apache.velocity.properties
        // et charge le fichier .properties correspondant
        String propsFile = config.getInitParameter(INIT_PROPS_KEY);
        if(propsFile != null) 
        {
            java.io.InputStream iStream = getServletContext().getResourceAsStream(propsFile);

            if (iStream != null) 
              p.load( iStream );
            else
                System.out.println("prop file !!");
        }
        
        /*
         * Altération d'autre paramètres au runtime
         */

        String path = config.getServletContext().getRealPath("/");
        if (path == null)
        {
            System.out.println(" AnaemServlet.loadConfiguration() : unable to get the current webapp root.  Using '/'. Please fix !"); 
            path = "/";
        }
        p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,  path);
        System.out.println("Velocity.FILE_RESOURCE_LOADER_PATH = " + path);
        p.setProperty("runtime.log", path + "velocity.log");

        return p;
    }

 

		
---------------------------------
 Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
Créez votre Yahoo! Mail

Re: Problem integrating with Cactus

Posted by Christophe Gimenez <an...@yahoo.fr>.
Hello
 
I'm using the latest stable releases of Velocity and Velocitools.
To avoid being to verbose on cutting & pasting tons of source code here, this is just the way the servlet is invoked under cactus :
 
public void setupServletAndRun() throws Exception
    {
        AnaemServlet servlet = new AnaemServlet();
        VelocityContext context=new VelocityContext();
        Template result=servlet.handleRequest(request, response, context);       
    }
 
The only difference with "normal" servlet invocation is the loadConfiguration() that is not beeing called... I presume it does not matter ?
 
If it's the class loader, what should I try to do ?
 
Thanks
 
PS : Sorry for html posting I must setup my yahoo acount as a pop/smtp ... asap !
 
 
Shinobu Kawai <sh...@gmail.com> wrote:
Hi Christophe,

> Hello, this is my first post on the list...

Welcome to the gang! :)

> I have a problem using Cactus test suites with my servlet (which is
> inherited from VelocityViewServlet) and I wonder if it could be due to the
> way I'm using Velocity API.
> I've summarized some informations below.

Not being so familiar with Cactus, some minimal sample code to
reproduce your problem would be nice.
## Gotta look into Cactus some day, though.

Also, which version of Velocity/VelocityTools are you using?

> Problem is : when running under Cactus (as a Cactus test) the
> Velocity.mergeTemplate call throws a NullPointerException.
> I step debugged, everything is ok (I've checked : writer object,
> innerContext object,filenames)
> 
> Stepping into Velocity API I can go as far as this method
> (RuntimeInstance.java)
> public Template getTemplate(String name, String encoding) throws
> ResourceNotFoundException, ParseErrorException, Exception
> {
> return (Template) resourceManager.getResource(name,
> ResourceManager.RESOURCE_TEMPLATE, encoding);
> }
> 
> Stepping into getResource method is not possible...

Might be a ClassLoader issue...

Best regards,
-- Shinobu

--
Shinobu Kawai 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


		
---------------------------------
 Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
Créez votre Yahoo! Mail

Re: Problem integrating with Cactus

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Christophe,

> Hello, this is my first post on the list...

Welcome to the gang!  :)

> I have a problem using Cactus test suites with my servlet (which is
> inherited from VelocityViewServlet) and I wonder if it could be due to the
> way I'm using Velocity API.
> I've summarized some informations below.

Not being so familiar with Cactus, some minimal sample code to
reproduce your problem would be nice.
## Gotta look into Cactus some day, though.

Also, which version of Velocity/VelocityTools are you using?

> Problem is : when running under Cactus (as a Cactus test) the
> Velocity.mergeTemplate call throws a NullPointerException.
> I step debugged, everything is ok (I've checked : writer object,
> innerContext object,filenames)
> 
> Stepping into Velocity API I can go as far as this method
> (RuntimeInstance.java)
> public Template getTemplate(String name, String  encoding) throws
> ResourceNotFoundException, ParseErrorException, Exception
> {
>    return (Template) resourceManager.getResource(name,
> ResourceManager.RESOURCE_TEMPLATE, encoding);
> }
> 
> Stepping into getResource method is not possible...

Might be a ClassLoader issue...

Best regards,
-- Shinobu

--
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org