public void request(WebRequest webRequest) { try { invocationContext = client.newInvocation(webRequest); rawRequest = new MyHttpRequest(invocationContext.getRequest(), webRequest.getURL().toExternalForm()); rawResponse = new MyHttpResponse(invocationContext.getResponse()); servletContext = invocationContext.getServlet().getServletConfig().getServletContext(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } if (requestContexts != null) { requestContext = requestContexts.getRequestContext(servletContext, rawRequest, rawResponse); } }
public void request(WebRequest webRequest) { try { invocationContext = client.newInvocation(webRequest); rawRequest = new MyHttpRequest(invocationContext.getRequest(), webRequest.getURL().toExternalForm()); rawResponse = new MyHttpResponse(invocationContext.getResponse()); servletContext = invocationContext.getServlet().getServletConfig().getServletContext(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } if (requestContexts != null) { requestContext = requestContexts.getRequestContext(servletContext, rawRequest, rawResponse); } }
@Deprecated private InvocationContext invokeWebRequest(String uri, String... parameters) { // This is not testing servlet, so any HTTP method suffices WebRequest request = new PostMethodWebRequest(SIMULATION_BASE_URL + uri); // TODO remove this portion once front-end migration is finished // Reason: CSRF protection is not part of action tests if (Const.SystemParams.PAGES_REQUIRING_ORIGIN_VALIDATION.contains(uri)) { request.setHeaderField("referer", SIMULATION_BASE_URL); String sessionId = sc.getSession(true).getId(); String token = StringHelper.encrypt(sessionId); request.setParameter(Const.ParamsNames.SESSION_TOKEN, token); } Map<String, List<String>> paramMultiMap = new HashMap<>(); for (int i = 0; i < parameters.length; i = i + 2) { paramMultiMap.computeIfAbsent(parameters[i], k -> new ArrayList<>()).add(parameters[i + 1]); } paramMultiMap.forEach((key, values) -> request.setParameter(key, values.toArray(new String[0]))); try { return sc.newInvocation(request); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Creates and returns a new invocation context to test calling of servlet methods. **/ public InvocationContext newInvocation( WebRequest request ) throws IOException, MalformedURLException { return newInvocation( request, FrameSelector.TOP_FRAME ); }
/** * Creates and returns a new invocation context to test calling of servlet methods. **/ public InvocationContext newInvocation( WebRequest request ) throws IOException, MalformedURLException { return newInvocation( request, FrameSelector.TOP_FRAME ); }
/** * Creates and returns a new invocation context to test calling of servlet methods. **/ public InvocationContext newInvocation( WebRequest request ) throws IOException, MalformedURLException { return newInvocation( request, FrameSelector.TOP_FRAME ); }
/** * Creates and returns a new invocation context from a GET request. **/ public InvocationContext newInvocation( String requestString ) throws IOException, MalformedURLException { return newInvocation( new GetMethodWebRequest( requestString ) ); }
/** * Creates and returns a new invocation context from a GET request. **/ public InvocationContext newInvocation( String requestString ) throws IOException, MalformedURLException { return newInvocation( new GetMethodWebRequest( requestString ) ); }
/** * Creates and returns a new invocation context from a GET request. **/ public InvocationContext newInvocation( String requestString ) throws IOException, MalformedURLException { return newInvocation( new GetMethodWebRequest( requestString ) ); }
/** * Creates a web response object which represents the response to the specified web request. **/ protected WebResponse newResponse( WebRequest request, FrameSelector targetFrame ) throws MalformedURLException,IOException { try { InvocationContext invocation = newInvocation( request, targetFrame ); invocation.service(); return invocation.getServletResponse(); } catch (ServletException e) { throw new HttpInternalErrorException( request.getURL(), e ); } }
/** * Creates a web response object which represents the response to the specified web request. **/ protected WebResponse newResponse( WebRequest request, FrameSelector targetFrame ) throws MalformedURLException,IOException { try { InvocationContext invocation = newInvocation( request, targetFrame ); invocation.service(); return invocation.getServletResponse(); } catch (ServletException e) { throw new HttpInternalErrorException( request.getURL(), e ); } }
/** * Creates a web response object which represents the response to the specified web request. **/ protected WebResponse newResponse( WebRequest request, FrameSelector targetFrame ) throws MalformedURLException,IOException { try { InvocationContext invocation = newInvocation( request, targetFrame ); invocation.service(); return invocation.getServletResponse(); } catch (ServletException e) { throw new HttpInternalErrorException( request.getURL(), e ); } }