سؤال

I am trying to test a servlet which sets attributes on ServletRequest. I am using jbehave with restTemplate and apache httpClient to send request to that servlet. Is it possible to verify what attributes were set on servletRequest?

here is what I am basically trying to do in servlet:

public void doGet(HttpServletRequest request, HttpServletResponse response) throws OException, ServletException{ 
request.setAttribute("attributeName","SIMPLE_NAME"); 
...
} 

and client:

HttpEntity entity = HttpEntity.EMPTY;
 Map<String, String> map = new HashMap<String, String>();
 restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
 HttpEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, entity, String.class, map);

so in that case I would like to verify that attributeName was set with value SIMPLE_NAME

هل كانت مفيدة؟

المحلول

No, this is not possible. HttpServletRequest attributes are a server side implementation detail that has nothing to do with the HTTP protocol. As such, an HTTP client has no knowledge of this (and shouldn't).

If you want to check that the attribute was added from the server side, you can implement and register a ServletRequestAttributeListener in your web application.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top