Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can't debug servlet/bean

 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a "simple" JUnit test for a Bean that can't be debugged. When I run it, it blows up with a trapped exception. So in the rest of the code I write, the normal thing is to fire up the debugger, step into the code and see what I'm doing wrong. With this one class, when I try to "debug" it using Netbeans 6.7, it blows up before I can get to the first line of the JUnit test.

The stackdump looks like:



I have no idea how to proceed.

I called it "simple" in quotes because since its a Bean that expects to be in a Container, it needs Mock implementations of the ServletRequest, CommandContext, HttpServletRequest, HttpServletResponse, etc.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without knowing more it's going to be hard to help; what kind of setup are you doing? What (if any) library|ies are you using to create the requests/etc? Is ServletException on your test's classpath?
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Without knowing more it's going to be hard to help; what kind of setup are you doing? What (if any) library|ies are you using to create the requests/etc?


Not sure how to answer "what kind of setup"

For example, I create a CommandContextMock() by declaring the class

public class CommandContextMock implements CommandContext {
}

and when the compiler complains, I let Netbeans autogenrate all the required functions. I implemented the ones that were actually needed to return suitable values:

public HttpServletRequest getRequest() {
return new HttpServletRequestMock();
}

etc.

David Newton wrote:Is ServletException on your test's classpath?

Not sure. Both the JDK 1.6 and Glassfish libraries are in the project's classpath. The code executes (incorrectly) without the debugger.

Netbeans reports that "classpath for compiling sources" and "compiled source" as well as JUnit are included.
I would expect that Glassfish includes the proper servlet definitions, but I'm not sure.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was it. I added j2ee.jar to the testing class path and now I can debug it.

Not sure why it was working before, but this fixed it.

Thanks much.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The mysteries of IDEs is how I usually end a lot of my debugging sessions ;)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic