Author: matthieu
Date: Fri Dec 11 10:04:37 2015
New Revision: 1719301
URL: http://svn.apache.org/viewvc?rev=1719301&view=rev
Log:
JAMES-1639 Handle xml configuration for spring integration
Added:
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/ConfigurationException.java
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/JettyHttpServerFactory.java
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/Bad400.java
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/JettyHttpServerFactoryTest.java
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/Ok200.java
james/project/trunk/server/container/jetty/src/test/resources/
james/project/trunk/server/container/jetty/src/test/resources/conflictingport.xml
james/project/trunk/server/container/jetty/src/test/resources/emptymappingconfiguration.xml
james/project/trunk/server/container/jetty/src/test/resources/emptyservletname.xml
james/project/trunk/server/container/jetty/src/test/resources/httpserver.xml
james/project/trunk/server/container/jetty/src/test/resources/unavailableservletname.xml
Modified:
james/project/trunk/server/container/jetty/pom.xml
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/Configuration.java
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/JettyHttpServer.java
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/ConfigurationTest.java
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/JettyHttpServerTest.java
Modified: james/project/trunk/server/container/jetty/pom.xml
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/pom.xml?rev=1719301&r1=1719300&r2=1719301&view=diff
==============================================================================
--- james/project/trunk/server/container/jetty/pom.xml (original)
+++ james/project/trunk/server/container/jetty/pom.xml Fri Dec 11 10:04:37 2015
@@ -138,6 +138,10 @@
<version>2.6.0</version>
</dependency>
<dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Modified:
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/Configuration.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/Configuration.java?rev=1719301&r1=1719300&r2=1719301&view=diff
==============================================================================
---
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/Configuration.java
(original)
+++
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/Configuration.java
Fri Dec 11 10:04:37 2015
@@ -18,6 +18,7 @@
****************************************************************/
package org.apache.james.http.jetty;
+import java.util.Objects;
import java.util.Optional;
import javax.servlet.Servlet;
@@ -40,7 +41,7 @@ public class Configuration {
private static final Range<Integer> VALID_PORT_RANGE = Range.closed(1,
65535);
- private ImmutableMap.Builder<String, Servlet> mappings;
+ private ImmutableMap.Builder<String, Object> mappings;
private Optional<Integer> port;
public class ServletBinder {
@@ -55,6 +56,12 @@ public class Configuration {
mappings.put(mappingUrl, servlet);
return Builder.this;
}
+
+ public Configuration.Builder with(Class<? extends Servlet>
servletClass) {
+ Preconditions.checkNotNull(servletClass);
+ mappings.put(mappingUrl, servletClass);
+ return Builder.this;
+ }
}
private Builder() {
@@ -84,19 +91,42 @@ public class Configuration {
}
}
- private final ImmutableMap<String, Servlet> mappings;
+ private final ImmutableMap<String, Object> mappings;
private final Optional<Integer> port;
- private Configuration(ImmutableMap<String, Servlet> mappings,
Optional<Integer> port) {
+ private Configuration(ImmutableMap<String, Object> mappings,
Optional<Integer> port) {
this.mappings = mappings;
this.port = port;
}
- public ImmutableMap<String, Servlet> getMappings() {
+ public ImmutableMap<String, Object> getMappings() {
return mappings;
}
public Optional<Integer> getPort() {
return port;
}
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(mappings, port);
+ }
+
+ @Override
+ public boolean equals(Object that) {
+ if (that instanceof Configuration) {
+ Configuration other = (Configuration) that;
+ return Objects.equals(mappings, other.mappings)
+ && Objects.equals(port, other.port);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return com.google.common.base.Objects.toStringHelper(getClass())
+ .add("mappings", mappings)
+ .add("port", port)
+ .toString();
+ }
}
\ No newline at end of file
Added:
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/ConfigurationException.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/ConfigurationException.java?rev=1719301&view=auto
==============================================================================
---
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/ConfigurationException.java
(added)
+++
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/ConfigurationException.java
Fri Dec 11 10:04:37 2015
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.james.http.jetty;
+
+public class ConfigurationException extends RuntimeException {
+
+ public ConfigurationException(String message, ClassNotFoundException e) {
+ super(message, e);
+ }
+
+ public ConfigurationException(String message) {
+ super(message);
+ }
+
+}
Modified:
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/JettyHttpServer.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/JettyHttpServer.java?rev=1719301&r1=1719300&r2=1719301&view=diff
==============================================================================
---
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/JettyHttpServer.java
(original)
+++
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/JettyHttpServer.java
Fri Dec 11 10:04:37 2015
@@ -20,6 +20,9 @@
package org.apache.james.http.jetty;
import java.io.Closeable;
+import java.util.function.BiConsumer;
+
+import javax.servlet.Servlet;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
@@ -27,36 +30,49 @@ import org.eclipse.jetty.servlet.Servlet
import org.eclipse.jetty.servlet.ServletHolder;
import com.google.common.base.Throwables;
+import com.google.common.collect.Maps;
public class JettyHttpServer implements Closeable {
@SuppressWarnings("resource")
- public static JettyHttpServer start(Configuration configuration) throws
Exception {
- return new JettyHttpServer(configuration).start();
+ public static JettyHttpServer create(Configuration configuration) {
+ return new JettyHttpServer(configuration);
}
private Server server;
private ServerConnector serverConnector;
+ private final Configuration configuration;
private JettyHttpServer(Configuration configuration) {
- server = new Server();
- server.addConnector(buildServerConnector(configuration));
- server.setHandler(buildServletHandler(configuration));
+ this.configuration = configuration;
+ this.server = new Server();
+ this.server.addConnector(buildServerConnector(configuration));
+ this.server.setHandler(buildServletHandler(configuration));
}
private ServerConnector buildServerConnector(Configuration configuration) {
- serverConnector = new ServerConnector(server);
+ this.serverConnector = new ServerConnector(server);
configuration.getPort().ifPresent(serverConnector::setPort);
return serverConnector;
}
private ServletHandler buildServletHandler(Configuration configuration) {
ServletHandler servletHandler = new ServletHandler();
- configuration.getMappings().forEach((path, servlet) ->
servletHandler.addServletWithMapping(new ServletHolder(servlet), path));
+ BiConsumer<String, ServletHolder> addServletMapping = (path,
servletHolder) -> servletHandler.addServletWithMapping(servletHolder, path);
+ Maps.transformEntries(configuration.getMappings(),
this::toServletHolder).forEach(addServletMapping);
return servletHandler;
}
+
- private JettyHttpServer start() throws Exception {
+ @SuppressWarnings("unchecked")
+ private ServletHolder toServletHolder(String path, Object value) {
+ if (value instanceof Servlet) {
+ return new ServletHolder((Servlet) value);
+ }
+ return new ServletHolder((Class<? extends Servlet>)value);
+ }
+
+ public JettyHttpServer start() throws Exception {
server.start();
return this;
}
@@ -69,6 +85,9 @@ public class JettyHttpServer implements
return serverConnector.getLocalPort();
}
+ public Configuration getConfiguration() {
+ return configuration;
+ }
@Override
public void close() {
Added:
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/JettyHttpServerFactory.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/JettyHttpServerFactory.java?rev=1719301&view=auto
==============================================================================
---
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/JettyHttpServerFactory.java
(added)
+++
james/project/trunk/server/container/jetty/src/main/java/org/apache/james/http/jetty/JettyHttpServerFactory.java
Fri Dec 11 10:04:37 2015
@@ -0,0 +1,69 @@
+/****************************************************************
+ * 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.james.http.jetty;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.servlet.Servlet;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.http.jetty.Configuration.Builder;
+
+public class JettyHttpServerFactory {
+
+ public List<JettyHttpServer> createServers(HierarchicalConfiguration
config) throws Exception {
+ List<HierarchicalConfiguration> configs =
config.configurationsAt("httpserver");
+ return configs.stream()
+ .map(this::buildConfiguration)
+ .map(JettyHttpServer::create)
+ .collect(Collectors.toList());
+ }
+
+ private Configuration buildConfiguration(HierarchicalConfiguration
serverConfig) {
+ Builder builder = Configuration.builder();
+
+ boolean randomPort = serverConfig.getBoolean("port[@random]", false);
+ Integer port = serverConfig.getInteger("port[@fixed]", null);
+ if (randomPort && port != null) {
+ throw new ConfigurationException("Random port is not compatible
with fixed port");
+ }
+ if (randomPort) {
+ builder.randomPort();
+ }
+ if (port != null) {
+ builder.port(port);
+ }
+ for (HierarchicalConfiguration mapping:
serverConfig.configurationsAt("mappings.mapping")) {
+ String classname = mapping.getString("servlet");
+ Class<? extends Servlet> servletClass = findServlet(classname);
+ builder.serve(mapping.getString("path")).with(servletClass);
+ }
+ return builder.build();
+ }
+
+ @SuppressWarnings("unchecked")
+ private Class<? extends Servlet> findServlet(String classname) {
+ try {
+ return (Class<? extends Servlet>)
ClassLoader.getSystemClassLoader().loadClass(classname);
+ } catch (ClassNotFoundException e) {
+ throw new ConfigurationException(String.format("'%s' servlet
cannot be found", classname), e);
+ }
+ }
+}
Added:
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/Bad400.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/Bad400.java?rev=1719301&view=auto
==============================================================================
---
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/Bad400.java
(added)
+++
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/Bad400.java
Fri Dec 11 10:04:37 2015
@@ -0,0 +1,38 @@
+/****************************************************************
+ * 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.james.http.jetty;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class Bad400 extends HttpServlet {
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ resp.setStatus(400);
+ resp.getWriter().println("Bad");
+ resp.flushBuffer();
+ }
+
+}
Modified:
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/ConfigurationTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/ConfigurationTest.java?rev=1719301&r1=1719300&r2=1719301&view=diff
==============================================================================
---
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/ConfigurationTest.java
(original)
+++
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/ConfigurationTest.java
Fri Dec 11 10:04:37 2015
@@ -21,6 +21,8 @@ package org.apache.james.http.jetty;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import javax.servlet.Servlet;
+
import org.junit.Test;
public class ConfigurationTest {
@@ -97,6 +99,11 @@ public class ConfigurationTest {
@Test
public void shouldNotAllowNullServlet() {
- assertThatThrownBy(() ->
Configuration.builder().serve("/").with(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() ->
Configuration.builder().serve("/").with((Servlet)null)).isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ public void shouldNotAllowNullServletClassname() {
+ assertThatThrownBy(() ->
Configuration.builder().serve("/").with((Class<? extends
Servlet>)null)).isInstanceOf(NullPointerException.class);
}
}
Added:
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/JettyHttpServerFactoryTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/JettyHttpServerFactoryTest.java?rev=1719301&view=auto
==============================================================================
---
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/JettyHttpServerFactoryTest.java
(added)
+++
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/JettyHttpServerFactoryTest.java
Fri Dec 11 10:04:37 2015
@@ -0,0 +1,90 @@
+/****************************************************************
+ * 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.james.http.jetty;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class JettyHttpServerFactoryTest {
+
+ private HierarchicalConfiguration loadConfiguration(InputStream
configuration) throws org.apache.commons.configuration.ConfigurationException {
+ XMLConfiguration config = new XMLConfiguration();
+ config.setDelimiterParsingDisabled(true);
+ config.setAttributeSplittingDisabled(true);
+ config.load(configuration);
+ return config;
+ }
+
+ @Test
+ public void shouldCreateServersAsDescribedInXmlConfiguration() throws
Exception {
+ HierarchicalConfiguration configuration =
loadConfiguration(ClassLoader.getSystemResourceAsStream("httpserver.xml"));
+ List<JettyHttpServer> servers = new
JettyHttpServerFactory().createServers(configuration);
+ assertThat(servers).extracting(JettyHttpServer::getConfiguration)
+ .containsOnly(Configuration.builder()
+ .port(5000)
+ .serve("/foo")
+ .with(Ok200.class)
+ .serve("/bar")
+ .with(Bad400.class)
+ .build(),
+ Configuration.builder()
+ .randomPort()
+ .serve("/foo")
+ .with(Ok200.class)
+ .build());
+ }
+
+ @Test
+ public void shouldThrowOnEmptyServletName() throws Exception {
+ HierarchicalConfiguration configuration =
loadConfiguration(ClassLoader.getSystemResourceAsStream("emptyservletname.xml"));
+ assertThatThrownBy(() -> new
JettyHttpServerFactory().createServers(configuration)).isInstanceOf(ConfigurationException.class);
+ }
+
+ @Test
+ public void shouldThrowOnUnavailableServletName() throws Exception {
+ HierarchicalConfiguration configuration =
loadConfiguration(ClassLoader.getSystemResourceAsStream("unavailableservletname.xml"));
+ assertThatThrownBy(() -> new
JettyHttpServerFactory().createServers(configuration)).isInstanceOf(ConfigurationException.class);
+ }
+
+ @Test
+ public void shouldThrowOnConflictingPortConfiguration() throws Exception {
+ HierarchicalConfiguration configuration =
loadConfiguration(ClassLoader.getSystemResourceAsStream("conflictingport.xml"));
+ assertThatThrownBy(() -> new
JettyHttpServerFactory().createServers(configuration)).isInstanceOf(ConfigurationException.class);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void shouldBeAbleToLoadEmptyMappingConfiguration() throws Exception
{
+ HierarchicalConfiguration configuration =
loadConfiguration(ClassLoader.getSystemResourceAsStream("emptymappingconfiguration.xml"));
+ assertThat(new JettyHttpServerFactory().createServers(configuration))
+ .extracting(server -> server.getConfiguration().getMappings())
+ .containsOnly(ImmutableMap.of());
+ }
+
+
+}
Modified:
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/JettyHttpServerTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/JettyHttpServerTest.java?rev=1719301&r1=1719300&r2=1719301&view=diff
==============================================================================
---
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/JettyHttpServerTest.java
(original)
+++
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/JettyHttpServerTest.java
Fri Dec 11 10:04:37 2015
@@ -70,8 +70,8 @@ public class JettyHttpServerTest {
@Test
public void shouldStartOnRandomPort() throws Exception {
- try (JettyHttpServer first =
JettyHttpServer.start(configurationBuilder.build());
- JettyHttpServer second =
JettyHttpServer.start(configurationBuilder.build())) {
+ try (JettyHttpServer first =
JettyHttpServer.create(configurationBuilder.build()).start();
+ JettyHttpServer second =
JettyHttpServer.create(configurationBuilder.build()).start()) {
assertThat(first.getPort()).isNotEqualTo(second.getPort());
}
}
@@ -79,7 +79,7 @@ public class JettyHttpServerTest {
@Test
public void shouldStartOnConfiguredPort() throws Exception {
int port = generateValidUnprivilegedPort();
- testee =
JettyHttpServer.start(configurationBuilder.port(port).build());
+ testee =
JettyHttpServer.create(configurationBuilder.port(port).build()).start();
assertThat(testee.getPort()).isEqualTo(port);
}
@@ -92,7 +92,7 @@ public class JettyHttpServerTest {
@Test
public void shouldReturn404WhenNoServletConfigured() throws Exception {
- testee = JettyHttpServer.start(configurationBuilder.build());
+ testee = JettyHttpServer.create(configurationBuilder.build()).start();
RestAssured.port = testee.getPort();
when()
.get("/")
@@ -105,9 +105,10 @@ public class JettyHttpServerTest {
public void
shouldLetConfiguredServletHandleIncomingRequestWhenServletConfigured() throws
Exception {
ServletMethod getHandler = (req, resp) ->
resp.getWriter().append("served").close();
- testee = JettyHttpServer.start(configurationBuilder
+ testee = JettyHttpServer.create(configurationBuilder
.serve("/")
- .with(get(getHandler)).build());
+ .with(get(getHandler)).build())
+ .start();
RestAssured.port = testee.getPort();
@@ -124,12 +125,13 @@ public class JettyHttpServerTest {
ServletMethod fooGetHandler = (req, resp) ->
resp.getWriter().append("served").close();
ServletMethod barGetMethod = (req, resp) -> resp.sendError(400,
"should not be called");
- testee = JettyHttpServer.start(configurationBuilder
+ testee = JettyHttpServer.create(configurationBuilder
.serve("/foo")
.with(get(fooGetHandler))
.serve("/bar")
.with(get(barGetMethod))
- .build());
+ .build())
+ .start();
RestAssured.port = testee.getPort();
@@ -141,4 +143,23 @@ public class JettyHttpServerTest {
.body(Matchers.equalTo("served"));
}
+ @Test
+ public void
shouldLetConfiguredServletHandleIncomingRequestWhenServletConfiguredByName()
throws Exception {
+
+ testee = JettyHttpServer.create(configurationBuilder
+ .serve("/foo")
+ .with(Ok200.class)
+ .build())
+ .start();
+
+ RestAssured.port = testee.getPort();
+
+ when()
+ .get("/foo")
+ .then()
+ .assertThat()
+ .statusCode(200)
+ .body(Matchers.equalTo("Ok"));
+ }
+
}
Added:
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/Ok200.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/Ok200.java?rev=1719301&view=auto
==============================================================================
---
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/Ok200.java
(added)
+++
james/project/trunk/server/container/jetty/src/test/java/org/apache/james/http/jetty/Ok200.java
Fri Dec 11 10:04:37 2015
@@ -0,0 +1,37 @@
+/****************************************************************
+ * 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.james.http.jetty;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class Ok200 extends HttpServlet {
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ resp.getWriter().print("Ok");
+ resp.flushBuffer();
+ }
+
+}
Added:
james/project/trunk/server/container/jetty/src/test/resources/conflictingport.xml
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/test/resources/conflictingport.xml?rev=1719301&view=auto
==============================================================================
---
james/project/trunk/server/container/jetty/src/test/resources/conflictingport.xml
(added)
+++
james/project/trunk/server/container/jetty/src/test/resources/conflictingport.xml
Fri Dec 11 10:04:37 2015
@@ -0,0 +1,11 @@
+<httpservers>
+ <httpserver>
+ <port fixed="5000" random="true"/>
+ <mappings>
+ <mapping>
+ <path>/foo</path>
+ <servlet>org.apache.james.http.jetty.Ok200</servlet>
+ </mapping>
+ </mappings>
+ </httpserver>
+</httpservers>
\ No newline at end of file
Added:
james/project/trunk/server/container/jetty/src/test/resources/emptymappingconfiguration.xml
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/test/resources/emptymappingconfiguration.xml?rev=1719301&view=auto
==============================================================================
---
james/project/trunk/server/container/jetty/src/test/resources/emptymappingconfiguration.xml
(added)
+++
james/project/trunk/server/container/jetty/src/test/resources/emptymappingconfiguration.xml
Fri Dec 11 10:04:37 2015
@@ -0,0 +1,5 @@
+<httpservers>
+ <httpserver>
+ <port fixed="5000"/>
+ </httpserver>
+</httpservers>
\ No newline at end of file
Added:
james/project/trunk/server/container/jetty/src/test/resources/emptyservletname.xml
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/test/resources/emptyservletname.xml?rev=1719301&view=auto
==============================================================================
---
james/project/trunk/server/container/jetty/src/test/resources/emptyservletname.xml
(added)
+++
james/project/trunk/server/container/jetty/src/test/resources/emptyservletname.xml
Fri Dec 11 10:04:37 2015
@@ -0,0 +1,11 @@
+<httpservers>
+ <httpserver>
+ <port fixed="5000"/>
+ <mappings>
+ <mapping>
+ <path>/foo</path>
+ <servlet></servlet>
+ </mapping>
+ </mappings>
+ </httpserver>
+</httpservers>
\ No newline at end of file
Added:
james/project/trunk/server/container/jetty/src/test/resources/httpserver.xml
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/test/resources/httpserver.xml?rev=1719301&view=auto
==============================================================================
---
james/project/trunk/server/container/jetty/src/test/resources/httpserver.xml
(added)
+++
james/project/trunk/server/container/jetty/src/test/resources/httpserver.xml
Fri Dec 11 10:04:37 2015
@@ -0,0 +1,24 @@
+<httpservers>
+ <httpserver>
+ <port fixed="5000"/>
+ <mappings>
+ <mapping>
+ <path>/foo</path>
+ <servlet>org.apache.james.http.jetty.Ok200</servlet>
+ </mapping>
+ <mapping>
+ <path>/bar</path>
+ <servlet>org.apache.james.http.jetty.Bad400</servlet>
+ </mapping>
+ </mappings>
+ </httpserver>
+ <httpserver>
+ <port random="true"/>
+ <mappings>
+ <mapping>
+ <path>/foo</path>
+ <servlet>org.apache.james.http.jetty.Ok200</servlet>
+ </mapping>
+ </mappings>
+ </httpserver>
+</httpservers>
\ No newline at end of file
Added:
james/project/trunk/server/container/jetty/src/test/resources/unavailableservletname.xml
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/container/jetty/src/test/resources/unavailableservletname.xml?rev=1719301&view=auto
==============================================================================
---
james/project/trunk/server/container/jetty/src/test/resources/unavailableservletname.xml
(added)
+++
james/project/trunk/server/container/jetty/src/test/resources/unavailableservletname.xml
Fri Dec 11 10:04:37 2015
@@ -0,0 +1,11 @@
+<httpservers>
+ <httpserver>
+ <port fixed="5000"/>
+ <mappings>
+ <mapping>
+ <path>/foo</path>
+ <servlet>com.apple.FreeServlet</servlet>
+ </mapping>
+ </mappings>
+ </httpserver>
+</httpservers>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]