Re: Problem integrating with Cactus

2005-02-26 Thread anaema_ml
On 25 Feb 2005 at 10:33, Nathan Bubna wrote: 

 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? 
  

It depends on the test you want to do. In my case, before doing any real test 
I'm trying  
to get it running at all. But a simple test case is not much longer (see  
http://jakarta.apache.org/cactus/integration/howto_tomcat.html) 
For now the code I'm using is : 

public class CactusTestsServlet extends ServletTestCase 
{ 
public CactusTestsServlet(String theName) 
{ 
super(theName); 
} 

public static Test suite() 
{ 
return new TestSuite(CactusTestsServlet.class); 
} 

public void setupCommonParameters(WebRequest webRequest) 
{ 
webRequest.addParameter(module,blog); 
} 
 
public void setupServletAndRun() throws Exception 
{ 
AnaemServlet servlet = new AnaemServlet(); 
VelocityContext context=new VelocityContext(); 
Template result=servlet.handleRequest(request, response, context);  
  
} 
 
public void beginPostAddMessage(WebRequest webRequest) 
{ 
setupCommonParameters(webRequest); 
} 

public void testPostAddMessage() throws Exception 
{ 
setupServletAndRun(); 
} 
 
public void endPostAddMessage(WebResponse webResponse) throws Exception 
{ 
System.out.println(webResponse.getText()); 
} 
} 

 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. 
  

It did. 2 or 3 times I did get my template generated under cactus. But most of 
the time  
it didn't work. Of course I can't rely on the fact that it did work 2 or 3 
times... I should  
try to mimic a VelocityViewServlet initialisation sequence, from API source 
code... 
But, without logging it's difficult to go further...  

 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. 
  

Sure, here is the trace.  




java.lang.NullPointerException 
at 
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:831)
 
at 
org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.java:30
3) 
at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:439) 
at app.WebApp.produce(WebApp.java:165) 
at app.WebApp.execute(WebApp.java:286) 
at AnaemServlet.handleRequest(AnaemServlet.java:115) 
at CactusTestsServlet.setupServletAndRun(CactusTestsServlet.java:34) 
at CactusTestsServlet.testPostAddMessage(CactusTestsServlet.java:49) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at 
org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTe
stCase.java:153) 
at 
org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCa
ller.java:119) 
at 
org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_around
Body0(AbstractWebTestController.java:93) 
at 
org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_around
Body1$advice(AbstractWebTestController.java:224) 
at 
org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(Abstract
WebTestController.java) 
at 
org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRed
irector.java:101) 
at 
org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(Servlet
TestRedirector.java:224) 
at 
org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
 
at 
org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedi
rector.java:72) 
at 
org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletT
estRedirector.java:224) 
at 
org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) 
at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.
java:237) 
at 

Re: Problem integrating with Cactus

2005-02-26 Thread anaema_ml
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Problem integrating with Cactus

2005-02-26 Thread Nathan Bubna
On Sat, 26 Feb 2005 10:34:21 +0100, [EMAIL PROTECTED]
[EMAIL PROTECTED] 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Problem integrating with Cactus

2005-02-25 Thread Shinobu Kawai
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 [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Problem integrating with Cactus

2005-02-25 Thread Christophe Gimenez
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 [EMAIL PROTECTED] 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
 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

2005-02-25 Thread Nathan Bubna
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
[EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 -
  Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos 
 mails !
 Créez votre Yahoo! Mail


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]