@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); } }
protected MessageBody getMessageBody() { if (_body == null) { _body = MessageBody.createPostMethodMessageBody( isMimeEncoded(), getCharacterSet() ); } return _body; }
/** * Returns true if selectFile may be called with this parameter. */ protected boolean maySelectFile( String parameterName ) { return isMimeEncoded() && isFileParameter( parameterName ); }
/** * Returns the query string defined for this request. **/ public String getQueryString() { try { URLEncodedString encoder = new URLEncodedString(); getParameterHolder().recordPredefinedParameters( encoder ); return encoder.getString(); } catch (IOException e) { throw new RuntimeException( "Programming error: " + e ); // should never happen } }
/** * Returns the query string defined for this request. **/ public String getQueryString() { try { URLEncodedString encoder = new URLEncodedString(); getParameterHolder().recordPredefinedParameters( encoder ); return encoder.getString(); } catch (IOException e) { throw new RuntimeException( "Programming error: " + e ); // should never happen } }
InputStream body = new FileInputStream("create.xml"); WebRequest request = new PostMethodWebRequest("http://example.com/thing/create", body, "text/xml");
protected MessageBody getMessageBody() { if (_body == null) { _body = MessageBody.createPostMethodMessageBody( isMimeEncoded(), getCharacterSet() ); } return _body; }
/** * Returns true if selectFile may be called with this parameter. */ protected boolean maySelectFile( String parameterName ) { return isMimeEncoded() && isFileParameter( parameterName ); }
protected String createJob(WebConversation conversation, String xml) throws IOException, SAXException, JDOMException { log.debug("**************************************************"); log.debug("HTTP POST: " + serviceUrl); // Create a new Job. ByteArrayInputStream in = new ByteArrayInputStream(xml.getBytes()); WebRequest postRequest = new PostMethodWebRequest(serviceUrl, in, "text/xml"); log.debug("Posted xml: " + xml); return createJob(conversation, postRequest); }
protected String createJob(WebConversation conversation) throws IOException, SAXException, JDOMException { log.debug("**************************************************"); log.debug("HTTP POST: " + serviceUrl); // Create a new Job with default values. WebRequest postRequest = new PostMethodWebRequest(serviceUrl); return createJob(conversation, postRequest); }
protected String createJob(WebConversation conversation, String contentType, String content) throws IOException, SAXException, JDOMException { log.debug("**************************************************"); log.debug("HTTP POST: " + serviceUrl); // Create a new Job. ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes()); WebRequest postRequest = new PostMethodWebRequest(serviceUrl, in, contentType); log.debug("Posted content: " + content); return createJob(conversation, postRequest); }
protected WebResponse deleteJobWithPostRequest(WebConversation conversation, String jobId) throws IOException, SAXException, JDOMException { String resourceUrl = serviceUrl + "/" + jobId; log.debug("**************************************************"); log.debug("HTTP POST: " + resourceUrl); WebRequest postRequest = new PostMethodWebRequest(resourceUrl); postRequest.setParameter("ACTION", "DELETE"); return deleteJob(conversation, postRequest, resourceUrl); }
protected WebRequest buildRequest(final TestProperties properties) throws UnsupportedEncodingException, MalformedURLException { // Build the request. WebRequest request = new PostMethodWebRequest(serviceUrl); // Add parameters if available. if (properties.parameters != null) { Map<String, List<String>> parameters = properties.parameters; List<String> valueList; List<String> keyList = new ArrayList<String>(parameters.keySet()); for (String key : keyList) { valueList = parameters.get(key); request.setParameter(key, valueList.toArray(new String[0])); } } log.debug("HTTP POST: " + request.getURL().toString()); log.debug(Util.getRequestParameters(request)); return request; } }
protected String createJob(WebConversation conversation, Map<String, List<String>> parameters) throws IOException, SAXException, JDOMException { log.debug("**************************************************"); log.debug("HTTP POST: " + serviceUrl); // Create a new Job with default values. WebRequest postRequest = new PostMethodWebRequest(serviceUrl); // Add parameters if available. if (parameters != null) { List<String> valueList; List<String> keyList = new ArrayList<String>(parameters.keySet()); for (String key : keyList) { valueList = parameters.get(key); postRequest.setParameter(key, valueList.toArray(new String[0])); } } // Set the RUNID to INTTEST postRequest.setParameter("runId", new String[] {"INTTEST"}); log.debug(Util.getRequestParameters(postRequest)); return createJob(conversation, postRequest); }
private WebRequest getScriptedSubmitRequest() { SubmitButton[] buttons = getSubmitButtons(); for (int i = 0; i < buttons.length; i++) { buttons[i].setPressed( false ); } if (getMethod().equalsIgnoreCase( "post" )) { return new PostMethodWebRequest( this ); } else { return new GetMethodWebRequest( this ); } }
private WebRequest getScriptedSubmitRequest() { SubmitButton[] buttons = getSubmitButtons(); for (int i = 0; i < buttons.length; i++) { buttons[i].setPressed( false ); } if (getMethod().equalsIgnoreCase( "post" )) { return new PostMethodWebRequest( this ); } else { return new GetMethodWebRequest( this ); } }
private WebRequest getScriptedSubmitRequest() { SubmitButton[] buttons = getSubmitButtons(); for (int i = 0; i < buttons.length; i++) { buttons[i].setPressed( false ); } if (getMethod().equalsIgnoreCase( "post" )) { return new PostMethodWebRequest( this ); } else { return new GetMethodWebRequest( this ); } }
WebRequest postRequest = new PostMethodWebRequest(resourceUrl); postRequest.setParameter("PHASE", "RUN"); post(conversation, postRequest);
@Test public void testInvokingSpringBeans() throws Exception { WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/Greeter", getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=utf-8"); invokingEndpoint(req); req = new PostMethodWebRequest(CONTEXT_URL + "/services/Greeter1", getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=utf-8"); invokingEndpoint(req); }
@Test public void testInvokingSpringBeans() throws Exception { WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/SOAPService", getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=utf-8"); invokingEndpoint(req); req = new PostMethodWebRequest(CONTEXT_URL + "/services/DerivedGreeterService", getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=utf-8"); invokingEndpoint(req); }