Dec 6th, 2012, 07:46 AM
forwading requestDispatcher sing MockHttpServletRequest and MockHttpAServletResponse
We're making us of the MockHttpServletRequest and MockHttpAServletResponse, BUT not in executing test cases (yes it's strange). Our web application is to be integrated with a message based service invocation layer and therefore we're not going to have hold to request/response objects.
As any web app, we have filters, listeners etc... So what we're trying to do is creating new MockHttpServletRequest and MockHttpAServletResponse objects, populating with the necessary headers, parameters etc... and doing a forward to a url (/foo/bar which relative to our root) which is mapped to our controller. The forward is done using the RequestDispatcher (have tried getting it from the MockHttpAServletRequest as well as from the container provided ServletContext), however nothing happens. The forward logic in inside a TimerTask which gets invoked every x minutes.
What i'm expecting (from the forward) is the application to be hit as any normal HTTP request and execute the filters, controllers etc...
Has anyone tried something similar to this.
Dec 6th, 2012, 08:31 AM
Not sure what you are trying to do but for some reason it doesn't feel right... You shouldn't use test classes in production systems. If you want to do a httprequest then use an UrlConnection or something like the httpclient library from apache but messing around with test classes in production code isn't something you should do.
Also if you are using message based systems I think Spring Integration (with a http inbound gateway of sorts) and not a web application. That also feels weird (but that is from my location ).
Dec 6th, 2012, 10:41 AM
Thanks for your reply Marten. I'll try to cut across your point regarding the usage of test classes for production. But do you have any idea why the requestdispacther forward on the mock request/response might not work?
Dec 6th, 2012, 10:49 AM
Because, as the classname suggest, it is a mock. It has absolutly no ties to any real functionality... So it will never work.
Tags for this Thread