문제

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