/** * Returns true if the response is HTML. * @return true if the contenType fits **/ public boolean isHTML() { boolean result=false; // check the different content types for (int i=0;i<validContentTypes.length;i++) { result=getContentType().equalsIgnoreCase(validContentTypes[i]); if (result) break; } // for return result; }
/** * Returns true if the response is HTML. * @return true if the contenType fits **/ public boolean isHTML() { boolean result=false; // check the different content types for (int i=0;i<validContentTypes.length;i++) { result=getContentType().equalsIgnoreCase(validContentTypes[i]); if (result) break; } // for return result; }
/** * Returns true if the response is HTML. * @return true if the contenType fits **/ public boolean isHTML() { boolean result=false; // check the different content types for (int i=0;i<validContentTypes.length;i++) { result=getContentType().equalsIgnoreCase(validContentTypes[i]); if (result) break; } // for return result; }
/** * Constructs a response object from a servlet response. * @param frame the target frame on which the response will be displayed * @param url the url from which the response was received * @param response the response populated by the servlet **/ ServletUnitWebResponse( ServletUnitClient client, FrameSelector frame, URL url, HttpServletResponse response, boolean throwExceptionOnError ) throws IOException { super( client, frame, url ); _response = (ServletUnitHttpResponse) response; /** make sure that any IO exception for HTML received page happens here, not later. **/ if (getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST || !throwExceptionOnError) { defineRawInputStream( new ByteArrayInputStream( _response.getContents() ) ); if (getContentType().startsWith( "text" )) loadResponseText(); } }
/** * Constructs a response object from an input stream. * @param frame the target window or frame to which the request should be directed * @param url the url from which the response was received * @param connection the URL connection from which the response can be read **/ HttpWebResponse( WebConversation client, FrameSelector frame, URL url, URLConnection connection, boolean throwExceptionOnError ) throws IOException { super( client, frame, url ); if (HttpUnitOptions.isLoggingHttpHeaders()) System.out.println( "\nReceived from " + url ); readHeaders( connection ); /** make sure that any IO exception for HTML received page happens here, not later. **/ if (_responseCode < HttpURLConnection.HTTP_BAD_REQUEST || !throwExceptionOnError) { defineRawInputStream( new BufferedInputStream( getInputStream( connection ) ) ); if (getContentType().startsWith( "text" )) loadResponseText(); } }
private void verifyPhase(WebConversation conversation, String jobId, String expectedPhase) throws Throwable { // GET request to the phase resource. String resourceUrl = serviceUrl + "/" + jobId + "/phase"; WebResponse response = get(conversation, resourceUrl, "text/plain"); log.debug(Util.getResponseHeaders(response)); log.debug("Response.getText():\r\n" + response.getText()); assertEquals("GET response Content-Type header to " + resourceUrl + " is incorrect", "text/plain", response.getContentType()); assertEquals("response should return only a string of the phase.", expectedPhase, response.getText()); }
@Test public void testGetServiceList() throws Exception { WebConversation client = new WebConversation(); WebResponse res = client.getResponse(serviceURL + "/services"); WebLink[] links = res.getLinks(); Set<String> s = new HashSet<>(); for (WebLink l : links) { s.add(l.getURLString()); } assertEquals("There should be 3 links for the service", 3, links.length); assertTrue(s.contains(serviceURL + "Greeter?wsdl")); assertTrue(s.contains(serviceURL + "Hello?wsdl")); assertTrue(s.contains(serviceURL + "?wsdl")); assertEquals("text/html", res.getContentType()); } }
@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 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); }
@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 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); }
@Test public void testGetImportedXSD() 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()); String text = res.getText(); assertEquals("text/xml", res.getContentType()); assertTrue(text.contains(CONTEXT_URL + "/services/greeter?wsdl=test_import.xsd")); req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter?wsdl=test_import.xsd"); res = client.getResponse(req); assertEquals(200, res.getResponseCode()); text = res.getText(); assertEquals("text/xml", res.getContentType()); assertTrue("the xsd should contain the completType SimpleStruct", text.contains("<complexType name=\"SimpleStruct\">")); }
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 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); }
@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