@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); } }
InputStream body = new FileInputStream("create.xml"); WebRequest request = new PostMethodWebRequest("http://example.com/thing/create", body, "text/xml");
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 ); } }
@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); }
/** * Creates and returns a web request which includes the specified button and position. If no button is specified, * will include the default button, if any. No parameter validation will be done on the returned request * and no scripts will be run when it is submitted. **/ public WebRequest newUnvalidatedRequest( SubmitButton button, int x, int y ) { if (button == null) button = getDefaultButton(); SubmitButton[] buttons = getSubmitButtons(); for (int i = 0; i < buttons.length; i++) { buttons[i].setPressed( false ); } button.setPressed( true ); if (getMethod().equalsIgnoreCase( "post" )) { return new PostMethodWebRequest( this, new UncheckedParameterHolder( this ), button, x, y ); } else { return new GetMethodWebRequest( this, new UncheckedParameterHolder( this ), button, x, y ); } }
/** * Creates and returns a web request which includes the specified button and position. If no button is specified, * will include the default button, if any. No parameter validation will be done on the returned request * and no scripts will be run when it is submitted. **/ public WebRequest newUnvalidatedRequest( SubmitButton button, int x, int y ) { if (button == null) button = getDefaultButton(); SubmitButton[] buttons = getSubmitButtons(); for (int i = 0; i < buttons.length; i++) { buttons[i].setPressed( false ); } button.setPressed( true ); if (getMethod().equalsIgnoreCase( "post" )) { return new PostMethodWebRequest( this, new UncheckedParameterHolder( this ), button, x, y ); } else { return new GetMethodWebRequest( this, new UncheckedParameterHolder( this ), button, x, y ); } }
/** * Creates and returns a web request which includes the specified button and position. If no button is specified, * will include the default button, if any. No parameter validation will be done on the returned request * and no scripts will be run when it is submitted. **/ public WebRequest newUnvalidatedRequest( SubmitButton button, int x, int y ) { if (button == null) button = getDefaultButton(); SubmitButton[] buttons = getSubmitButtons(); for (int i = 0; i < buttons.length; i++) { buttons[i].setPressed( false ); } button.setPressed( true ); if (getMethod().equalsIgnoreCase( "post" )) { return new PostMethodWebRequest( this, new UncheckedParameterHolder( this ), button, x, y ); } else { return new GetMethodWebRequest( this, new UncheckedParameterHolder( this ), button, x, y ); } }
private void invoke(String encoding) throws Exception { WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/greeter", getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=" + encoding); ServletUnitClient client = newClient(); WebResponse response = client.getResponse(req); client.setExceptionsThrownOnErrorStatus(false); assertEquals("text/xml", response.getContentType()); assertTrue(encoding.equalsIgnoreCase(response.getCharacterSet())); Document doc = StaxUtils.read(response.getInputStream()); assertNotNull(doc); addNamespace("h", "http://apache.org/hello_world_soap_http/types"); assertValid("/s:Envelope/s:Body", doc); assertValid("//h:sayHiResponse", doc); }
@Test public void testPostInvokeServices() throws Exception { newClient(); WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/greeter", getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=UTF-8"); WebResponse response = newClient().getResponse(req); assertEquals("text/xml", response.getContentType()); assertEquals(StandardCharsets.UTF_8.name(), response.getCharacterSet()); Document doc = StaxUtils.read(response.getInputStream()); assertNotNull(doc); addNamespace("h", "http://apache.org/hello_world_soap_http/types"); assertValid("/s:Envelope/s:Body", doc); assertValid("//h:sayHiResponse", doc); } }
@Test public void testPostInvokeServices() throws Exception { newClient(); WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/Greeter", getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=UTF-8"); WebResponse response = newClient().getResponse(req); assertEquals("text/xml", response.getContentType()); assertEquals(StandardCharsets.UTF_8.name(), response.getCharacterSet()); Document doc = StaxUtils.read(response.getInputStream()); assertNotNull(doc); addNamespace("h", "http://apache.org/hello_world_soap_http/types"); assertValid("/s:Envelope/s:Body", doc); assertValid("//h:sayHiResponse", doc); } }
@Test public void testPostInvokeServices() throws Exception { WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/Greeter", getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=UTF-8"); WebResponse response = newClient().getResponse(req); assertEquals("text/xml", response.getContentType()); //assertEquals(StandardCharsets.UTF_8, response.getCharacterSet()); Document doc = StaxUtils.read(response.getInputStream()); assertNotNull(doc); addNamespace("h", "http://apache.org/hello_world_soap_http/types"); assertValid("/s:Envelope/s:Body", doc); assertValid("//h:sayHiResponse", doc); assertValid("//h:responseType", doc); }