This is an automated email from the ASF dual-hosted git repository. rcordier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 7219cc9596b9d8b2628f4859a41d13afe18e93cd Author: Rene Cordier <rcord...@linagora.com> AuthorDate: Tue Mar 3 09:08:04 2020 +0700 [Refactoring] Delete unused classes --- .../org/apache/james/jmap/draft/JmapServer.java | 24 ------ .../james/http/jetty/JettyHttpServerFactory.java | 87 -------------------- .../http/jetty/JettyHttpServerFactoryTest.java | 95 ---------------------- 3 files changed, 206 deletions(-) diff --git a/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/JmapServer.java b/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/JmapServer.java deleted file mode 100644 index 41aa713..0000000 --- a/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/JmapServer.java +++ /dev/null @@ -1,24 +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.james.jmap.draft; - -public interface JmapServer { - JmapGuiceProbe getJmapProbe(); -} diff --git a/server/container/jetty/src/main/java/org/apache/james/http/jetty/JettyHttpServerFactory.java b/server/container/jetty/src/main/java/org/apache/james/http/jetty/JettyHttpServerFactory.java deleted file mode 100644 index 67a1bfc..0000000 --- a/server/container/jetty/src/main/java/org/apache/james/http/jetty/JettyHttpServerFactory.java +++ /dev/null @@ -1,87 +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.james.http.jetty; - -import java.util.List; -import java.util.stream.Collectors; - -import javax.servlet.Filter; -import javax.servlet.Servlet; - -import org.apache.commons.configuration2.HierarchicalConfiguration; -import org.apache.commons.configuration2.tree.ImmutableNode; -import org.apache.james.http.jetty.Configuration.Builder; - -public class JettyHttpServerFactory { - - public List<JettyHttpServer> createServers(HierarchicalConfiguration<ImmutableNode> config) throws Exception { - List<HierarchicalConfiguration<ImmutableNode>> configs = config.configurationsAt("httpserver"); - return configs.stream() - .map(this::buildConfiguration) - .map(JettyHttpServer::create) - .collect(Collectors.toList()); - } - - private Configuration buildConfiguration(HierarchicalConfiguration<ImmutableNode> 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); - } - List<HierarchicalConfiguration<ImmutableNode>> mappings = serverConfig.configurationsAt("mappings.mapping"); - for (HierarchicalConfiguration<ImmutableNode> mapping: mappings) { - String classname = mapping.getString("servlet"); - Class<? extends Servlet> servletClass = findServlet(classname); - builder.serve(mapping.getString("path")).with(servletClass); - } - List<HierarchicalConfiguration<ImmutableNode>> filters = serverConfig.configurationsAt("filters.mapping"); - for (HierarchicalConfiguration<ImmutableNode> mapping: filters) { - String classname = mapping.getString("filter"); - Class<? extends Filter> filterClass = findFilter(classname); - builder.filter(mapping.getString("path")).with(filterClass); - } - 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); - } - } - - @SuppressWarnings("unchecked") - private Class<? extends Filter> findFilter(String classname) { - try { - return (Class<? extends Filter>) ClassLoader.getSystemClassLoader().loadClass(classname); - } catch (ClassNotFoundException e) { - throw new ConfigurationException(String.format("'%s' filter cannot be found", classname), e); - } - } -} diff --git a/server/container/jetty/src/test/java/org/apache/james/http/jetty/JettyHttpServerFactoryTest.java b/server/container/jetty/src/test/java/org/apache/james/http/jetty/JettyHttpServerFactoryTest.java deleted file mode 100644 index 231e8ad..0000000 --- a/server/container/jetty/src/test/java/org/apache/james/http/jetty/JettyHttpServerFactoryTest.java +++ /dev/null @@ -1,95 +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.james.http.jetty; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import java.util.List; - -import org.apache.commons.configuration2.HierarchicalConfiguration; -import org.apache.commons.configuration2.tree.ImmutableNode; -import org.apache.james.server.core.configuration.FileConfigurationProvider; -import org.junit.Test; - -import com.google.common.collect.ImmutableMap; - -public class JettyHttpServerFactoryTest { - - @Test - public void shouldCreateServersAsDescribedInXmlConfiguration() throws Exception { - HierarchicalConfiguration<ImmutableNode> configuration = FileConfigurationProvider.getConfig(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) - .filter("/*") - .with(SpyFilter.class).only() - .build()); - } - - @Test - public void shouldThrowOnEmptyServletName() throws Exception { - HierarchicalConfiguration<ImmutableNode> configuration = FileConfigurationProvider.getConfig(ClassLoader.getSystemResourceAsStream("emptyservletname.xml")); - assertThatThrownBy(() -> new JettyHttpServerFactory().createServers(configuration)).isInstanceOf(ConfigurationException.class); - } - - @Test - public void shouldThrowOnUnavailableServletName() throws Exception { - HierarchicalConfiguration<ImmutableNode> configuration = FileConfigurationProvider.getConfig(ClassLoader.getSystemResourceAsStream("unavailableservletname.xml")); - assertThatThrownBy(() -> new JettyHttpServerFactory().createServers(configuration)).isInstanceOf(ConfigurationException.class); - } - - @Test - public void shouldThrowOnConflictingPortConfiguration() throws Exception { - HierarchicalConfiguration<ImmutableNode> configuration = FileConfigurationProvider.getConfig(ClassLoader.getSystemResourceAsStream("conflictingport.xml")); - assertThatThrownBy(() -> new JettyHttpServerFactory().createServers(configuration)).isInstanceOf(ConfigurationException.class); - } - - @SuppressWarnings("unchecked") - @Test - public void shouldBeAbleToLoadEmptyMappingConfiguration() throws Exception { - HierarchicalConfiguration<ImmutableNode> configuration = FileConfigurationProvider.getConfig(ClassLoader.getSystemResourceAsStream("emptymappingconfiguration.xml")); - assertThat(new JettyHttpServerFactory().createServers(configuration)) - .extracting(server -> server.getConfiguration().getMappings()) - .containsOnly(ImmutableMap.of()); - } - - @Test - public void shouldThrowOnEmptyFilterName() throws Exception { - HierarchicalConfiguration<ImmutableNode> configuration = FileConfigurationProvider.getConfig(ClassLoader.getSystemResourceAsStream("emptyfiltername.xml")); - assertThatThrownBy(() -> new JettyHttpServerFactory().createServers(configuration)).isInstanceOf(ConfigurationException.class); - } - - @Test - public void shouldThrowOnUnavailableFilterName() throws Exception { - HierarchicalConfiguration<ImmutableNode> configuration = FileConfigurationProvider.getConfig(ClassLoader.getSystemResourceAsStream("unavailablefiltername.xml")); - assertThatThrownBy(() -> new JettyHttpServerFactory().createServers(configuration)).isInstanceOf(ConfigurationException.class); - } - -} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org