Java Code Examples for org.springframework.mock.web.MockHttpServletRequest#setRemoteHost()

The following examples show how to use org.springframework.mock.web.MockHttpServletRequest#setRemoteHost() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpMockServiceImpl.java    From AnyMock with Apache License 2.0 6 votes vote down vote up
private MockHttpServletRequest buildMockRequest(HttpServletRequest request) {
    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameters(request.getParameterMap());

    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String key = (String)headerNames.nextElement();
        mockRequest.addHeader(key, request.getHeader(key));
    }

    mockRequest.setMethod(request.getMethod());
    mockRequest.setRequestURI(request.getRequestURI());
    mockRequest.setRemoteAddr(request.getRemoteAddr());
    mockRequest.setRemoteHost(request.getRemoteHost());
    mockRequest.setRemotePort(request.getRemotePort());
    mockRequest.setRemoteUser(request.getRemoteUser());
    mockRequest.setAttribute(BODY, request.getAttribute(BODY));
    return mockRequest;
}
 
Example 2
Source File: ServletFilterRequestTest.java    From vespa with Apache License 2.0 5 votes vote down vote up
private ServletRequest newServletRequest() throws Exception {
    MockHttpServletRequest parent = new MockHttpServletRequest("GET", uri.toString());
    parent.setProtocol(Version.HTTP_1_1.toString());
    parent.setRemoteHost(host);
    parent.setRemotePort(port);
    parent.setParameter(paramName, paramValue);
    parent.setParameter(listParamName, listParamValue);
    parent.addHeader(headerName, headerValue);
    parent.setAttribute(attributeName, attributeValue);
    HttpConnection connection = Mockito.mock(HttpConnection.class);
    when(connection.getCreatedTimeStamp()).thenReturn(System.currentTimeMillis());
    parent.setAttribute("org.eclipse.jetty.server.HttpConnection", connection);
    return new ServletRequest(parent, uri);
}