protected void run(JavaNet cmd) throws ProcessingException, BuildException { // mandatory attributes check if( localFile==null ) throw new BuildException("file name is not set"); if( url==null ) throw new BuildException("url is not set"); log("downloading "+url,Project.MSG_VERBOSE); try { WebResponse r = cmd.getConversation().getResponse(url.toExternalForm()); copyStream( r.getInputStream(), new FileOutputStream(localFile) ); } catch( IOException e ) { throw new BuildException(e); } catch( SAXException e ) { throw new BuildException(e); } log("done",Project.MSG_VERBOSE); }
protected void loadResponseText() throws IOException { if (_responseText != null) throw new IllegalStateException( "May only invoke loadResponseText once" ); _responseText = ""; InputStream inputStream = getInputStream(); try { final int contentLength = this.encodedUsingGZIP() ? -1 : getContentLength(); int bytesRemaining = contentLength < 0 ? Integer.MAX_VALUE : contentLength; byte[] bytes = readFromStream( inputStream, bytesRemaining ); readTags( bytes ); _responseText = new String( bytes, getCharacterSet() ); _inputStream = new ByteArrayInputStream( bytes ); if (HttpUnitOptions.isCheckContentLength() && contentLength >= 0 && bytes.length != contentLength) { throw new IOException("Truncated message. Expected length: " + contentLength + ", Actual length: " + bytes.length); } } finally { inputStream.close(); } }
protected void loadResponseText() throws IOException { if (_responseText != null) throw new IllegalStateException( "May only invoke loadResponseText once" ); _responseText = ""; InputStream inputStream = getInputStream(); try { final int contentLength = this.encodedUsingGZIP() ? -1 : getContentLength(); int bytesRemaining = contentLength < 0 ? Integer.MAX_VALUE : contentLength; byte[] bytes = readFromStream( inputStream, bytesRemaining ); readTags( bytes ); _responseText = new String( bytes, getCharacterSet() ); _inputStream = new ByteArrayInputStream( bytes ); if (HttpUnitOptions.isCheckContentLength() && contentLength >= 0 && bytes.length != contentLength) { throw new IOException("Truncated message. Expected length: " + contentLength + ", Actual length: " + bytes.length); } } finally { inputStream.close(); } }
protected void loadResponseText() throws IOException { if (_responseText != null) throw new IllegalStateException( "May only invoke loadResponseText once" ); _responseText = ""; InputStream inputStream = getInputStream(); try { final int contentLength = this.encodedUsingGZIP() ? -1 : getContentLength(); int bytesRemaining = contentLength < 0 ? Integer.MAX_VALUE : contentLength; byte[] bytes = readFromStream( inputStream, bytesRemaining ); readTags( bytes ); _responseText = new String( bytes, getCharacterSet() ); _inputStream = new ByteArrayInputStream( bytes ); if (HttpUnitOptions.isCheckContentLength() && contentLength >= 0 && bytes.length != contentLength) { throw new IOException("Truncated message. Expected length: " + contentLength + ", Actual length: " + bytes.length); } } finally { inputStream.close(); } }
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 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(); }
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(); }
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)); }
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 testGetWSDLWithXMLBinding() throws Exception { ServletUnitClient client = newClient(); client.setExceptionsThrownOnErrorStatus(true); WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter2?wsdl"); WebResponse res = client.getResponse(req); assertEquals(200, res.getResponseCode()); assertEquals("text/xml", res.getContentType()); Document doc = StaxUtils.read(res.getInputStream()); assertNotNull(doc); addNamespace("http", "http://schemas.xmlsoap.org/wsdl/http/"); assertValid("//wsdl:operation[@name='greetMe']", doc); NodeList addresses = assertValid("//http:address/@location", doc); boolean found = true; for (int i = 0; i < addresses.getLength(); i++) { String address = addresses.item(i).getLocalName(); if (address.startsWith("http://localhost") && address.endsWith("/services/greeter2")) { found = true; break; } } assertTrue(found); }
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 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 { 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 { 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); }
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 testGetWSDLWithIncludes() throws Exception { ServletUnitClient client = newClient(); client.setExceptionsThrownOnErrorStatus(true); WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter3?wsdl"); WebResponse res = client.getResponse(req); assertEquals(200, res.getResponseCode()); assertEquals("text/xml", res.getContentType()); Document doc = StaxUtils.read(res.getInputStream()); assertNotNull(doc); assertXPathEquals("//xsd:include/@schemaLocation", "http://localhost/mycontext/services/greeter3?xsd=hello_world_includes2.xsd", doc.getDocumentElement()); req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter3?xsd=hello_world_includes2.xsd"); res = client.getResponse(req); assertEquals(200, res.getResponseCode()); assertEquals("text/xml", res.getContentType()); doc = StaxUtils.read(res.getInputStream()); assertNotNull(doc); assertValid("//xsd:complexType[@name='ErrorCode']", 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); }
assertEquals("text/xml", res.getContentType()); Document doc = StaxUtils.read(res.getInputStream()); assertNotNull(doc); assertEquals("text/xml", res.getContentType()); doc = StaxUtils.read(res.getInputStream()); assertNotNull(doc);
@Test public void testGetWSDLWithMultiplePublishedEndpointUrl() throws Exception { ServletUnitClient client = newClient(); client.setExceptionsThrownOnErrorStatus(true); WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter5?wsdl"); WebResponse res = client.getResponse(req); assertEquals(200, res.getResponseCode()); assertEquals("text/xml", res.getContentType()); Document doc = StaxUtils.read(res.getInputStream()); assertNotNull(doc); WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); wsdlReader.setFeature("javax.wsdl.verbose", false); assertValid("//wsdl:service[@name='SOAPService']/wsdl:port[@name='SoapPort']/wsdlsoap:address[@location='" + "http://cxf.apache.org/publishedEndpointUrl1']", doc); assertValid("//wsdl:service[@name='SOAPService']/wsdl:port[@name='SoapPort1']/wsdlsoap:address[@location='" + "http://cxf.apache.org/publishedEndpointUrl2']", doc); } @Test