/** 将服务端response提交到client。 */ public void commit() { try { if (requestContexts != null && requestContext != null) { requestContexts.commitRequestContext(requestContext); } clientResponse = client.getResponse(invocationContext); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
/** 将服务端response提交到client。 */ public void commit() { try { if (requestContexts != null && requestContext != null) { requestContexts.commitRequestContext(requestContext); } clientResponse = client.getResponse(invocationContext); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
/** * Returns the response from the specified servlet using GET. * @exception SAXException thrown if there is an error parsing the response **/ public WebResponse getResponse( String url ) throws MalformedURLException, IOException, SAXException { return getClient().getResponse( url ); }
/** * Returns the response from the specified servlet. * @exception SAXException thrown if there is an error parsing the response **/ public WebResponse getResponse( WebRequest request ) throws MalformedURLException, IOException, SAXException { return getClient().getResponse( request ); }
/** * Returns the response from the specified servlet using GET. * @exception SAXException thrown if there is an error parsing the response **/ public WebResponse getResponse( String url ) throws MalformedURLException, IOException, SAXException { return getClient().getResponse( url ); }
/** * Returns the response from the specified servlet. * @exception SAXException thrown if there is an error parsing the response **/ public WebResponse getResponse( WebRequest request ) throws MalformedURLException, IOException, SAXException { return getClient().getResponse( request ); }
public void testDynamicReport() throws Exception { ServletRunner sr = new ServletRunner( getClass().getResourceAsStream("/webwork/web.xml") ); // (1) use the web.xml file to define mappings ServletUnitClient client = sr.newClient(); // (2) create a client to invoke the application WebResponse r = client.getResponse( "http://localhost/generateReport.action" ); // (3) invoke the servlet w/o authorization String fname=r.getHeaderField("CONTENT-DISPOSITION"); fname = fname.substring(fname.indexOf("=")+1); FileOutputStream fos = new FileOutputStream( new File(System.getProperty("user.dir")+ "/target/" + fname)); InputStream is = r.getInputStream(); StreamUtils.copy(is, fos); is.close(); fos.close(); }
public void testDynamicReportWithTemplate() throws Exception { ServletRunner sr = new ServletRunner( getClass().getResourceAsStream("/struts2/web.xml") ); // (1) use the web.xml file to define mappings ServletUnitClient client = sr.newClient(); // (2) create a client to invoke the application WebResponse r = client.getResponse( "http://localhost/generateReportTemplate.action" ); // (3) invoke the servlet w/o authorization String fname=r.getHeaderField("CONTENT-DISPOSITION"); fname = fname.substring(fname.indexOf("=")+1); FileOutputStream fos = new FileOutputStream( new File(System.getProperty("user.dir")+ "/target/" + fname)); InputStream is = r.getInputStream(); StreamUtils.copy(is, fos); is.close(); fos.close(); }
public void testDynamicReportWithTemplate() throws Exception { ServletRunner sr = new ServletRunner( getClass().getResourceAsStream("/webwork/web.xml") ); // (1) use the web.xml file to define mappings ServletUnitClient client = sr.newClient(); // (2) create a client to invoke the application WebResponse r = client.getResponse( "http://localhost/generateReportTemplate.action" ); // (3) invoke the servlet w/o authorization String fname=r.getHeaderField("CONTENT-DISPOSITION"); fname = fname.substring(fname.indexOf("=")+1); FileOutputStream fos = new FileOutputStream( new File(System.getProperty("user.dir")+ "/target/" + fname)); InputStream is = r.getInputStream(); StreamUtils.copy(is, fos); is.close(); fos.close(); }
public void testDynamicReport() throws Exception { ServletRunner sr = new ServletRunner( getClass().getResourceAsStream("/struts2/web.xml") ); // (1) use the web.xml file to define mappings ServletUnitClient client = sr.newClient(); // (2) create a client to invoke the application WebResponse r = client.getResponse( "http://localhost/example/generateReport.action" ); // (3) invoke the servlet w/o authorization String fname=r.getHeaderField("CONTENT-DISPOSITION"); fname = fname.substring(fname.indexOf("=")+1); FileOutputStream fos = new FileOutputStream( new File(System.getProperty("user.dir")+ "/target/" + fname)); InputStream is = r.getInputStream(); StreamUtils.copy(is, fos); is.close(); fos.close(); }
@Before public void setUp() throws Exception { InputStream configurationStream = getResourceAsStream(getConfiguration()); sr = new ServletRunner(configurationStream, CONTEXT); try { sr.newClient().getResponse(CONTEXT_URL + "/services"); } catch (HttpNotFoundException e) { // ignore, we just want to boot up the servlet } HttpUnitOptions.setExceptionsThrownOnErrorStatus(true); }
@Test public void testGetUnformatServiceList() throws Exception { ServletUnitClient client = newClient(); client.setExceptionsThrownOnErrorStatus(false); WebResponse res = client.getResponse(CONTEXT_URL + "/services?formatted=false"); assertTrue(res.getText().contains("http://localhost/mycontext/services/greeter3")); assertTrue(res.getText().contains("http://localhost/mycontext/services/greeter2")); assertTrue(res.getText().contains("http://localhost/mycontext/services/greeter")); }
@Before public void setUp() throws Exception { InputStream configurationStream = getResourceAsStream(getConfiguration()); sr = new ServletRunner(configurationStream, CONTEXT); try { sr.newClient().getResponse(CONTEXT_URL + "/services"); } catch (HttpNotFoundException e) { // ignore, we just want to boot up the servlet } HttpUnitOptions.setExceptionsThrownOnErrorStatus(true); configurationStream.close(); } @After
@Test public void testGetServiceList() throws Exception { ServletUnitClient client = newClient(); client.setExceptionsThrownOnErrorStatus(false); //test the '/' context get service list WebResponse res = client.getResponse(CONTEXT_URL + "/"); WebLink[] links = res.getLinks(); assertEquals("Wrong number of service links", 3, links.length); Set<String> links2 = new HashSet<>(); for (WebLink l : links) { links2.add(l.getURLString()); } assertEquals("text/html", res.getContentType()); }
private void testInvokingBookService(String serviceAddress) throws Exception { ServletUnitClient client = newClient(); client.setExceptionsThrownOnErrorStatus(false); WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + serviceAddress); WebResponse response = client.getResponse(req); InputStream in = response.getInputStream(); InputStream expected = JaxRsServletTest.class .getResourceAsStream("resources/expected_get_book123.txt"); assertEquals(" Can't get the expected result ", getStringFromInputStream(expected), getStringFromInputStream(in)); }
@Test public void testInvalidServiceUrl() throws Exception { ServletUnitClient client = newClient(); client.setExceptionsThrownOnErrorStatus(false); WebResponse res = client.getResponse(CONTEXT_URL + "/services/NoSuchService"); assertEquals(404, res.getResponseCode()); assertEquals("text/html", res.getContentType()); }
@Test public void testInvoke() { try { sr = new ServletRunner(getResourceAsStream(getConfiguration()), CONTEXT); sr.newClient().getResponse(CONTEXT_URL + "/services"); // there expect a spring bean exception fail("we expect a spring bean Exception here"); } catch (Exception ex) { // supprot spring 2.0.x and sping 2.5 assertTrue("we expect a Bean Exception here", ex instanceof org.springframework.beans.FatalBeanException); } }
public void invokingEndpoint(WebRequest req) throws Exception { WebResponse response = newClient().getResponse(req); assertEquals("text/xml", response.getContentType()); assertTrue("utf-8".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); }
public void invokingEndpoint(WebRequest req) throws Exception { WebResponse response = newClient().getResponse(req); assertEquals("text/xml", response.getContentType()); assertTrue("utf-8".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 testGetWSDL() throws Exception { ServletUnitClient client = newClient(); client.setExceptionsThrownOnErrorStatus(true); WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter?wsdl"); WebResponse res = client.getResponse(req); assertEquals(200, res.getResponseCode()); assertEquals("text/xml", res.getContentType()); Document doc = StaxUtils.read(res.getInputStream()); assertNotNull(doc); assertValid("//wsdl:operation[@name='greetMe']", doc); assertValid("//wsdlsoap:address[@location='" + CONTEXT_URL + "/services/greeter']", doc); }