Updated jetty-spring module.
This commit is contained in:
parent
dd180a8c48
commit
a5df0ab456
|
@ -1,5 +0,0 @@
|
|||
This jetty module is an example of how spring can be used to
|
||||
configure and run Jetty.
|
||||
|
||||
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
<name>Example :: Jetty Spring</name>
|
||||
|
||||
<properties>
|
||||
<spring-version>2.5.6</spring-version>
|
||||
<spring-version>3.1.3.RELEASE</spring-version>
|
||||
<dependencies>target/dependencies</dependencies>
|
||||
</properties>
|
||||
|
||||
|
@ -38,24 +38,25 @@
|
|||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
<artifactId>jetty-xml</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-plus</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-deploy</artifactId>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring</artifactId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
|
|
|
@ -5,72 +5,57 @@
|
|||
<!-- Configure the Jetty Server with Spring -->
|
||||
<!-- This file is the similar to jetty.xml, but written in spring -->
|
||||
<!-- XmlBeanFactory format. -->
|
||||
<!-- -->
|
||||
<!-- This file may be run with: -->
|
||||
<!-- java -jar start.jar OPTIONS=Server,spring \ -->
|
||||
<!-- start.class=org.eclipse.jetty.spring.Main \ -->
|
||||
<!-- etc/jetty-spring.xml -->
|
||||
<!-- -->
|
||||
<!-- The spring and commons-logging jars may need to be added -->
|
||||
<!-- to the classpath -->
|
||||
<!-- =============================================================== -->
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
|
||||
|
||||
<bean id="Server" name="Main" class="org.eclipse.jetty.spring.Server" init-method="start" destroy-method="stop">
|
||||
|
||||
<property name="threadPool">
|
||||
<bean id="ThreadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
|
||||
<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>
|
||||
</property>
|
||||
|
||||
</constructor-arg>
|
||||
|
||||
<property name="connectors">
|
||||
<list>
|
||||
<bean id="Connector" class="org.eclipse.jetty.server.ServerConnector">
|
||||
<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"/>
|
||||
<ref bean="contexts"/>
|
||||
<bean id="defaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
|
||||
<property name="beans">
|
||||
<list>
|
||||
<bean id="ContextDeployer" class="org.eclipse.jetty.deploy.ContextDeployer">
|
||||
<bean id="deploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
|
||||
<property name="contexts" ref="contexts"/>
|
||||
<property name="directory" value="contexts"/>
|
||||
<property name="scanInterval" value="5"/>
|
||||
<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>
|
||||
|
||||
<bean id="WebAppDeployer" class="org.eclipse.jetty.deploy.WebAppDeployer">
|
||||
<property name="contexts" ref="contexts"/>
|
||||
<property name="webAppDir" value="webapps"/>
|
||||
<property name="extract" value="true"/>
|
||||
<property name="defaultsDescriptor" value="etc/webdefault.xml"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.eclipse.jetty.security.HashLoginService">
|
||||
<property name="name" value="Test Realm"/>
|
||||
<property name="config" value="etc/realm.properties"/>
|
||||
<property name="refreshInterval" value="0"/>
|
||||
</bean>
|
||||
|
||||
</list>
|
||||
</property>
|
||||
|
||||
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -16,23 +16,19 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.spring;
|
||||
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Run Jetty from Spring configuration.
|
||||
* @see <a href="http://svn.codehaus.org/jetty/jetty/trunk/jetty-spring/src/main/config/etc/jetty-spring.xml">jetty-spring.xml</a>
|
||||
/**
|
||||
* 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]:"src/main/config/etc/jetty-spring.xml");
|
||||
XmlConfiguration.main(new String[]{config.getFile().getAbsolutePath()});
|
||||
|
||||
Resource config = Resource.newResource(args.length == 1 ? args[0] : "etc/jetty-spring.xml");
|
||||
XmlConfiguration.main(config.getFile().getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.spring;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.jetty.util.thread.ThreadPool;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Convenience class for jetty with Spring.
|
||||
* This class provides a setBeans method as an alternate
|
||||
* access to the {@link #addBean(Object)} API.
|
||||
*/
|
||||
public class Server extends org.eclipse.jetty.server.Server
|
||||
{
|
||||
public Server()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public Server(InetSocketAddress addr)
|
||||
{
|
||||
super(addr);
|
||||
}
|
||||
|
||||
public Server(int port)
|
||||
{
|
||||
super(port);
|
||||
}
|
||||
|
||||
public Server(ThreadPool pool)
|
||||
{
|
||||
super(pool);
|
||||
}
|
||||
|
||||
public void setBeans(Collection<Object> beans)
|
||||
{
|
||||
for (Object o:beans)
|
||||
addBean(o);
|
||||
}
|
||||
}
|
|
@ -22,7 +22,9 @@ package org.eclipse.jetty.spring;
|
|||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.xml.ConfigurationProcessor;
|
||||
import org.eclipse.jetty.xml.ConfigurationProcessorFactory;
|
||||
|
@ -35,61 +37,64 @@ import org.springframework.core.io.UrlResource;
|
|||
|
||||
/**
|
||||
* Spring ConfigurationProcessor
|
||||
* <p>
|
||||
* <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>
|
||||
* <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
|
||||
* and if the spring configuration file contains a definition for the singleton id, the the singleton is updated
|
||||
* with a call to {@link XmlBeanFactory#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
|
||||
* <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
|
||||
* <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
|
||||
{
|
||||
static final Logger __log = org.eclipse.jetty.util.log.Log.getLogger(SpringConfigurationProcessor.class.getName());
|
||||
|
||||
Map<String, Object> _idMap;
|
||||
Map<String, String> _propertyMap;
|
||||
XmlBeanFactory _beanFactory;
|
||||
String _main;
|
||||
private static final Logger LOG = Log.getLogger(SpringConfigurationProcessor.class);
|
||||
|
||||
private Map<String, Object> _idMap;
|
||||
private Map<String, String> _propertyMap;
|
||||
private XmlBeanFactory _beanFactory;
|
||||
private String _main;
|
||||
|
||||
public void init(URL url, XmlParser.Node config, Map<String, Object> idMap, Map<String, String> properties)
|
||||
{
|
||||
try
|
||||
{
|
||||
_idMap=idMap;
|
||||
_propertyMap=properties;
|
||||
_idMap = idMap;
|
||||
_propertyMap = properties;
|
||||
|
||||
Resource resource = (url!=null)
|
||||
?new UrlResource(url)
|
||||
: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("UTF-8"));
|
||||
|
||||
_beanFactory=new XmlBeanFactory(resource);
|
||||
|
||||
Resource resource = url != null
|
||||
? new UrlResource(url)
|
||||
: 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("UTF-8"));
|
||||
|
||||
_beanFactory = new XmlBeanFactory(resource);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Object configure(Object obj) throws Exception
|
||||
{
|
||||
doConfigure();
|
||||
return _beanFactory.configureBean(obj,_main);
|
||||
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()
|
||||
*/
|
||||
public Object configure() throws Exception
|
||||
|
@ -100,28 +105,28 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
|
|||
|
||||
private void doConfigure()
|
||||
{
|
||||
_beanFactory.registerSingleton("properties",_propertyMap);
|
||||
|
||||
_beanFactory.registerSingleton("properties", _propertyMap);
|
||||
|
||||
// Look for the main bean;
|
||||
for (String bean : _beanFactory.getBeanDefinitionNames())
|
||||
{
|
||||
__log.debug("{} - {}",bean,Arrays.asList(_beanFactory.getAliases(bean)));
|
||||
LOG.debug("{} - {}", bean, Arrays.asList(_beanFactory.getAliases(bean)));
|
||||
String[] aliases = _beanFactory.getAliases(bean);
|
||||
if ("Main".equals(bean) || aliases!=null && Arrays.asList(aliases).contains("Main"))
|
||||
if ("Main".equals(bean) || aliases != null && Arrays.asList(aliases).contains("Main"))
|
||||
{
|
||||
_main=bean;
|
||||
_main = bean;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_main==null)
|
||||
_main=_beanFactory.getBeanDefinitionNames()[0];
|
||||
|
||||
if (_main == null)
|
||||
_main = _beanFactory.getBeanDefinitionNames()[0];
|
||||
|
||||
// Register id beans as singletons
|
||||
__log.debug("idMap {}",_idMap);
|
||||
LOG.debug("idMap {}", _idMap);
|
||||
for (String id : _idMap.keySet())
|
||||
{
|
||||
__log.debug("register {}",id);
|
||||
_beanFactory.registerSingleton(id,_idMap.get(id));
|
||||
LOG.debug("register {}", id);
|
||||
_beanFactory.registerSingleton(id, _idMap.get(id));
|
||||
}
|
||||
|
||||
// Apply configuration to existing singletons
|
||||
|
@ -129,13 +134,13 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
|
|||
{
|
||||
if (_beanFactory.containsBeanDefinition(id))
|
||||
{
|
||||
__log.debug("reconfigure {}",id);
|
||||
_beanFactory.configureBean(_idMap.get(id),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));
|
||||
_idMap.put(id, _beanFactory.getBean(id));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.spring;
|
||||
|
||||
import org.eclipse.jetty.xml.ConfigurationProcessor;
|
||||
|
@ -25,12 +24,12 @@ import org.eclipse.jetty.xml.XmlConfiguration;
|
|||
|
||||
/**
|
||||
* Spring ConfigurationProcessor Factory
|
||||
* <p>
|
||||
* <p/>
|
||||
* Create a {@link SpringConfigurationProcessor} for XML documents with a "beans" element.
|
||||
* The factory is discovered by a {@link ServiceLoader} for {@link ConfigurationProcessorFactory}.
|
||||
* The factory is discovered by a {@link java.util.ServiceLoader} for {@link ConfigurationProcessorFactory}.
|
||||
*
|
||||
* @see SpringConfigurationProcessor
|
||||
* @see XmlConfiguration
|
||||
*
|
||||
*/
|
||||
public class SpringConfigurationProcessorFactory implements ConfigurationProcessorFactory
|
||||
{
|
||||
|
|
|
@ -24,13 +24,13 @@ import java.util.Map;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SpringXmlConfigurationTest
|
||||
{
|
||||
protected String _configure="org/eclipse/jetty/spring/configure.xml";
|
||||
|
@ -60,7 +60,7 @@ public class SpringXmlConfigurationTest
|
|||
URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure);
|
||||
XmlConfiguration configuration = new XmlConfiguration(url);
|
||||
|
||||
Map<String,String> properties = new HashMap<String,String>();
|
||||
Map<String,String> properties = new HashMap<>();
|
||||
properties.put("test", "xxx");
|
||||
|
||||
TestConfiguration nested = new TestConfiguration();
|
||||
|
@ -74,20 +74,20 @@ public class SpringXmlConfigurationTest
|
|||
|
||||
tc=(TestConfiguration)configuration.configure(tc);
|
||||
|
||||
assertEquals("preconfig",tc.getTestString0());
|
||||
assertEquals(42,tc.getTestInt0());
|
||||
assertEquals("SetValue",tc.getTestString1());
|
||||
assertEquals(1,tc.getTestInt1());
|
||||
Assert.assertEquals("preconfig", tc.getTestString0());
|
||||
Assert.assertEquals(42, tc.getTestInt0());
|
||||
Assert.assertEquals("SetValue", tc.getTestString1());
|
||||
Assert.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());
|
||||
Assert.assertEquals("nested", tc.getNested().getTestString0());
|
||||
Assert.assertEquals("nested", tc.getNested().getTestString1());
|
||||
Assert.assertEquals("default", tc.getNested().getNested().getTestString0());
|
||||
Assert.assertEquals("deep", tc.getNested().getNested().getTestString1());
|
||||
|
||||
assertEquals("deep",((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestString1());
|
||||
assertEquals(2,((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestInt2());
|
||||
Assert.assertEquals("deep", ((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestString1());
|
||||
Assert.assertEquals(2, ((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestInt2());
|
||||
|
||||
assertEquals("xxx",tc.getTestString2());
|
||||
Assert.assertEquals("xxx", tc.getTestString2());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -98,7 +98,7 @@ public class SpringXmlConfigurationTest
|
|||
URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure);
|
||||
XmlConfiguration configuration = new XmlConfiguration(url);
|
||||
|
||||
Map<String,String> properties = new HashMap<String,String>();
|
||||
Map<String,String> properties = new HashMap<>();
|
||||
properties.put("test", "xxx");
|
||||
|
||||
TestConfiguration nested = new TestConfiguration();
|
||||
|
@ -108,20 +108,20 @@ public class SpringXmlConfigurationTest
|
|||
configuration.getProperties().putAll(properties);
|
||||
TestConfiguration tc = (TestConfiguration)configuration.configure();
|
||||
|
||||
assertEquals("default",tc.getTestString0());
|
||||
assertEquals(-1,tc.getTestInt0());
|
||||
assertEquals("SetValue",tc.getTestString1());
|
||||
assertEquals(1,tc.getTestInt1());
|
||||
Assert.assertEquals("default", tc.getTestString0());
|
||||
Assert.assertEquals(-1, tc.getTestInt0());
|
||||
Assert.assertEquals("SetValue", tc.getTestString1());
|
||||
Assert.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());
|
||||
Assert.assertEquals("nested", tc.getNested().getTestString0());
|
||||
Assert.assertEquals("nested", tc.getNested().getTestString1());
|
||||
Assert.assertEquals("default", tc.getNested().getNested().getTestString0());
|
||||
Assert.assertEquals("deep", tc.getNested().getNested().getTestString1());
|
||||
|
||||
assertEquals("deep",((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestString1());
|
||||
assertEquals(2,((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestInt2());
|
||||
Assert.assertEquals("deep", ((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestString1());
|
||||
Assert.assertEquals(2, ((TestConfiguration)configuration.getIdMap().get("nestedDeep")).getTestInt2());
|
||||
|
||||
assertEquals("xxx",tc.getTestString2());
|
||||
Assert.assertEquals("xxx", tc.getTestString2());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -133,13 +133,11 @@ public class SpringXmlConfigurationTest
|
|||
Server server = (Server)configuration.configure();
|
||||
|
||||
server.dumpStdErr();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void XmlConfigurationMain() throws Exception
|
||||
{
|
||||
XmlConfiguration.main(new String[]{"src/test/resources/org/eclipse/jetty/spring/jetty.xml"});
|
||||
|
||||
XmlConfiguration.main("src/test/resources/org/eclipse/jetty/spring/jetty.xml");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,113 +25,131 @@ import org.junit.Ignore;
|
|||
@Ignore
|
||||
public class TestConfiguration
|
||||
{
|
||||
public static int VALUE=77;
|
||||
public static int VALUE = 77;
|
||||
|
||||
public TestConfiguration nested;
|
||||
public String testString0="default";
|
||||
public String testString0 = "default";
|
||||
public String testString1;
|
||||
public String testString2;
|
||||
public int testInt0=-1;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,30 +4,30 @@
|
|||
<beans>
|
||||
<!-- 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" singleton="false" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
|
||||
<property name="targetObject"><ref local="properties" /></property>
|
||||
<property name="targetMethod"><value>get</value></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</value></property>
|
||||
<property name="testInt1"><value>1</value></property>
|
||||
<property name="nested" ref="nested"/>
|
||||
<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</value></property>
|
||||
<property name="testString1"><value>nested</value></property>
|
||||
<property name="nested" ref="nestedDeep"/>
|
||||
<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</value></property>
|
||||
<property name="testInt2"><value>2</value></property>
|
||||
<property name="testString1" value="deep" />
|
||||
<property name="testInt2" value="2" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
|
||||
<beans>
|
||||
<bean id="Server" name="Main" class="org.eclipse.jetty.spring.Server">
|
||||
|
||||
<!--
|
||||
<property name="beans">
|
||||
<list>
|
||||
<bean id="ContextDeployer" class="org.eclipse.jetty.spring.ContextDeployer">
|
||||
<property name="contexts" ref="contexts"/>
|
||||
<property name="contextsDir" value="contexts"/>
|
||||
<property name="scanInterval" value="5"/>
|
||||
</bean>
|
||||
|
||||
<bean id="WebAppDeployer" class="org.eclipse.jetty.deploy.WebAppDeployer">
|
||||
<property name="contexts" ref="contexts"/>
|
||||
<property name="webAppDir" value="webapps"/>
|
||||
<property name="extract" value="true"/>
|
||||
<property name="defaultsDescriptor" value="etc/webdefault.xml"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.eclipse.jetty.security.HashLoginService">
|
||||
<property name="name" value="Test Realm"/>
|
||||
<property name="config" value="etc/realm.properties"/>
|
||||
<property name="refreshInterval" value="0"/>
|
||||
</bean>
|
||||
|
||||
</list>
|
||||
</property>
|
||||
-->
|
||||
|
||||
</bean>
|
||||
</beans>
|
||||
|
||||
|
|
@ -2,44 +2,42 @@
|
|||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
|
||||
<beans>
|
||||
<bean id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
|
||||
<bean id="Server" name="Main" class="org.eclipse.jetty.spring.Server">
|
||||
<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">
|
||||
<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.spring.Server"><ref bean="Server"/></constructor-arg>
|
||||
<property name="port" value="0"/>
|
||||
<bean id="connector" class="org.eclipse.jetty.server.ServerConnector">
|
||||
<constructor-arg type="org.eclipse.jetty.server.Server" 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"/>
|
||||
<ref bean="contexts"/>
|
||||
<bean id="defaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
|
||||
<property name="stopAtShutdown" value="true"/>
|
||||
<property name="sendServerVersion" value="true"/>
|
||||
<property name="sendDateHeader" value="true"/>
|
||||
<property name="stopTimeout" value="1000"/>
|
||||
<property name="dumpAfterStart" value="true"/>
|
||||
<property name="dumpBeforeStop" value="false"/>
|
||||
|
||||
|
||||
</bean>
|
||||
</beans>
|
||||
|
||||
|
|
|
@ -37,8 +37,8 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
* An unmanaged bean is associated with the aggregate for the purposes of {@link #dump()}, but it's lifecycle must be managed externally.
|
||||
* <p>
|
||||
* When a {@link LifeCycle} bean is added with out a managed state being specified, if it is already started, then it is assumed to be an unmanaged bean.
|
||||
* If it is not started then it is added in and auto managed state, which means that when this bean is itself started, it if must also start the added bean, then it
|
||||
* is switched from Auto to be a managed bean. Otherwise it becomes an unmanaged bean. Simply put an Auto bean will be stopped by this aggregate only if it
|
||||
* If it is not started then it is added in and auto managed state, which means that when this bean is itself started, it if must also start the added bean, then it
|
||||
* is switched from Auto to be a managed bean. Otherwise it becomes an unmanaged bean. Simply put an Auto bean will be stopped by this aggregate only if it
|
||||
* is started by this aggregate.
|
||||
* <p>
|
||||
* The methods {@link #addBean(Object, boolean)}, {@link #manage(Object)} and {@link #unmanage(Object)} can be used to
|
||||
|
@ -55,11 +55,11 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
private final List<Container.Listener> _listeners = new CopyOnWriteArrayList<>();
|
||||
private boolean _started = false;
|
||||
|
||||
|
||||
|
||||
public ContainerLifeCycle()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Starts the managed lifecycle beans in the order they were added.
|
||||
*/
|
||||
|
@ -99,7 +99,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
|
||||
/**
|
||||
* Starts the given lifecycle.
|
||||
*
|
||||
*
|
||||
* @param l
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -107,7 +107,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
{
|
||||
l.start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stops the managed lifecycle beans in the reverse order they were added.
|
||||
*/
|
||||
|
@ -192,7 +192,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
LifeCycle l = (LifeCycle)o;
|
||||
return addBean(o,l.isRunning()?Managed.UNMANAGED:Managed.AUTO);
|
||||
}
|
||||
|
||||
|
||||
return addBean(o,Managed.POJO);
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
for (Bean b:_beans)
|
||||
{
|
||||
listener.beanAdded(this,b._bean);
|
||||
|
||||
|
||||
// handle inheritance
|
||||
if (listener instanceof InheritedListener && b.isManaged() && b._bean instanceof Container)
|
||||
((Container)b._bean).addBean(listener);
|
||||
|
@ -236,7 +236,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
|
||||
// Add the bean
|
||||
_beans.add(new_bean);
|
||||
|
||||
|
||||
// Tell existing listeners about the new bean
|
||||
for (Container.Listener l:_listeners)
|
||||
l.beanAdded(this,o);
|
||||
|
@ -254,7 +254,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
|
||||
if (_started)
|
||||
{
|
||||
LifeCycle l = (LifeCycle)o;
|
||||
LifeCycle l = (LifeCycle)o;
|
||||
if (!l.isRunning())
|
||||
l.start();
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
case AUTO:
|
||||
if (o instanceof LifeCycle)
|
||||
{
|
||||
LifeCycle l = (LifeCycle)o;
|
||||
LifeCycle l = (LifeCycle)o;
|
||||
if (_started)
|
||||
{
|
||||
if (l.isRunning())
|
||||
|
@ -280,7 +280,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
else
|
||||
new_bean._managed=Managed.POJO;
|
||||
break;
|
||||
|
||||
|
||||
case POJO:
|
||||
new_bean._managed=Managed.POJO;
|
||||
}
|
||||
|
@ -293,9 +293,9 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
LOG.debug("{} added {}",this,new_bean);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -324,7 +324,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
if (bean._managed!=Managed.MANAGED)
|
||||
{
|
||||
bean._managed=Managed.MANAGED;
|
||||
|
||||
|
||||
if (bean._bean instanceof Container)
|
||||
{
|
||||
for (Container.Listener l:_listeners)
|
||||
|
@ -338,14 +338,14 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (bean._bean instanceof AbstractLifeCycle)
|
||||
{
|
||||
((AbstractLifeCycle)bean._bean).setStopTimeout(getStopTimeout());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unmanages a bean already contained by this aggregate, so that it is not started/stopped/destroyed with this
|
||||
* aggregate.
|
||||
|
@ -380,14 +380,19 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
bean._managed=Managed.UNMANAGED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<Object> getBeans()
|
||||
{
|
||||
return getBeans(Object.class);
|
||||
}
|
||||
|
||||
public void setBeans(Collection<Object> beans)
|
||||
{
|
||||
for (Object bean : beans)
|
||||
addBean(bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Collection<T> getBeans(Class<T> clazz)
|
||||
{
|
||||
|
@ -420,7 +425,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
for (Bean b : beans)
|
||||
remove(b);
|
||||
}
|
||||
|
||||
|
||||
private Bean getBean(Object o)
|
||||
{
|
||||
for (Bean b : _beans)
|
||||
|
@ -437,13 +442,13 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
Bean b=getBean(o);
|
||||
return b!=null && remove(b);
|
||||
}
|
||||
|
||||
|
||||
private boolean remove(Bean bean)
|
||||
{
|
||||
if (_beans.remove(bean))
|
||||
{
|
||||
unmanage(bean);
|
||||
|
||||
|
||||
for (Container.Listener l:_listeners)
|
||||
l.beanRemoved(this,bean._bean);
|
||||
|
||||
|
@ -467,7 +472,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void setStopTimeout(long stopTimeout)
|
||||
|
@ -548,7 +553,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
{
|
||||
dumpBeans(out,indent);
|
||||
}
|
||||
|
||||
|
||||
protected void dumpBeans(Appendable out, String indent, Collection<?>... collections) throws IOException
|
||||
{
|
||||
dumpThis(out);
|
||||
|
@ -564,14 +569,14 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
|
||||
switch(b._managed)
|
||||
{
|
||||
case POJO:
|
||||
case POJO:
|
||||
out.append(indent).append(" +- ");
|
||||
if (b._bean instanceof Dumpable)
|
||||
((Dumpable)b._bean).dump(out, indent + (i == size ? " " : " | "));
|
||||
else
|
||||
dumpObject(out, b._bean);
|
||||
break;
|
||||
|
||||
|
||||
case MANAGED:
|
||||
out.append(indent).append(" += ");
|
||||
if (b._bean instanceof Dumpable)
|
||||
|
@ -598,7 +603,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
|
||||
if (i<size)
|
||||
out.append(indent).append(" |\n");
|
||||
|
||||
|
||||
for (Collection<?> c : collections)
|
||||
{
|
||||
for (Object o : c)
|
||||
|
@ -639,7 +644,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum Managed { POJO, MANAGED, UNMANAGED, AUTO };
|
||||
|
||||
|
@ -657,7 +662,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
{
|
||||
return _managed==Managed.MANAGED;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
@ -675,7 +680,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
addBean(newBean);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void updateBeans(Object[] oldBeans, final Object[] newBeans)
|
||||
{
|
||||
// remove oldChildren not in newChildren
|
||||
|
@ -692,7 +697,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
|
|||
removeBean(o);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add new beans not in old
|
||||
if (newBeans!=null)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue