Пример #1
0
 private MockHttpServletRequest buildMock(String completeUrl, String contextPath) {
   try {
     URI uri = new URI(completeUrl);
     MockServletContext context = new MockServletContext();
     context.setContextPath(contextPath);
     MockHttpServletRequest httpRequest =
         new MockHttpServletRequest(context, "get", uri.getPath());
     httpRequest.setLocalName(uri.getHost());
     httpRequest.setServerName(uri.getHost());
     httpRequest.setServletPath(
         completeUrl.substring(completeUrl.indexOf(contextPath) + contextPath.length()));
     httpRequest.setContextPath(contextPath);
     httpRequest.setServerPort(uri.getPort());
     return httpRequest;
   } catch (URISyntaxException e) {
     return null;
   }
 }