File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes can't debug servlet/bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "can Watch "can New topic
Author

can't debug servlet/bean

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4655
    
    5

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Aug 11, 2007
Posts: 4655
    
    5

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

Joined: Aug 11, 2007
Posts: 4655
    
    5

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

Joined: Sep 29, 2008
Posts: 12617

The mysteries of IDEs is how I usually end a lot of my debugging sessions ;)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can't debug servlet/bean