user568171
user568171

Reputation:

Using HttpServletRequest Outside of a Servlet

I'm working this API and there is a factory method that sets the current context (request, user, etc). The context needs a HttpServletRequest parameter, but I'm not for sure how to initialize it. I would like this setContext(HttpServletRequest) method to be in the default constructor of the class, how do I go about initializing it so that I can use it with setContext? Is the only way to work with HttpServletRequest objects in a servlet, so I can't use the a java class?

Here's the library I'm using: http://library.blackboard.com/ref/6760ba98-8f24-44f2-8e65-0dcee799abb8/index.html

Upvotes: 0

Views: 3112

Answers (2)

aldrinleal
aldrinleal

Reputation: 3609

You can either do it using mocks, or better yet: Use HttpUnit ServletUnit

However, keep in mind that this library probably needs to run inside a container: Review your options and, when sure of all the operations "the library" will invoke on the container, simply mock it up.

Upvotes: 0

Jeremy
Jeremy

Reputation: 607

I'm not sure why you'd want to use it outside of a Servlet context other than testing. For automated tests you can create a mock implementation that includes the features required to get the required functionality to work. Just make sure that the mock implementation behaves the same way as when it's running inside a servlet container.

Upvotes: 1

Related Questions