You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2022/08/01 19:55:26 UTC
[cxf] 01/02: CXF-8744: Get rid of httpunit (#974)
This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch 3.5.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit a7b4f1698c9f05ad0af949f8a3ab9a45976d9a2d
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Mon Aug 1 15:10:20 2022 -0400
CXF-8744: Get rid of httpunit (#974)
(cherry picked from commit 3d71fe88f5d9649f3b770598b5b170cb6bc8871f)
# Conflicts:
# systests/transports/pom.xml
# systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringServletContextTest.java
---
systests/transports/pom.xml | 21 +-
.../cxf/systest/servlet/AbstractJettyServer.java | 75 ++++
.../cxf/systest/servlet/AbstractServletTest.java | 137 +++---
.../apache/cxf/systest/servlet/CXFFilterTest.java | 116 +++--
.../apache/cxf/systest/servlet/CXFServletTest.java | 466 +++++++++++----------
.../systest/servlet/ErrorContextSerletTest.java | 62 ---
.../systest/servlet/ErrorContextServletTest.java | 72 ++++
.../servlet/ExternalServicesServletTest.java | 135 +++---
.../systest/servlet/GetMethodQueryWebRequest.java | 42 --
.../cxf/systest/servlet/JaxRsServletTest.java | 78 ----
.../cxf/systest/servlet/JsFrontEndServletTest.java | 85 ++--
.../systest/servlet/NoSpringServletClientTest.java | 48 ++-
.../servlet/SpringAutoPublishServletTest.java | 153 ++++---
.../systest/servlet/SpringServletContextTest.java | 63 ++-
.../cxf/systest/servlet/SpringServletTest.java | 193 +++++----
15 files changed, 958 insertions(+), 788 deletions(-)
diff --git a/systests/transports/pom.xml b/systests/transports/pom.xml
index bc26953d6f..ba1aa9fbaa 100644
--- a/systests/transports/pom.xml
+++ b/systests/transports/pom.xml
@@ -229,24 +229,9 @@
<version>${cxf.spring.version}</version>
</dependency>
<dependency>
- <groupId>httpunit</groupId>
- <artifactId>httpunit</artifactId>
- <version>1.7</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>xerces</groupId>
- <artifactId>xercesImpl</artifactId>
- </exclusion>
- <exclusion>
- <groupId>xerces</groupId>
- <artifactId>xmlParserAPIs</artifactId>
- </exclusion>
- </exclusions>
+ <groupId>net.sourceforge.nekohtml</groupId>
+ <artifactId>nekohtml</artifactId>
+ <version>1.9.22</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/AbstractJettyServer.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/AbstractJettyServer.java
new file mode 100644
index 0000000000..2d72777d71
--- /dev/null
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/AbstractJettyServer.java
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.servlet;
+
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.DefaultHandler;
+import org.eclipse.jetty.server.handler.HandlerCollection;
+import org.eclipse.jetty.util.resource.Resource;
+import org.eclipse.jetty.webapp.WebAppContext;
+
+import static org.junit.Assert.fail;
+
+public abstract class AbstractJettyServer extends AbstractBusTestServerBase {
+ private org.eclipse.jetty.server.Server server;
+ private final String descriptor;
+ private final String resourcePath;
+ private final String contextPath;
+ private final int port;
+
+ protected AbstractJettyServer(final String descriptor, final String resourcePath,
+ final String contextPath, int portNumber) {
+ this.descriptor = descriptor;
+ this.resourcePath = resourcePath;
+ this.contextPath = contextPath;
+ this.port = portNumber;
+ }
+
+ protected void run() {
+ server = new Server(port);
+
+ try {
+ final WebAppContext context = new WebAppContext();
+ context.setContextPath(contextPath);
+ context.setBaseResource(Resource.newClassPathResource(resourcePath));
+ context.setDescriptor(Resource.newClassPathResource(descriptor).getURI().toString());
+
+ HandlerCollection handlers = new HandlerCollection();
+ handlers.setHandlers(new Handler[] {context, new DefaultHandler()});
+ server.setHandler(handlers);
+ server.start();
+ } catch (final Exception ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ if (server != null) {
+ server.stop();
+ server.destroy();
+ server = null;
+ }
+ }
+}
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/AbstractServletTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/AbstractServletTest.java
index bcf882d5fd..4e59e67e47 100644
--- a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/AbstractServletTest.java
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/AbstractServletTest.java
@@ -21,60 +21,105 @@ package org.apache.cxf.systest.servlet;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
+import java.util.Collection;
+import java.util.HashSet;
-import org.xml.sax.SAXException;
-
-import com.meterware.httpunit.HttpException;
-import com.meterware.httpunit.HttpNotFoundException;
-import com.meterware.httpunit.HttpUnitOptions;
-import com.meterware.httpunit.WebRequest;
-import com.meterware.servletunit.ServletRunner;
-import com.meterware.servletunit.ServletUnitClient;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
-import org.apache.cxf.test.AbstractCXFTest;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
-import org.junit.After;
-import org.junit.Before;
+import org.apache.cxf.test.TestUtilities;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.html.dom.HTMLAnchorElementImpl;
+import org.apache.html.dom.HTMLDocumentImpl;
+import org.apache.http.HttpHeaders;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.entity.ContentType;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.cyberneko.html.parsers.DOMParser;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-public abstract class AbstractServletTest extends AbstractCXFTest {
+public abstract class AbstractServletTest extends AbstractBusClientServerTestBase {
public static final String CONTEXT = "/mycontext";
- public static final String CONTEXT_URL = "http://localhost/mycontext";
- protected ServletRunner sr;
-
- @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
- }
+ protected TestUtilities testUtilities;
+
+ protected AbstractServletTest() {
+ testUtilities = new TestUtilities(getClass());
+ testUtilities.addDefaultNamespaces();
+ }
- HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
- configurationStream.close();
+ /**
+ * Add a namespace that will be used for XPath expressions.
+ *
+ * @param ns Namespace name.
+ * @param uri The namespace uri.
+ */
+ public void addNamespace(String ns, String uri) {
+ testUtilities.addNamespace(ns, uri);
}
- @After
- public void tearDown() throws Exception {
- if (sr != null) {
- sr.shutDown();
- }
+
+ /**
+ * Assert that the following XPath query selects one or more nodes.
+ *
+ * @param xpath
+ * @throws Exception
+ */
+ public NodeList assertValid(String xpath, Node node) throws Exception {
+ return testUtilities.assertValid(xpath, node);
}
/**
- * @return The web.xml to use for testing.
+ * Assert that the text of the xpath node retrieved is equal to the value
+ * specified.
+ *
+ * @param xpath
+ * @param value
+ * @param node
*/
- protected String getConfiguration() {
- return "/org/apache/cxf/systest/servlet/web.xml";
+ public void assertXPathEquals(String xpath, String value, Node node) throws Exception {
+ testUtilities.assertXPathEquals(xpath, value, node);
}
- protected ServletUnitClient newClient() {
- return sr.newClient();
+ protected CloseableHttpClient newClient() {
+ return HttpClients.createDefault();
}
+ protected String uri(String path) {
+ return "http://localhost:" + getPort() + CONTEXT + path;
+ }
+
+ protected Collection<HTMLAnchorElementImpl> getLinks(HTMLDocumentImpl document) {
+ final Collection<HTMLAnchorElementImpl> links = new HashSet<>();
+
+ for (int i = 0; i < document.getLinks().getLength(); ++i) {
+ final HTMLAnchorElementImpl link = (HTMLAnchorElementImpl)document.getLinks().item(i);
+ links.add(link);
+ }
+
+ return links;
+ }
+
+ protected HTMLDocumentImpl parse(InputStream in) throws SAXException, IOException {
+ final DOMParser parser = new DOMParser();
+ parser.parse(new InputSource(in));
+ return (HTMLDocumentImpl)parser.getDocument();
+ }
+
+ protected String getContentType(CloseableHttpResponse response) {
+ return ContentType.parse(response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue()).getMimeType();
+ }
+
+ protected String getCharset(CloseableHttpResponse response) {
+ return ContentType.parse(response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue()).getCharset().name();
+ }
+
+ protected abstract int getPort();
+
/**
* Here we expect an errorCode other than 200, and look for it checking for
* text is omitted as it doesn't work. It would never work on java1.3, but
@@ -88,20 +133,12 @@ public abstract class AbstractServletTest extends AbstractCXFTest {
* @throws IOException
* @throws SAXException
*/
- protected void expectErrorCode(WebRequest request, int errorCode, String errorText)
+ protected void expectErrorCode(HttpUriRequest request, int errorCode, String errorText)
throws MalformedURLException, IOException, SAXException {
- String failureText = "Expected error " + errorCode + " from " + request.getURL();
-
- try {
- newClient().getResponse(request);
- fail(errorText + " -got success instead");
- } catch (HttpException e) {
- assertEquals(failureText, errorCode, e.getResponseCode());
- /*
- * checking for text omitted as it doesn't work. if(errorText!=null) {
- * assertTrue( "Failed to find "+errorText+" in "+
- * e.getResponseMessage(), e.getMessage().indexOf(errorText)>=0); }
- */
+ String failureText = "Expected error " + errorCode + " from " + request.getRequestLine().getUri();
+
+ try (CloseableHttpResponse response = newClient().execute(request)) {
+ assertEquals(failureText, errorCode, response.getStatusLine().getStatusCode());
}
}
}
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/CXFFilterTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/CXFFilterTest.java
index 681cc5842e..b4e6baf8c8 100644
--- a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/CXFFilterTest.java
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/CXFFilterTest.java
@@ -20,70 +20,102 @@ package org.apache.cxf.systest.servlet;
import java.nio.charset.StandardCharsets;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.w3c.dom.Document;
-import com.meterware.httpunit.PostMethodWebRequest;
-import com.meterware.httpunit.WebLink;
-import com.meterware.httpunit.WebRequest;
-import com.meterware.httpunit.WebResponse;
-import com.meterware.servletunit.ServletUnitClient;
-
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
import org.apache.cxf.staxutils.StaxUtils;
-
+import org.apache.html.dom.HTMLAnchorElementImpl;
+import org.apache.html.dom.HTMLDocumentImpl;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
public class CXFFilterTest extends AbstractServletTest {
+ @Ignore
+ public static class EmbeddedJettyServer extends AbstractJettyServer {
+ public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class);
- @Override
- protected String getConfiguration() {
- return "/org/apache/cxf/systest/servlet/web-filter.xml";
+ public EmbeddedJettyServer() {
+ super("/org/apache/cxf/systest/servlet/web-filter.xml", "/", CONTEXT, PORT);
+ }
}
- @Test
- public void testGetServiceList() throws Exception {
-
- ServletUnitClient client = newClient();
- client.setExceptionsThrownOnErrorStatus(false);
+ @BeforeClass
+ public static void startServers() throws Exception {
+ AbstractResourceInfo.clearAllMaps();
+ assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true));
+ createStaticBus();
+ }
- //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);
+ @AfterClass
+ public static void tearDown() throws Exception {
+ stopAllServers();
+ }
- Set<String> links2 = new HashSet<>();
- for (WebLink l : links) {
- links2.add(l.getURLString());
+ @Test
+ public void testGetServiceList() throws Exception {
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet method = new HttpGet(uri("/"));
+
+ //test the '/' context get service list
+ try (CloseableHttpResponse res = client.execute(method)) {
+ HTMLDocumentImpl doc = parse(res.getEntity().getContent());
+ Collection<HTMLAnchorElementImpl> links = getLinks(doc);
+ assertEquals("Wrong number of service links", 3, links.size());
+
+ Set<String> links2 = new HashSet<>();
+ for (HTMLAnchorElementImpl link: links) {
+ links2.add(link.getHref());
+ }
+
+ assertEquals("text/html", getContentType(res));
+ assertEquals(StandardCharsets.UTF_8.name(), getCharset(res));
+ }
}
-
- assertEquals("text/html", res.getContentType());
}
@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");
+ try (CloseableHttpClient client = newClient()) {
+ final HttpPost method = new HttpPost(uri("/services/Greeter"));
+
+ method.setEntity(new InputStreamEntity(getClass().getResourceAsStream("GreeterMessage.xml"),
+ ContentType.create("text/xml", StandardCharsets.UTF_8)));
+
+ try (CloseableHttpResponse response = client.execute(method)) {
+ assertEquals("text/xml", getContentType(response));
+ assertEquals(StandardCharsets.UTF_8.name(), getCharset(response));
+
+ Document doc = StaxUtils.read(response.getEntity().getContent());
+ assertNotNull(doc);
+
+ addNamespace("h", "http://apache.org/hello_world_soap_http/types");
+
+ assertValid("/s:Envelope/s:Body", doc);
+ assertValid("//h:sayHiResponse", doc);
+ }
+ }
+ }
- assertValid("/s:Envelope/s:Body", doc);
- assertValid("//h:sayHiResponse", doc);
+ @Override
+ protected int getPort() {
+ return EmbeddedJettyServer.PORT;
}
-}
\ No newline at end of file
+}
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java
index e5ea8f17d9..7d342c2d4d 100644
--- a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/CXFServletTest.java
@@ -18,9 +18,8 @@
*/
package org.apache.cxf.systest.servlet;
-
-
import java.nio.charset.StandardCharsets;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -33,41 +32,54 @@ import javax.xml.ws.soap.SOAPBinding;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
-import com.meterware.httpunit.GetMethodWebRequest;
-import com.meterware.httpunit.PostMethodWebRequest;
-import com.meterware.httpunit.WebLink;
-import com.meterware.httpunit.WebRequest;
-import com.meterware.httpunit.WebResponse;
-import com.meterware.servletunit.ServletUnitClient;
-
import org.apache.cxf.Bus;
-import org.apache.cxf.BusException;
import org.apache.cxf.BusFactory;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
import org.apache.cxf.staxutils.StaxUtils;
import org.apache.hello_world_soap_http.BaseGreeterImpl;
-
-import org.junit.Before;
+import org.apache.html.dom.HTMLAnchorElementImpl;
+import org.apache.html.dom.HTMLDocumentImpl;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class CXFServletTest extends AbstractServletTest {
+ @Ignore
+ public static class EmbeddedJettyServer extends AbstractJettyServer {
+ public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class);
+
+ public EmbeddedJettyServer() {
+ super("/org/apache/cxf/systest/servlet/web.xml", "/", CONTEXT, PORT);
+ }
+ }
- @Before
- public void setUp() throws Exception {
- BusFactory.setDefaultBus(null);
- BusFactory.setThreadDefaultBus(null);
- super.setUp();
+ @BeforeClass
+ public static void startServers() throws Exception {
+ AbstractResourceInfo.clearAllMaps();
+ assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true));
+ createStaticBus();
}
- @Override
- protected Bus createBus() throws BusException {
- return null;
+ @AfterClass
+ public static void tearDown() throws Exception {
+ stopAllServers();
}
@Test
@@ -78,245 +90,268 @@ public class CXFServletTest extends AbstractServletTest {
}
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);
+ try (CloseableHttpClient client = newClient()) {
+ final HttpPost method = new HttpPost(uri("/services/greeter"));
+
+ method.setEntity(new InputStreamEntity(getClass().getResourceAsStream("GreeterMessage.xml"),
+ ContentType.create("text/xml", encoding)));
+
+ try (CloseableHttpResponse response = client.execute(method)) {
+ assertEquals("text/xml", getContentType(response));
+ assertEquals(encoding.toUpperCase(), getCharset(response));
+
+ Document doc = StaxUtils.read(response.getEntity().getContent());
+ 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 testGetServiceList() throws Exception {
- ServletUnitClient client = newClient();
- client.setExceptionsThrownOnErrorStatus(false);
-
- WebResponse res = client.getResponse(CONTEXT_URL + "/services");
-
-
- WebLink[] links = res.getLinks();
- assertEquals("Wrong number of service links", 6, links.length);
-
- Set<String> links2 = new HashSet<>();
- for (WebLink l : links) {
- links2.add(l.getURLString());
- }
-
- assertTrue(links2.contains(CONTEXT_URL + "/services/greeter?wsdl"));
- assertTrue(links2.contains(CONTEXT_URL + "/services/greeter2?wsdl"));
- assertTrue(links2.contains("http://cxf.apache.org/MyGreeter?wsdl"));
- assertEquals("text/html", res.getContentType());
-
- res = client.getResponse(CONTEXT_URL + "/services/");
-
-
- links = res.getLinks();
- links2.clear();
- for (WebLink l : links) {
- links2.add(l.getURLString());
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet method = new HttpGet(uri("/services"));
+
+ try (CloseableHttpResponse res = client.execute(method)) {
+ HTMLDocumentImpl doc = parse(res.getEntity().getContent());
+ Collection<HTMLAnchorElementImpl> links = getLinks(doc);
+ assertEquals("Wrong number of service links", 6, links.size());
+
+ Set<String> links2 = new HashSet<>();
+ for (HTMLAnchorElementImpl l : links) {
+ links2.add(l.getHref());
+ }
+
+ assertTrue(links2.contains(uri("/services/greeter?wsdl")));
+ assertTrue(links2.contains(uri("/services/greeter2?wsdl")));
+ assertTrue(links2.contains("http://cxf.apache.org/MyGreeter?wsdl"));
+
+ assertEquals("text/html", getContentType(res));
+ }
+
+ try (CloseableHttpResponse res = client.execute(method)) {
+ HTMLDocumentImpl doc = parse(res.getEntity().getContent());
+ Collection<HTMLAnchorElementImpl> links = getLinks(doc);
+
+ Set<String> links2 = new HashSet<>();
+ for (HTMLAnchorElementImpl l : links) {
+ links2.add(l.getHref());
+ }
+
+ assertEquals("Wrong number of service links", 6, links.size());
+ assertTrue(links2.contains(uri("/services/greeter?wsdl")));
+ assertTrue(links2.contains(uri("/services/greeter2?wsdl")));
+ assertTrue(links2.contains("http://cxf.apache.org/MyGreeter?wsdl"));
+
+ assertEquals("text/html", getContentType(res));
+
+ // Ensure that the Bus is available for people doing an Endpoint.publish() or similar.
+ assertNotNull(BusFactory.getDefaultBus(false));
+ }
}
-
- assertEquals("Wrong number of service links", 6, links.length);
- assertTrue(links2.contains(CONTEXT_URL + "/services/greeter?wsdl"));
- assertTrue(links2.contains(CONTEXT_URL + "/services/greeter2?wsdl"));
- assertTrue(links2.contains("http://cxf.apache.org/MyGreeter?wsdl"));
-
- assertEquals("text/html", res.getContentType());
-
-
- // Ensure that the Bus is available for people doing an Endpoint.publish() or similar.
- assertNotNull(BusFactory.getDefaultBus(false));
}
@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"));
-
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet method = new HttpGet(uri("/services?formatted=false"));
+
+ try (CloseableHttpResponse res = client.execute(method)) {
+ final String content = IOUtils.readStringFromStream(res.getEntity().getContent());
+ assertTrue(content.contains(uri("/services/greeter3")));
+ assertTrue(content.contains(uri("/services/greeter2")));
+ assertTrue(content.contains(uri("/services/greeter")));
+ }
+ }
}
@Test
public void testServiceListWithLoopAddress() throws Exception {
- ServletUnitClient client = newClient();
- client.setExceptionsThrownOnErrorStatus(false);
-
- WebResponse res = client.getResponse(CONTEXT_URL + "/services");
-
- 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"));
- WebRequest req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter?wsdl");
- res = client.getResponse(req);
- req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter2?wsdl");
- res = client.getResponse(req);
- req = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/greeter3?wsdl");
- res = client.getResponse(req);
- String loopAddr = "http://127.0.0.1/mycontext";
- res = client.getResponse(loopAddr + "/services");
- assertFalse(res.getText().contains(
- "http://127.0.0.1/mycontext/serviceshttp://localhost/mycontext/services/greeter"));
-
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet method = new HttpGet(uri("/services"));
+
+ try (CloseableHttpResponse res = client.execute(method)) {
+ final String content = IOUtils.readStringFromStream(res.getEntity().getContent());
+ assertTrue(content.contains(uri("/services/greeter3")));
+ assertTrue(content.contains(uri("/services/greeter2")));
+ assertTrue(content.contains(uri("/services/greeter")));
+ }
+
+ final HttpGet greeter = new HttpGet(uri("/services/greeter?wsdl"));
+ try (CloseableHttpResponse res = client.execute(greeter)) {
+ assertThat(res.getStatusLine().getStatusCode(), equalTo(200));
+ }
+
+ final HttpGet greeter2 = new HttpGet(uri("/services/greeter2?wsdl"));
+ try (CloseableHttpResponse res = client.execute(greeter2)) {
+ assertThat(res.getStatusLine().getStatusCode(), equalTo(200));
+ }
+
+ final HttpGet greeter3 = new HttpGet(uri("/services/greeter3?wsdl"));
+ try (CloseableHttpResponse res = client.execute(greeter3)) {
+ assertThat(res.getStatusLine().getStatusCode(), equalTo(200));
+ }
+
+ final HttpGet loopback = new HttpGet("http://127.0.0.1:" + getPort() + "/mycontext/services");
+ try (CloseableHttpResponse res = client.execute(loopback)) {
+ final String content = IOUtils.readStringFromStream(res.getEntity().getContent());
+ assertTrue(content.contains("http://127.0.0.1:" + getPort() + "/mycontext/services"));
+ }
+ }
}
@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);
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet method = new HttpGet(uri("/services/greeter?wsdl"));
+
+ try (CloseableHttpResponse res = client.execute(method)) {
+ assertEquals(200, res.getStatusLine().getStatusCode());
+ assertEquals("text/xml", getContentType(res));
+ Document doc = StaxUtils.read(res.getEntity().getContent());
+ assertNotNull(doc);
+
+ assertValid("//wsdl:operation[@name='greetMe']", doc);
+ assertValid("//wsdlsoap:address[@location='" + uri("/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);
-
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet method = new HttpGet(uri("/services/greeter5?wsdl"));
+
+ try (CloseableHttpResponse res = client.execute(method)) {
+ assertEquals(200, res.getStatusLine().getStatusCode());
+ assertEquals("text/xml", getContentType(res));
+ Document doc = StaxUtils.read(res.getEntity().getContent());
+ 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
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);
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet wsdl = new HttpGet(uri("/services/greeter3?wsdl"));
+
+ try (CloseableHttpResponse res = client.execute(wsdl)) {
+ assertEquals(200, res.getStatusLine().getStatusCode());
+ assertEquals("text/xml", getContentType(res));
+ Document doc = StaxUtils.read(res.getEntity().getContent());
+ assertNotNull(doc);
+
+ assertXPathEquals("//xsd:include/@schemaLocation",
+ uri("/services/greeter3?xsd=hello_world_includes2.xsd"),
+ doc.getDocumentElement());
+ }
+
+ final HttpGet xsd = new HttpGet(uri("/services/greeter3?xsd=hello_world_includes2.xsd"));
+ try (CloseableHttpResponse res = client.execute(xsd)) {
+ assertEquals(200, res.getStatusLine().getStatusCode());
+ assertEquals("text/xml", getContentType(res));
+ Document doc = StaxUtils.read(res.getEntity().getContent());
+ assertNotNull(doc);
+
+ assertValid("//xsd:complexType[@name='ErrorCode']", 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;
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet method = new HttpGet(uri("/services/greeter2?wsdl"));
+
+ try (CloseableHttpResponse res = client.execute(method)) {
+ assertEquals(200, res.getStatusLine().getStatusCode());
+ assertEquals("text/xml", getContentType(res));
+
+ Document doc = StaxUtils.read(res.getEntity().getContent());
+ 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);
}
}
- assertTrue(found);
}
@Test
public void testInvalidServiceUrl() throws Exception {
- ServletUnitClient client = newClient();
- client.setExceptionsThrownOnErrorStatus(false);
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet method = new HttpGet(uri("/services/NoSuchService"));
- WebResponse res = client.getResponse(CONTEXT_URL + "/services/NoSuchService");
- assertEquals(404, res.getResponseCode());
- assertEquals("text/html", res.getContentType());
+ try (CloseableHttpResponse res = client.execute(method)) {
+ assertEquals(404, res.getStatusLine().getStatusCode());
+ assertEquals("text/html", getContentType(res));
+ }
+ }
}
@Test
public void testServiceWsdlNotFound() throws Exception {
- WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/NoSuchService?wsdl");
-
- expectErrorCode(req, 404, "Response code 404 required for invalid WSDL url.");
+ final HttpGet method = new HttpGet(uri("/services/NoSuchService?wsdl"));
+ expectErrorCode(method, 404, "Response code 404 required for invalid WSDL url.");
}
@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\">"));
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet wsdl = new HttpGet(uri("/services/greeter?wsdl"));
+ try (CloseableHttpResponse res = client.execute(wsdl)) {
+ assertEquals(200, res.getStatusLine().getStatusCode());
+ final String text = IOUtils.readStringFromStream(res.getEntity().getContent());
+ assertEquals("text/xml", getContentType(res));
+ assertTrue(text.contains(uri("/services/greeter?wsdl=test_import.xsd")));
+ }
+
+ final HttpGet xsd = new HttpGet(uri("/services/greeter?wsdl=test_import.xsd"));
+ try (CloseableHttpResponse res = client.execute(xsd)) {
+ assertEquals(200, res.getStatusLine().getStatusCode());
+ final String text = IOUtils.readStringFromStream(res.getEntity().getContent());
+
+ assertEquals("text/xml", getContentType(res));
+ assertTrue("the xsd should contain the completType SimpleStruct",
+ text.contains("<complexType name=\"SimpleStruct\">"));
+ }
+ }
}
-
@Test
public void testGetBinding() throws Exception {
- Endpoint ep = Endpoint.create("http://schemas.xmlsoap.org/wsdl/soap/http", new HelloImpl());
- assertTrue(ep.getBinding() instanceof SOAPBinding);
+ final Bus bus = BusFactory.getDefaultBus();
+ try {
+ BusFactory.setDefaultBus(null);
+ Endpoint ep = Endpoint.create("http://schemas.xmlsoap.org/wsdl/soap/http", new HelloImpl());
+ assertTrue(ep.getBinding() instanceof SOAPBinding);
+ } finally {
+ BusFactory.setDefaultBus(bus);
+ }
}
@WebService(name = "Hello", portName = "HelloPort",
@@ -334,4 +369,9 @@ public class CXFServletTest extends AbstractServletTest {
}
-}
\ No newline at end of file
+
+ @Override
+ protected int getPort() {
+ return EmbeddedJettyServer.PORT;
+ }
+}
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/ErrorContextSerletTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/ErrorContextSerletTest.java
deleted file mode 100644
index 37402b1047..0000000000
--- a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/ErrorContextSerletTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.systest.servlet;
-
-import com.meterware.servletunit.ServletRunner;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusException;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.fail;
-
-public class ErrorContextSerletTest extends AbstractServletTest {
- @Override
- protected String getConfiguration() {
- return "/org/apache/cxf/systest/servlet/web-spring-error.xml";
- }
-
- @Override
- protected Bus createBus() throws BusException {
- // don't set up the bus, let the servlet do it
- return null;
- }
-
- @Before
- public void setUp() throws Exception {
- // do nothing here
-
- }
-
- @Test
- public void testInvoke() throws Exception {
- 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 (org.springframework.beans.FatalBeanException ex) {
- // expected
- }
- }
-
-
-}
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/ErrorContextServletTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/ErrorContextServletTest.java
new file mode 100644
index 0000000000..d98f5c1bca
--- /dev/null
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/ErrorContextServletTest.java
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.servlet;
+
+
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class ErrorContextServletTest extends AbstractServletTest {
+ @Ignore
+ public static class EmbeddedJettyServer extends AbstractJettyServer {
+ public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class);
+
+ public EmbeddedJettyServer() {
+ super("/org/apache/cxf/systest/servlet/web-spring-error.xml", "/", CONTEXT, PORT);
+ }
+ }
+
+ @BeforeClass
+ public static void startServers() throws Exception {
+ AbstractResourceInfo.clearAllMaps();
+ assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true));
+ createStaticBus();
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ stopAllServers();
+ }
+
+ @Test
+ public void testInvoke() throws Exception {
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet method = new HttpGet(uri("/services/greeter?wsdl"));
+ // The Spring context contains errors, the service should not be available
+ try (CloseableHttpResponse res = client.execute(method)) {
+ assertEquals(503, res.getStatusLine().getStatusCode());
+ }
+ }
+ }
+
+ @Override
+ protected int getPort() {
+ return EmbeddedJettyServer.PORT;
+ }
+}
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/ExternalServicesServletTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/ExternalServicesServletTest.java
index e3afcea634..7f848b9bf8 100644
--- a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/ExternalServicesServletTest.java
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/ExternalServicesServletTest.java
@@ -20,21 +20,26 @@ package org.apache.cxf.systest.servlet;
import java.nio.charset.StandardCharsets;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.w3c.dom.Document;
-import com.meterware.httpunit.PostMethodWebRequest;
-import com.meterware.httpunit.WebLink;
-import com.meterware.httpunit.WebRequest;
-import com.meterware.httpunit.WebResponse;
-import com.meterware.servletunit.ServletUnitClient;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusException;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
import org.apache.cxf.staxutils.StaxUtils;
-
+import org.apache.html.dom.HTMLAnchorElementImpl;
+import org.apache.html.dom.HTMLDocumentImpl;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -42,68 +47,76 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class ExternalServicesServletTest extends AbstractServletTest {
- static final String FORCED_BASE_ADDRESS
- = "http://localhost/somewhere";
- @Override
- protected Bus createBus() throws BusException {
- return null;
+ private static final String FORCED_BASE_ADDRESS = "http://localhost/somewhere";
+
+ @Ignore
+ public static class EmbeddedJettyServer extends AbstractJettyServer {
+ public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class);
+
+ public EmbeddedJettyServer() {
+ super("/org/apache/cxf/systest/servlet/web-external.xml", "/", CONTEXT, PORT);
+ }
}
- @Override
- protected String getConfiguration() {
- return "/org/apache/cxf/systest/servlet/web-external.xml";
+ @BeforeClass
+ public static void startServers() throws Exception {
+ AbstractResourceInfo.clearAllMaps();
+ assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true));
+ createStaticBus();
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ stopAllServers();
}
@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", 6, links.length);
-
- Set<String> links2 = new HashSet<>();
- for (WebLink l : links) {
- links2.add(l.getURLString());
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet method = new HttpGet(uri("/"));
+
+ try (CloseableHttpResponse res = client.execute(method)) {
+ HTMLDocumentImpl doc = parse(res.getEntity().getContent());
+ Collection<HTMLAnchorElementImpl> links = getLinks(doc);
+ assertEquals("Wrong number of service links", 6, links.size());
+
+ Set<String> links2 = new HashSet<>();
+ for (HTMLAnchorElementImpl l : links) {
+ links2.add(l.getHref());
+ }
+ assertTrue(links2.contains(FORCED_BASE_ADDRESS + "/greeter?wsdl"));
+ assertTrue(links2.contains(FORCED_BASE_ADDRESS + "/greeter2?wsdl"));
+
+ assertEquals("text/html", getContentType(res));
+ }
}
- assertTrue(links2.contains(FORCED_BASE_ADDRESS + "/greeter?wsdl"));
- assertTrue(links2.contains(FORCED_BASE_ADDRESS + "/greeter2?wsdl"));
-
- assertEquals("text/html", res.getContentType());
-
- //HTTPUnit do not support require url with ""
- /*
- res = client.getResponse(CONTEXT_URL);
- links = res.getLinks();
- assertEquals("There should get two links for the services", 1, links.length);
- assertEquals(CONTEXT_URL + "/greeter?wsdl", links[0].getURLString());
- assertEquals(CONTEXT_URL + "/greeter2?wsdl", links[1].getURLString());
- 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");
+ try (CloseableHttpClient client = newClient()) {
+ final HttpPost method = new HttpPost(uri("/greeter"));
+
+ method.setEntity(new InputStreamEntity(getClass().getResourceAsStream("GreeterMessage.xml"),
+ ContentType.create("text/xml", StandardCharsets.UTF_8)));
+
+ try (CloseableHttpResponse response = client.execute(method)) {
+ assertEquals("text/xml", getContentType(response));
+ assertEquals(StandardCharsets.UTF_8.name(), getCharset(response));
+
+ Document doc = StaxUtils.read(response.getEntity().getContent());
+ assertNotNull(doc);
+
+ addNamespace("h", "http://apache.org/hello_world_soap_http/types");
+
+ assertValid("/s:Envelope/s:Body", doc);
+ assertValid("//h:sayHiResponse", doc);
+ }
+ }
+ }
- assertValid("/s:Envelope/s:Body", doc);
- assertValid("//h:sayHiResponse", doc);
+ @Override
+ protected int getPort() {
+ return EmbeddedJettyServer.PORT;
}
-}
\ No newline at end of file
+}
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/GetMethodQueryWebRequest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/GetMethodQueryWebRequest.java
deleted file mode 100644
index dc54536597..0000000000
--- a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/GetMethodQueryWebRequest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.systest.servlet;
-
-import com.meterware.httpunit.GetMethodWebRequest;
-
-//Customer WebRequest for sending the "http://localhost/xxx?wsdl" request
-public class GetMethodQueryWebRequest extends GetMethodWebRequest {
- private String urlString;
-
- public GetMethodQueryWebRequest(String urlStr) {
- super(urlStr);
- urlString = urlStr;
- }
-
- public String getQueryString() {
- int pos = urlString.indexOf('?');
- if (pos > 0) {
- return urlString.substring(pos + 1);
- }
- return "";
- }
-
-
-
-}
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/JaxRsServletTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/JaxRsServletTest.java
deleted file mode 100644
index df0dbbe66f..0000000000
--- a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/JaxRsServletTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.systest.servlet;
-
-import java.io.InputStream;
-
-import com.meterware.httpunit.WebRequest;
-import com.meterware.httpunit.WebResponse;
-import com.meterware.servletunit.ServletUnitClient;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusException;
-import org.apache.cxf.helpers.IOUtils;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-
-
-public class JaxRsServletTest extends AbstractServletTest {
-
-
- @Override
- protected String getConfiguration() {
- return "/org/apache/cxf/systest/servlet/web-jaxrs.xml";
- }
-
- @Override
- protected Bus createBus() throws BusException {
- // don't set up the bus, let the servlet do it
- return null;
- }
-
- @org.junit.Ignore // this doesn't work yet
- @Test
- public void testGetThatBook123() throws Exception {
- testInvokingBookService("/jaxrs/bookstorestorage/thosebooks/123");
- }
-
- 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 String getStringFromInputStream(InputStream in) throws Exception {
- return IOUtils.toString(in);
- }
-}
\ No newline at end of file
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/JsFrontEndServletTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/JsFrontEndServletTest.java
index 1df48422a6..9212e13869 100644
--- a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/JsFrontEndServletTest.java
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/JsFrontEndServletTest.java
@@ -18,47 +18,76 @@
*/
package org.apache.cxf.systest.servlet;
-import org.w3c.dom.Document;
+import java.nio.charset.StandardCharsets;
-import com.meterware.httpunit.PostMethodWebRequest;
-import com.meterware.httpunit.WebRequest;
-import com.meterware.httpunit.WebResponse;
+import org.w3c.dom.Document;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
import org.apache.cxf.staxutils.StaxUtils;
-
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
public class JsFrontEndServletTest extends AbstractServletTest {
+ @Ignore
+ public static class EmbeddedJettyServer extends AbstractJettyServer {
+ public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class);
- protected String getConfiguration() {
- return "/org/apache/cxf/systest/servlet/web-js.xml";
+ public EmbeddedJettyServer() {
+ super("/org/apache/cxf/systest/servlet/web-js.xml", "/", CONTEXT, PORT);
+ }
}
- @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);
+ @BeforeClass
+ public static void startServers() throws Exception {
+ AbstractResourceInfo.clearAllMaps();
+ assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true));
+ createStaticBus();
+ }
+ @AfterClass
+ public static void tearDown() throws Exception {
+ stopAllServers();
}
+ @Test
+ public void testPostInvokeServices() throws Exception {
+ try (CloseableHttpClient client = newClient()) {
+ final HttpPost method = new HttpPost(uri("/services/Greeter"));
+
+ method.setEntity(new InputStreamEntity(getClass().getResourceAsStream("GreeterMessage.xml"),
+ ContentType.create("text/xml", StandardCharsets.UTF_8)));
+
+ try (CloseableHttpResponse response = client.execute(method)) {
+
+ assertEquals("text/xml", getContentType(response));
+ assertEquals(StandardCharsets.UTF_8.name(), getCharset(response));
+
+ Document doc = StaxUtils.read(response.getEntity().getContent());
+ 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);
+ }
+ }
+ }
-}
\ No newline at end of file
+ @Override
+ protected int getPort() {
+ return EmbeddedJettyServer.PORT;
+ }
+}
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
index 507fda5d2d..f793358734 100644
--- a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/NoSpringServletClientTest.java
@@ -20,23 +20,25 @@ package org.apache.cxf.systest.servlet;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.URL;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.xml.namespace.QName;
-import com.meterware.httpunit.WebConversation;
-import com.meterware.httpunit.WebLink;
-import com.meterware.httpunit.WebResponse;
-
import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.endpoint.ServerRegistry;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
-import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.apache.hello_world_soap_http.Greeter;
import org.apache.hello_world_soap_http.SOAPService;
+import org.apache.html.dom.HTMLAnchorElementImpl;
+import org.apache.html.dom.HTMLDocumentImpl;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -47,12 +49,13 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-public class NoSpringServletClientTest extends AbstractBusClientServerTestBase {
+public class NoSpringServletClientTest extends AbstractServletTest {
private static final String PORT = NoSpringServletServer.PORT;
private static Bus serverBus;
private static NoSpringServletServer server;
private final QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapPort");
private final String serviceURL = "http://localhost:" + PORT + "/soap/";
+
@BeforeClass
public static void startServers() throws Exception {
server = new NoSpringServletServer();
@@ -129,17 +132,28 @@ public class NoSpringServletClientTest extends AbstractBusClientServerTestBase {
@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());
+ try (CloseableHttpClient client = HttpClients.createDefault()) {
+ final HttpGet method = new HttpGet(serviceURL + "/services");
+
+ try (CloseableHttpResponse res = client.execute(method)) {
+ HTMLDocumentImpl doc = parse(res.getEntity().getContent());
+ Collection<HTMLAnchorElementImpl> links = getLinks(doc);
+
+ Set<String> s = new HashSet<>();
+ for (HTMLAnchorElementImpl l : links) {
+ s.add(l.getHref());
+ }
+ assertEquals("There should be 3 links for the service", 3, links.size());
+ assertTrue(s.contains(serviceURL + "Greeter?wsdl"));
+ assertTrue(s.contains(serviceURL + "Hello?wsdl"));
+ assertTrue(s.contains(serviceURL + "?wsdl"));
+ assertEquals("text/html", getContentType(res));
+ }
}
- 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());
+ }
+
+ @Override
+ protected int getPort() {
+ return Integer.parseInt(NoSpringServletServer.PORT);
}
}
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringAutoPublishServletTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringAutoPublishServletTest.java
index 81403607c6..8209ab6c3b 100644
--- a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringAutoPublishServletTest.java
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringAutoPublishServletTest.java
@@ -18,17 +18,23 @@
*/
package org.apache.cxf.systest.servlet;
-import org.w3c.dom.Document;
+import java.nio.charset.StandardCharsets;
-import com.meterware.httpunit.PostMethodWebRequest;
-import com.meterware.httpunit.WebRequest;
-import com.meterware.httpunit.WebResponse;
-import com.meterware.servletunit.ServletUnitClient;
+import org.w3c.dom.Document;
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusException;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
import org.apache.cxf.staxutils.StaxUtils;
-
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -36,78 +42,93 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class SpringAutoPublishServletTest extends AbstractServletTest {
- @Override
- protected String getConfiguration() {
- return "/org/apache/cxf/systest/servlet/web-spring-auto-launch.xml";
+ @Ignore
+ public static class EmbeddedJettyServer extends AbstractJettyServer {
+ public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class);
+
+ public EmbeddedJettyServer() {
+ super("/org/apache/cxf/systest/servlet/web-spring-auto-launch.xml", "/", CONTEXT, PORT);
+ }
}
- @Override
- protected Bus createBus() throws BusException {
- // don't set up the bus, let the servlet do it
- return null;
+ @BeforeClass
+ public static void startServers() throws Exception {
+ AbstractResourceInfo.clearAllMaps();
+ assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true));
+ createStaticBus();
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ stopAllServers();
}
@Test
public void testInvokingSpringBeans() throws Exception {
+ final HttpPost method = new HttpPost(uri("/services/SOAPService"));
- WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/SOAPService",
- getClass().getResourceAsStream("GreeterMessage.xml"),
- "text/xml; charset=utf-8");
+ method.setEntity(new InputStreamEntity(getClass().getResourceAsStream("GreeterMessage.xml"),
+ ContentType.create("text/xml", StandardCharsets.UTF_8)));
- invokingEndpoint(req);
+ invokingEndpoint(method);
- req = new PostMethodWebRequest(CONTEXT_URL + "/services/DerivedGreeterService",
- getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=utf-8");
+ final HttpPost method2 = new HttpPost(uri("/services/DerivedGreeterService"));
- invokingEndpoint(req);
+ method2.setEntity(new InputStreamEntity(getClass().getResourceAsStream("GreeterMessage.xml"),
+ ContentType.create("text/xml", StandardCharsets.UTF_8)));
+
+ invokingEndpoint(method2);
}
- 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(HttpUriRequest method) throws Exception {
+ try (CloseableHttpClient client = newClient()) {
+ try (CloseableHttpResponse response = client.execute(method)) {
+ assertEquals("text/xml", getContentType(response));
+ assertTrue("utf-8".equalsIgnoreCase(getCharset(response)));
+
+ Document doc = StaxUtils.read(response.getEntity().getContent());
+ 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/SOAPService?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/SOAPService']", doc);
-
- req =
- new GetMethodQueryWebRequest(CONTEXT_URL + "/services/DerivedGreeterService?wsdl");
- res = client.getResponse(req);
- assertEquals(200, res.getResponseCode());
- assertEquals("text/xml", res.getContentType());
-
- doc = StaxUtils.read(res.getInputStream());
- assertNotNull(doc);
-
- assertValid("//wsdl:operation[@name='greetMe']", doc);
- assertValid("//wsdlsoap:address"
- + "[@location='http://localhost/mycontext/services/DerivedGreeterService']",
- doc);
-
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet greeter = new HttpGet(uri("/services/SOAPService?wsdl"));
+ try (CloseableHttpResponse res = client.execute(greeter)) {
+ assertEquals(200, res.getStatusLine().getStatusCode());
+ assertEquals("text/xml", getContentType(res));
+
+ Document doc = StaxUtils.read(res.getEntity().getContent());
+ assertNotNull(doc);
+
+ assertValid("//wsdl:operation[@name='greetMe']", doc);
+ assertValid("//wsdlsoap:address[@location='" + uri("/services/SOAPService") + "']", doc);
+ }
+
+ final HttpGet derived = new HttpGet(uri("/services/DerivedGreeterService?wsdl"));
+ try (CloseableHttpResponse res = client.execute(derived)) {
+ assertEquals(200, res.getStatusLine().getStatusCode());
+ assertEquals("text/xml", getContentType(res));
+
+ Document doc = StaxUtils.read(res.getEntity().getContent());
+ assertNotNull(doc);
+
+ assertValid("//wsdl:operation[@name='greetMe']", doc);
+ assertValid("//wsdlsoap:address"
+ + "[@location='" + uri("/services/DerivedGreeterService") + "']",
+ doc);
+ }
+ }
+ }
+
+ @Override
+ protected int getPort() {
+ return EmbeddedJettyServer.PORT;
}
-}
\ No newline at end of file
+}
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringServletContextTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringServletContextTest.java
index 720a407383..47473bd41e 100644
--- a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringServletContextTest.java
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringServletContextTest.java
@@ -23,27 +23,39 @@ import java.util.Arrays;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
-import com.meterware.httpunit.WebRequest;
-import com.meterware.httpunit.WebResponse;
-import com.meterware.servletunit.ServletUnitClient;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusException;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertTrue;
public class SpringServletContextTest extends AbstractServletTest {
+
+ @Ignore
+ public static class EmbeddedJettyServer extends AbstractJettyServer {
+ public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class);
+
+ public EmbeddedJettyServer() {
+ super("/org/apache/cxf/systest/servlet/web-spring-context.xml", "/", CONTEXT, PORT);
+ }
+ }
+
@Configuration
public static class AppConfig {
@Bean(destroyMethod = "shutdown")
@@ -77,26 +89,33 @@ public class SpringServletContextTest extends AbstractServletTest {
}
}
- @Override
- protected String getConfiguration() {
- return "/org/apache/cxf/systest/servlet/web-spring-context.xml";
+ @BeforeClass
+ public static void startServers() throws Exception {
+ AbstractResourceInfo.clearAllMaps();
+ assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true));
+ createStaticBus();
}
- @Override
- protected Bus createBus() throws BusException {
- // don't set up the bus, let the servlet do it
- return null;
+ @AfterClass
+ public static void tearDown() throws Exception {
+ stopAllServers();
}
@Test
public void testContextRefresh() throws Exception {
- ServletUnitClient client = newClient();
- client.setExceptionsThrownOnErrorStatus(true);
-
- for (int i = 0; i < 5; ++i) {
- final WebRequest request = new GetMethodQueryWebRequest(CONTEXT_URL + "/services/context/refresh");
- final WebResponse response = client.getResponse(request);
- assertThat(response.getResponseCode(), equalTo(204));
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet method = new HttpGet(uri("/services/context/refresh"));
+
+ for (int i = 0; i < 5; ++i) {
+ try (CloseableHttpResponse response = client.execute(method)) {
+ assertThat(response.getStatusLine().getStatusCode(), equalTo(204));
+ }
+ }
}
}
-}
\ No newline at end of file
+
+ @Override
+ protected int getPort() {
+ return EmbeddedJettyServer.PORT;
+ }
+}
diff --git a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java
index 02dcd9dd51..440d0ed872 100644
--- a/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java
+++ b/systests/transports/src/test/java/org/apache/cxf/systest/servlet/SpringServletTest.java
@@ -18,126 +18,141 @@
*/
package org.apache.cxf.systest.servlet;
+import java.nio.charset.StandardCharsets;
+
import javax.xml.ws.Endpoint;
import org.w3c.dom.Document;
-import com.meterware.httpunit.HttpNotFoundException;
-import com.meterware.httpunit.PostMethodWebRequest;
-import com.meterware.httpunit.WebRequest;
-import com.meterware.httpunit.WebResponse;
-import com.meterware.servletunit.ServletUnitClient;
-
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusException;
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
import org.apache.cxf.staxutils.StaxUtils;
-
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
public class SpringServletTest extends AbstractServletTest {
- @Override
- protected String getConfiguration() {
- return "/org/apache/cxf/systest/servlet/web-spring.xml";
+ @Ignore
+ public static class EmbeddedJettyServer extends AbstractJettyServer {
+ public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class);
+
+ public EmbeddedJettyServer() {
+ super("/org/apache/cxf/systest/servlet/web-spring.xml", "/", CONTEXT, PORT);
+ }
}
- @Override
- protected Bus createBus() throws BusException {
- // don't set up the bus, let the servlet do it
- return null;
+ @BeforeClass
+ public static void startServers() throws Exception {
+ AbstractResourceInfo.clearAllMaps();
+ assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true));
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ stopAllServers();
}
@Test
public void testInvokingSpringBeans() throws Exception {
+ final HttpPost method = new HttpPost(uri("/services/Greeter"));
- WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/Greeter",
- getClass().getResourceAsStream("GreeterMessage.xml"),
- "text/xml; charset=utf-8");
-
- invokingEndpoint(req);
+ method.setEntity(new InputStreamEntity(getClass().getResourceAsStream("GreeterMessage.xml"),
+ ContentType.create("text/xml", StandardCharsets.UTF_8)));
- req = new PostMethodWebRequest(CONTEXT_URL + "/services/Greeter1",
- getClass().getResourceAsStream("GreeterMessage.xml"), "text/xml; charset=utf-8");
-
- invokingEndpoint(req);
- }
+ invokingEndpoint(method);
- public void invokingEndpoint(WebRequest req) throws Exception {
+ final HttpPost method2 = new HttpPost(uri("/services/Greeter1"));
- WebResponse response = newClient().getResponse(req);
- assertEquals("text/xml", response.getContentType());
- assertTrue("utf-8".equalsIgnoreCase(response.getCharacterSet()));
+ method2.setEntity(new InputStreamEntity(getClass().getResourceAsStream("GreeterMessage.xml"),
+ ContentType.create("text/xml", StandardCharsets.UTF_8)));
- 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);
+ invokingEndpoint(method2);
}
+ public void invokingEndpoint(HttpUriRequest method) throws Exception {
+ try (CloseableHttpClient client = newClient()) {
+ try (CloseableHttpResponse response = client.execute(method)) {
+ assertEquals("text/xml", getContentType(response));
+ assertTrue("utf-8".equalsIgnoreCase(getCharset(response)));
+
+ Document doc = StaxUtils.read(response.getEntity().getContent());
+ 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);
-
- req =
- new GetMethodQueryWebRequest(CONTEXT_URL + "/services/Greeter2?wsdl");
- res = client.getResponse(req);
- assertEquals(200, res.getResponseCode());
- assertEquals("text/xml", res.getContentType());
-
- doc = StaxUtils.read(res.getInputStream());
- assertNotNull(doc);
-
- assertValid("//wsdl:operation[@name='greetMe']", doc);
- assertValid("//wsdlsoap:address[@location='http://cxf.apache.org/Greeter']", doc);
-
- Endpoint.publish("/services/Greeter3", new org.apache.hello_world_soap_http.GreeterImpl());
- req =
- new GetMethodQueryWebRequest(CONTEXT_URL + "/services/Greeter3?wsdl");
- res = client.getResponse(req);
- assertEquals(200, res.getResponseCode());
- assertEquals("text/xml", res.getContentType());
-
- doc = StaxUtils.read(res.getInputStream());
- assertNotNull(doc);
-
- assertValid("//wsdl:operation[@name='greetMe']", doc);
- assertValid("//wsdlsoap:address[@location='" + CONTEXT_URL + "/services/Greeter3']", doc);
-
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet greeter = new HttpGet(uri("/services/Greeter?wsdl"));
+ try (CloseableHttpResponse res = client.execute(greeter)) {
+ assertEquals(200, res.getStatusLine().getStatusCode());
+ assertEquals("text/xml", getContentType(res));
+
+ Document doc = StaxUtils.read(res.getEntity().getContent());
+ assertNotNull(doc);
+
+ assertValid("//wsdl:operation[@name='greetMe']", doc);
+ assertValid("//wsdlsoap:address[@location='" + uri("/services/Greeter") + "']", doc);
+ }
+
+ final HttpGet greeter2 = new HttpGet(uri("/services/Greeter2?wsdl"));
+ try (CloseableHttpResponse res = client.execute(greeter2)) {
+ assertEquals(200, res.getStatusLine().getStatusCode());
+ assertEquals("text/xml", getContentType(res));
+
+ Document doc = StaxUtils.read(res.getEntity().getContent());
+ assertNotNull(doc);
+
+ assertValid("//wsdl:operation[@name='greetMe']", doc);
+ assertValid("//wsdlsoap:address[@location='http://cxf.apache.org/Greeter']", doc);
+
+ Endpoint.publish("/services/Greeter3", new org.apache.hello_world_soap_http.GreeterImpl());
+ }
+
+ final HttpGet greeter3 = new HttpGet(uri("/services/Greeter3?wsdl"));
+ try (CloseableHttpResponse res = client.execute(greeter3)) {
+ assertEquals(200, res.getStatusLine().getStatusCode());
+ assertEquals("text/xml", getContentType(res));
+
+ Document doc = StaxUtils.read(res.getEntity().getContent());
+ assertNotNull(doc);
+
+ assertValid("//wsdl:operation[@name='greetMe']", doc);
+ assertValid("//wsdlsoap:address[@location='" + uri("/services/Greeter3") + "']", doc);
+ }
+ }
}
@Test
public void testIgnoreServiceList() throws Exception {
- ServletUnitClient client = newClient();
- client.setExceptionsThrownOnErrorStatus(true);
-
- WebRequest req =
- new GetMethodQueryWebRequest(CONTEXT_URL + "/services/");
- try {
- client.getResponse(req);
- fail();
- } catch (HttpNotFoundException ex) {
- // expected
+ try (CloseableHttpClient client = newClient()) {
+ final HttpGet greeter = new HttpGet(uri("/services"));
+
+ try (CloseableHttpResponse res = client.execute(greeter)) {
+ assertEquals(404, res.getStatusLine().getStatusCode());
+ }
}
}
-}
\ No newline at end of file
+
+ @Override
+ protected int getPort() {
+ return EmbeddedJettyServer.PORT;
+ }
+}