0

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

4
  • Not sure but try passing null Commented Mar 24, 2011 at 2:43
  • 1
    What API is it? Does it come with documentation? Read it. Commented Mar 24, 2011 at 2:44
  • 1
    You can absolutely use HttpServletRequests outside of servlets. The problem is, where does the request come from? It doesn't really make sense to create your own, since an HttpServletRequest represents an HTTP request. What's the API that you're working with that needs this parameter? You're probably just not using correctly. Commented Mar 24, 2011 at 2:45
  • Blackboard CMS? Sorry, never heard of. I however wonder what exactly you need it for and what you're actually trying to achieve with this API. Doesn't it get shipped/installed/deployed as a ready-to use web module or something? Commented Mar 24, 2011 at 2:59

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.