Remove dead /jetty-spring/ module

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2020-11-16 08:18:58 -06:00
parent 428d60bc3c
commit 390fa83d8e
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
21 changed files with 3 additions and 1009 deletions

2
Jenkinsfile vendored
View File

@ -25,7 +25,7 @@ pipeline {
',**/org/eclipse/jetty/demo/**' +
// special environments / late integrations
',**/org/eclipse/jetty/gcloud/**' + ',**/org/eclipse/jetty/infinispan/**' +
',**/org/eclipse/jetty/osgi/**' + ',**/org/eclipse/jetty/spring/**' +
',**/org/eclipse/jetty/osgi/**' +
',**/org/eclipse/jetty/http/spi/**' +
// test classes
',**/org/eclipse/jetty/tests/**' + ',**/org/eclipse/jetty/test/**',

View File

@ -330,12 +330,6 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-spring</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-start</artifactId>

View File

@ -292,11 +292,6 @@
<artifactId>jetty-servlets</artifactId>
<version>10.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-spring</artifactId>
<version>10.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-unixsocket-common</artifactId>

View File

@ -21,6 +21,5 @@
include::cdi.adoc[]
include::weld.adoc[]
include::spring-usage.adoc[]
include::osgi.adoc[]
include::metro.adoc[]

View File

@ -1,104 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
[[framework-jetty-spring]]
=== Spring Setup
You can assemble and configure Jetty in code or with almost any IoC style framework including Spring.
If all you want to do is setup a Jetty server in your stock Spring usage, simply look at the xml snippet below as an example.
If you want to replace the jetty-xml being used to start the normal Jetty distribution with spring, you may do so however currently it will not leverage the rest of the module system.
==== Jetty-Spring Module
The skeleton of a jetty spring module can be enabled from the jetty-distribution via the link:#startup-modules[module mechanism].
For example:
[source, screen, subs="{sub-order}"]
....
$ java -jar start.jar --add-to-start=spring
....
This (or the alternative link:#start-jar[--add-to-start]=spring command) creates a `${jetty.home}/lib/spring` directory and populates it with the jetty-spring integration jar.
It does NOT supply the spring jars and their dependencies.
You will need to download these and place them into jetty's classpath - you can use the `${jetty.home}/lib/spring` directory created by spring.mod for this purpose.
==== Using Spring to Configure Jetty
Configuring Jetty via Spring is simply a matter of calling the API as Spring beans.
The following is an example mimicking the default jetty startup configuration.
[source, xml, subs="{sub-order}"]
----
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!-- =============================================================== -->
<!-- Configure the Jetty Server with Spring -->
<!-- This file is the similar to jetty.xml, but written in spring -->
<!-- XmlBeanFactory format. -->
<!-- =============================================================== -->
<beans>
<bean id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
<bean id="server" name="Main" class="org.eclipse.jetty.server.Server" init-method="start" destroy-method="stop">
<constructor-arg>
<bean id="threadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<property name="minThreads" value="10"/>
<property name="maxThreads" value="50"/>
</bean>
</constructor-arg>
<property name="connectors">
<list>
<bean id="connector" class="org.eclipse.jetty.server.ServerConnector">
<constructor-arg ref="server"/>
<property name="port" value="8080"/>
</bean>
</list>
</property>
<property name="handler">
<bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<property name="handlers">
<list>
<ref bean="contexts"/>
<bean id="defaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</list>
</property>
</bean>
</property>
<property name="beans">
<list>
<bean id="deploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
<property name="contexts" ref="contexts"/>
<property name="appProviders">
<list>
<bean id="webAppProvider" class="org.eclipse.jetty.deploy.providers.WebAppProvider">
<property name="monitoredDirName" value="webapps"/>
<property name="scanInterval" value="1"/>
<property name="extractWars" value="true"/>
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
</beans>
----

View File

@ -126,7 +126,7 @@
org.eclipse.jetty.orbit,org.eclipse.jetty.http2,org.eclipse.jetty.websocket,org.eclipse.jetty.fcgi,org.eclipse.jetty.toolchain,org.apache.taglibs
</excludeGroupIds>
<excludeArtifactIds>
apache-jsp,apache-jstl,jetty-start,jetty-spring,jetty-slf4j-impl
apache-jsp,apache-jstl,jetty-start,jetty-slf4j-impl
</excludeArtifactIds>
<includeTypes>jar</includeTypes>
<outputDirectory>${assembly-directory}/lib</outputDirectory>
@ -144,7 +144,7 @@
org.eclipse.jetty.orbit,org.eclipse.jetty.http2,org.eclipse.jetty.websocket,org.eclipse.jetty.fcgi,org.eclipse.jetty.toolchain,org.apache.taglibs
</excludeGroupIds>
<excludeArtifactIds>
apache-jsp,apache-jstl,jetty-start,jetty-spring
apache-jsp,apache-jstl,jetty-start
</excludeArtifactIds>
<includeTypes>jar</includeTypes>
<classifier>sources</classifier>
@ -282,33 +282,6 @@
<outputDirectory>${source-assembly-directory}/lib/fcgi</outputDirectory>
</configuration>
</execution>
<execution>
<id>copy-lib-spring-deps</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.eclipse.jetty</includeGroupIds>
<includeArtifactIds>jetty-spring</includeArtifactIds>
<includeTypes>jar</includeTypes>
<outputDirectory>${assembly-directory}/lib/spring</outputDirectory>
</configuration>
</execution>
<execution>
<id>copy-lib-spring-src-deps</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.eclipse.jetty</includeGroupIds>
<includeArtifactIds>jetty-spring</includeArtifactIds>
<includeTypes>jar</includeTypes>
<classifier>sources</classifier>
<outputDirectory>${source-assembly-directory}/lib/spring</outputDirectory>
</configuration>
</execution>
<execution>
<id>copy-servlet-api-deps</id>
<phase>generate-resources</phase>
@ -702,12 +675,6 @@
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-spring</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>

View File

@ -308,10 +308,6 @@
<groupId>org.eclipse.jetty.fcgi</groupId>
<artifactId>fcgi-server</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-start</artifactId>

View File

@ -1,81 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-project</artifactId>
<version>10.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jetty-spring</artifactId>
<name>Example :: Jetty Spring</name>
<properties>
<dependencies>target/dependencies</dependencies>
<bundle-symbolic-name>${project.groupId}.spring</bundle-symbolic-name>
</properties>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)";resolution:=optional
</Require-Capability>
<Provide-Capability>
osgi.serviceloader;osgi.serviceloader=org.eclipse.jetty.xml.ConfigurationProcessorFactory
</Provide-Capability>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-xml</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,61 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!-- =============================================================== -->
<!-- Configure the Jetty Server with Spring -->
<!-- This file is the similar to jetty.xml, but written in spring -->
<!-- XmlBeanFactory format. -->
<!-- =============================================================== -->
<beans>
<bean id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
<bean id="server" name="Main" class="org.eclipse.jetty.server.Server" init-method="start" destroy-method="stop">
<constructor-arg>
<bean id="threadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<property name="minThreads" value="10"/>
<property name="maxThreads" value="50"/>
</bean>
</constructor-arg>
<property name="connectors">
<list>
<bean id="connector" class="org.eclipse.jetty.server.ServerConnector">
<constructor-arg ref="server"/>
<property name="port" value="8080"/>
</bean>
</list>
</property>
<property name="handler">
<bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerList">
<property name="handlers">
<list>
<ref bean="contexts"/>
<bean id="defaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</list>
</property>
</bean>
</property>
<property name="beans">
<list>
<bean id="deploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
<property name="contexts" ref="contexts"/>
<property name="appProviders">
<list>
<bean id="webAppProvider" class="org.eclipse.jetty.deploy.providers.WebAppProvider">
<property name="monitoredDirName" value="webapps"/>
<property name="scanInterval" value="1"/>
<property name="extractWars" value="true"/>
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
</beans>

View File

@ -1,16 +0,0 @@
# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
[description]
Enables Spring configuration processing of Jetty XML files.
All Jetty-style XML files can optionally be written as Spring beans.2
[depend]
server
[lib]
lib/spring/*.jar
[ini-template]
## See https://eclipse.org/jetty/documentation/current/frameworks.html#framework-jetty-spring
## for information on how to complete spring configuration

View File

@ -1,32 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
import org.eclipse.jetty.spring.SpringConfigurationProcessorFactory;
import org.eclipse.jetty.xml.ConfigurationProcessorFactory;
module org.eclipse.jetty.spring
{
exports org.eclipse.jetty.spring;
requires transitive org.eclipse.jetty.xml;
requires org.slf4j;
requires spring.beans;
requires spring.core;
provides ConfigurationProcessorFactory with SpringConfigurationProcessorFactory;
}

View File

@ -1,34 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.spring;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
/**
* Runs Jetty from a Spring configuration file passed as argument.
*/
public class Main
{
public static void main(String[] args) throws Exception
{
Resource config = Resource.newResource(args.length == 1 ? args[0] : "etc/jetty-spring.xml");
XmlConfiguration.main(config.getFile().getAbsolutePath());
}
}

View File

@ -1,170 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.spring;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map;
import java.util.ServiceLoader;
import org.eclipse.jetty.xml.ConfigurationProcessor;
import org.eclipse.jetty.xml.ConfigurationProcessorFactory;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.eclipse.jetty.xml.XmlParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
/**
* Spring ConfigurationProcessor
* <p>
* A {@link ConfigurationProcessor} that uses a spring XML file to emulate the {@link XmlConfiguration} format.
* <p>
* {@link XmlConfiguration} expects a primary object that is either passed in to a call to {@link #configure(Object)}
* or that is constructed by a call to {@link #configure()}. This processor looks for a bean definition
* with an id, name or alias of "Main" as uses that as the primary bean.
* <p>
* The objects mapped by {@link XmlConfiguration#getIdMap()} are set as singletons before any configuration calls
* and if the spring configuration file contains a definition for the singleton id, the the singleton is updated
* with a call to {@link DefaultListableBeanFactory#configureBean(Object, String)}.
* <p>
* The property map obtained via {@link XmlConfiguration#getProperties()} is set as a singleton called "properties"
* and values can be accessed by somewhat verbose
* usage of {@link org.springframework.beans.factory.config.MethodInvokingFactoryBean}.
* <p>
* This processor is returned by the {@link SpringConfigurationProcessorFactory} for any XML document whos first
* element is "beans". The factory is discovered by a {@link ServiceLoader} for {@link ConfigurationProcessorFactory}.
*/
public class SpringConfigurationProcessor implements ConfigurationProcessor
{
private static final Logger LOG = LoggerFactory.getLogger(SpringConfigurationProcessor.class);
private XmlConfiguration _configuration;
private DefaultListableBeanFactory _beanFactory;
private String _main;
@Override
public void init(org.eclipse.jetty.util.resource.Resource jettyResource, XmlParser.Node config, XmlConfiguration configuration)
{
try
{
_configuration = configuration;
Resource springResource;
if (jettyResource != null)
{
springResource = new UrlResource(jettyResource.getURI());
}
else
{
springResource = new ByteArrayResource((
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" +
config).getBytes(StandardCharsets.UTF_8));
}
_beanFactory = new DefaultListableBeanFactory()
{
@Override
protected void applyPropertyValues(String beanName, BeanDefinition mbd, BeanWrapper bw, PropertyValues pvs)
{
_configuration.initializeDefaults(bw.getWrappedInstance());
super.applyPropertyValues(beanName, mbd, bw, pvs);
}
};
new XmlBeanDefinitionReader(_beanFactory).loadBeanDefinitions(springResource);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
@Override
public Object configure(Object obj) throws Exception
{
doConfigure();
return _beanFactory.configureBean(obj, _main);
}
/**
* Return a configured bean. If a bean has the id or alias of "Main", then it is returned, otherwise the first bean in the file is returned.
*
* @see org.eclipse.jetty.xml.ConfigurationProcessor#configure()
*/
@Override
public Object configure() throws Exception
{
doConfigure();
return _beanFactory.getBean(_main);
}
private void doConfigure()
{
_beanFactory.registerSingleton("properties", _configuration.getProperties());
// Look for the main bean;
for (String bean : _beanFactory.getBeanDefinitionNames())
{
LOG.debug("{} - {}", bean, Arrays.asList(_beanFactory.getAliases(bean)));
String[] aliases = _beanFactory.getAliases(bean);
if ("Main".equals(bean) || aliases != null && Arrays.asList(aliases).contains("Main"))
{
_main = bean;
break;
}
}
if (_main == null)
_main = _beanFactory.getBeanDefinitionNames()[0];
// Register id beans as singletons
Map<String, Object> idMap = _configuration.getIdMap();
LOG.debug("idMap {}", idMap);
for (String id : idMap.keySet())
{
LOG.debug("register {}", id);
_beanFactory.registerSingleton(id, idMap.get(id));
}
// Apply configuration to existing singletons
for (String id : idMap.keySet())
{
if (_beanFactory.containsBeanDefinition(id))
{
LOG.debug("reconfigure {}", id);
_beanFactory.configureBean(idMap.get(id), id);
}
}
// Extract id's for next time.
for (String id : _beanFactory.getSingletonNames())
{
idMap.put(id, _beanFactory.getBean(id));
}
}
}

View File

@ -1,43 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.spring;
import org.eclipse.jetty.xml.ConfigurationProcessor;
import org.eclipse.jetty.xml.ConfigurationProcessorFactory;
import org.eclipse.jetty.xml.XmlConfiguration;
/**
* Spring ConfigurationProcessor Factory
* <p>
* Create a {@link SpringConfigurationProcessor} for XML documents with a "beans" element.
* The factory is discovered by a {@link java.util.ServiceLoader} for {@link ConfigurationProcessorFactory}.
*
* @see SpringConfigurationProcessor
* @see XmlConfiguration
*/
public class SpringConfigurationProcessorFactory implements ConfigurationProcessorFactory
{
@Override
public ConfigurationProcessor getConfigurationProcessor(String dtd, String tag)
{
if ("beans".equals(tag))
return new SpringConfigurationProcessor();
return null;
}
}

View File

@ -1,23 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
/**
* Jetty Spring : Spring IoC Configuration for Jetty
*/
package org.eclipse.jetty.spring;

View File

@ -1 +0,0 @@
org.eclipse.jetty.spring.SpringConfigurationProcessorFactory

View File

@ -1,163 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.spring;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class SpringXmlConfigurationTest
{
protected String _configure = "org/eclipse/jetty/spring/configure.xml";
@BeforeEach
public void init()
{
// Jetty's XML configuration will make use of java.util.ServiceLoader
// to load the proper ConfigurationProcessorFactory, so these tests
// will always fail in JDK 5.
String javaVersion = System.getProperty("java.version");
Pattern regexp = Pattern.compile("1\\.(\\d{1})\\..*");
Matcher matcher = regexp.matcher(javaVersion);
if (matcher.matches())
{
String minor = matcher.group(1);
assumeTrue(Integer.parseInt(minor) > 5);
}
}
@Test
public void testPassedObject() throws Exception
{
TestConfiguration.VALUE = 77;
URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure);
XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(url));
Map<String, String> properties = new HashMap<>();
properties.put("test", "xxx");
TestConfiguration nested = new TestConfiguration();
nested.setTestString0("nested");
configuration.getIdMap().put("nested", nested);
TestConfiguration tc = new TestConfiguration();
tc.setTestString0("preconfig");
tc.setTestInt0(42);
configuration.getProperties().putAll(properties);
tc = (TestConfiguration)configuration.configure(tc);
assertEquals("preconfig", tc.getTestString0());
assertEquals(42, tc.getTestInt0());
assertEquals("SetValue", tc.getTestString1());
assertEquals(1, tc.getTestInt1());
assertEquals("nested", tc.getNested().getTestString0());
assertEquals("nested", tc.getNested().getTestString1());
assertEquals("default", tc.getNested().getNested().getTestString0());
assertEquals("deep", tc.getNested().getNested().getTestString1());
assertEquals("deep", ((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestString1());
assertEquals(2, ((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestInt2());
assertEquals("xxx", tc.getTestString2());
}
@Test
public void testNewObject() throws Exception
{
final String newDefaultValue = "NEW DEFAULT";
TestConfiguration.VALUE = 71;
URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure);
final AtomicInteger count = new AtomicInteger(0);
XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(url))
{
@Override
public void initializeDefaults(Object object)
{
super.initializeDefaults(object);
if (object instanceof TestConfiguration)
{
count.incrementAndGet();
((TestConfiguration)object).setTestString0(newDefaultValue);
((TestConfiguration)object).setTestString1("WILL BE OVERRIDDEN");
}
}
};
Map<String, String> properties = new HashMap<String, String>();
properties.put("test", "xxx");
TestConfiguration nested = new TestConfiguration();
nested.setTestString0("nested");
configuration.getIdMap().put("nested", nested);
configuration.getProperties().putAll(properties);
TestConfiguration tc = (TestConfiguration)configuration.configure();
assertEquals(3, count.get());
assertEquals(newDefaultValue, tc.getTestString0());
assertEquals(-1, tc.getTestInt0());
assertEquals("SetValue", tc.getTestString1());
assertEquals(1, tc.getTestInt1());
assertEquals(newDefaultValue, tc.getNested().getTestString0());
assertEquals("nested", tc.getNested().getTestString1());
assertEquals(newDefaultValue, tc.getNested().getNested().getTestString0());
assertEquals("deep", tc.getNested().getNested().getTestString1());
assertEquals("deep", ((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestString1());
assertEquals(2, ((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestInt2());
assertEquals("xxx", tc.getTestString2());
}
@Test
public void testJettyXml() throws Exception
{
URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource("org/eclipse/jetty/spring/jetty.xml");
XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(url));
Server server = (Server)configuration.configure();
server.dumpStdErr();
}
@Test
public void xmlConfigurationMain() throws Exception
{
XmlConfiguration.main("src/test/resources/org/eclipse/jetty/spring/jetty.xml");
}
}

View File

@ -1,154 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.spring;
import java.net.URL;
import org.junit.jupiter.api.Disabled;
@Disabled
public class TestConfiguration
{
public static int VALUE = 77;
public TestConfiguration nested;
public String testString0 = "default";
public String testString1;
public String testString2;
public int testInt0 = -1;
public int testInt1;
public int testInt2;
public URL url;
public Object[] objArray;
public int[] intArray;
public static int getVALUE()
{
return VALUE;
}
public static void setVALUE(int vALUE)
{
VALUE = vALUE;
}
public TestConfiguration()
{
}
public TestConfiguration getNested()
{
return nested;
}
public void setNested(TestConfiguration nested)
{
this.nested = nested;
}
public String getTestString0()
{
return testString0;
}
public void setTestString0(String testString0)
{
this.testString0 = testString0;
}
public String getTestString1()
{
return testString1;
}
public void setTestString1(String testString1)
{
this.testString1 = testString1;
}
public String getTestString2()
{
return testString2;
}
public void setTestString2(String testString2)
{
this.testString2 = testString2;
}
public int getTestInt0()
{
return testInt0;
}
public void setTestInt0(int testInt0)
{
this.testInt0 = testInt0;
}
public int getTestInt1()
{
return testInt1;
}
public void setTestInt1(int testInt1)
{
this.testInt1 = testInt1;
}
public int getTestInt2()
{
return testInt2;
}
public void setTestInt2(int testInt2)
{
this.testInt2 = testInt2;
}
public URL getUrl()
{
return url;
}
public void setUrl(URL url)
{
this.url = url;
}
public Object[] getObjArray()
{
return objArray;
}
public void setObjArray(Object[] objArray)
{
this.objArray = objArray;
}
public int[] getIntArray()
{
return intArray;
}
public void setIntArray(int[] intArray)
{
this.intArray = intArray;
}
}

View File

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- define the singleton properties Map, filled in with XmlConfiguration.getProperties() -->
<bean id="properties" class="java.util.Map"/>
<!-- extract a value from the property map -->
<bean id="testProperty" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject"><ref bean="properties" /></property>
<property name="targetMethod" value="get" />
<property name="arguments"><list><value>test</value></list></property>
</bean>
<bean id="root" name="Some,Names,Main" class="org.eclipse.jetty.spring.TestConfiguration">
<property name="testString1" value="SetValue" />
<property name="testInt1" value="1" />
<property name="nested" ref="nested" />
<property name="testString2" ref="testProperty"/>
</bean>
<bean id="nested" class="org.eclipse.jetty.spring.TestConfiguration">
<property name="testInt2" value="2" />
<property name="testString1" value="nested" />
<property name="nested" ref="nestedDeep" />
</bean>
<bean id="nestedDeep" class="org.eclipse.jetty.spring.TestConfiguration">
<property name="testString1" value="deep" />
<property name="testInt2" value="2" />
</bean>
</beans>

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
<bean id="server" name="Main" class="org.eclipse.jetty.server.Server">
<constructor-arg type="org.eclipse.jetty.util.thread.ThreadPool">
<bean id="threadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<property name="minThreads" value="10"/>
<property name="maxThreads" value="200"/>
</bean>
</constructor-arg>
<property name="connectors">
<list>
<bean id="connector" class="org.eclipse.jetty.server.ServerConnector">
<constructor-arg type="org.eclipse.jetty.server.Server" ref="server" />
</bean>
</list>
</property>
<property name="handler">
<bean id="handlers" class="org.eclipse.jetty.server.handler.HandlerList">
<property name="handlers">
<list>
<ref bean="contexts"/>
<bean id="defaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</list>
</property>
</bean>
</property>
<property name="stopAtShutdown" value="true"/>
<property name="stopTimeout" value="1000"/>
<property name="dumpAfterStart" value="true"/>
<property name="dumpBeforeStop" value="false"/>
</bean>
</beans>

View File

@ -126,7 +126,6 @@
<module>jetty-jndi</module>
<module>jetty-jaas</module>
<module>jetty-cdi</module>
<module>jetty-spring</module>
<module>jetty-client</module>
<module>jetty-proxy</module>
<module>jetty-jaspi</module>