Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 800573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:18:34+00:00 2026-05-14T23:18:34+00:00

How do I mimic an HTTPServletRequest and HTTPServletResponse object. The reason is I want

  • 0

How do I mimic an HTTPServletRequest and HTTPServletResponse object. The reason is I want to test the behaviour of some servlets.

I know JUnit probably provides this functionality but I don’t know how to use it (I will learn soon) and need to do this reasonably quickly.

HTTPServletRequest and HTTPServletResponse are both interfaces so they can’t be instantiated. There is a HttpServletRequestWrapper which implements HttpServletRequest but it doesn’t seem to have any setParameter() type methods and HttpServletResponse doesn’t seem to have any implementing classes at all.

How can I test my code by passing a suitable HttpServletRequest object and then checking that the received HttpServletResponse object matches what I expect?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:18:35+00:00Added an answer on May 14, 2026 at 11:18 pm

    The fact that it’s an interface makes it easier to mimic: It’s mocking final classes that’s tricky.

    class MyHttpServletRequest implements HttpServletRequest
    {
      //whatever
    }
    
    class MyHttpServletResponse implements HttpServletResponse
    {
      //whatever
    }
    
    
    doGet(new MyHttpServletRequest(),
          new MyHttpServletResponse())
    

    Subclassing HttpServletRequestWrapper may be easier, but it’s not necessary. I would look at overriding getParameter and getParameterMap

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 539k
  • Answers 539k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are a few ways. Set one image as a… May 17, 2026 at 2:23 am
  • Editorial Team
    Editorial Team added an answer That's pretty easy - just use the Sum extension method… May 17, 2026 at 2:23 am
  • Editorial Team
    Editorial Team added an answer The chunked transfer encoding is a sequence of chunks where… May 17, 2026 at 2:23 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I want to mimic a Python functionality in Java. In Python if I want
I want to mimic a piece of C code in Python with ctypes, the
I am trying to write some kind of raw html to mimic what spring
I'm trying to mimic the following Java code: int[][] multi; // DIMENSIONS ARE UNKNOWN
I'm trying to mimic static variables on a JavaScript function, with the following purpose:
I am trying to mimic the following PHP code in C# <?php if (
I'm looking to mimic the behavior of the activitypointer entity with custom entities. For
I would like to mimic the RepeatColumn function of the ASP.NET DataList control in
I try to mimic a network request send by a closed source application. The
I'm trying to mimic what every other tabular view does with the DataGridView control,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.