Project

General

Profile

« Previous | Next » 

Revision 30270

[maven-release-plugin] copy for tag dnet-runtime-1.0.0

View differences:

modules/dnet-runtime/tags/dnet-runtime-1.0.0/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-runtime/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "dnet-runtime"}
modules/dnet-runtime/tags/dnet-runtime-1.0.0/src/main/java/eu/dnetlib/conf/PropertyFetcher.java
1
package eu.dnetlib.conf;
2

  
3
import java.util.Map.Entry;
4
import java.util.Properties;
5

  
6
import org.apache.commons.logging.Log;
7
import org.apache.commons.logging.LogFactory;
8
import org.springframework.beans.BeansException;
9
import org.springframework.beans.factory.InitializingBean;
10
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
11
import org.springframework.beans.factory.config.PropertyResourceConfigurer;
12

  
13
/**
14
 * PropertyFletcher
15
 * 
16
 * @author marko
17
 * 
18
 */
19
public class PropertyFetcher extends PropertyResourceConfigurer implements InitializingBean {
20

  
21
	private static final Log log = LogFactory.getLog(PropertyFetcher.class); // NOPMD by marko on 11/24/08 5:02 PM
22

  
23
	boolean unchangedHostname = false;
24
	boolean unchangedPort = true;
25

  
26
	private Properties props;
27

  
28
	@Override
29
	public void afterPropertiesSet() throws Exception {
30
		this.props = mergeProperties();
31

  
32
		// Convert the merged properties, if necessary.
33
		convertProperties(props);
34

  
35
		log.debug("FOUND A container.hostname property " + props.getProperty("container.hostname"));
36

  
37
		if ("localhost".equals(props.getProperty("container.hostname"))) {
38
			unchangedHostname = true;
39
		}
40
		if (props.getProperty("container.port") != null) {
41
			log.debug("FOUND A container.port property " + props.getProperty("container.port"));
42
			unchangedPort = false;
43
		}
44

  
45
		if (log.isDebugEnabled()) {
46
			log.debug("HOST unchanged? " + unchangedHostname);
47
			log.debug("PORT unchanged? " + unchangedPort);
48
			for (Entry<?, ?> e : props.entrySet()) {
49
				log.debug("system property: " + e.getKey() + " --> " + e.getValue());
50
			}
51
		}
52
	}
53

  
54
	@Override
55
	protected void processProperties(final ConfigurableListableBeanFactory arg0, final Properties props) throws BeansException {
56

  
57
	}
58

  
59
	public boolean isUnchangedHostname() {
60
		return unchangedHostname;
61
	}
62

  
63
	public void setUnchangedHostname(final boolean unchangedHostname) {
64
		this.unchangedHostname = unchangedHostname;
65
	}
66

  
67
	public boolean isUnchangedPort() {
68
		return unchangedPort;
69
	}
70

  
71
	public void setUnchangedPort(final boolean unchangedPort) {
72
		this.unchangedPort = unchangedPort;
73
	}
74

  
75
	public String getProperty(final String key) {
76
		return props.getProperty(key);
77
	}
78

  
79
	public Properties getProps() {
80
		return props;
81
	}
82

  
83
	public void setProps(final Properties props) {
84
		this.props = props;
85
	}
86

  
87
}
modules/dnet-runtime/tags/dnet-runtime-1.0.0/src/main/java/eu/dnetlib/conf/WebappContextPropertyLocationFactory.java
1
package eu.dnetlib.conf;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import org.apache.commons.logging.Log;
7
import org.apache.commons.logging.LogFactory;
8
import org.springframework.beans.factory.FactoryBean;
9

  
10
/**
11
 * This class wraps a list of property file paths and expands the @{webapp} placeholder with the name of the webapp taken from servlet-api
12
 * 2.5.
13
 * 
14
 * @author marko
15
 * 
16
 */
17
public class WebappContextPropertyLocationFactory extends AbstractWebappContextProperty implements FactoryBean<List<String>> {
18

  
19
	/**
20
	 * logger.
21
	 */
22
	private static final Log log = LogFactory.getLog(WebappContextPropertyLocationFactory.class); // NOPMD by marko on 11/24/08 5:02 PM
23

  
24
	private List<String> locations;
25

  
26
	@Override
27
	public List<String> getObject() throws Exception {
28
		List<String> expanded = new ArrayList<String>();
29

  
30
		for (String loc : locations) {
31
			expanded.add(expand(loc).trim());
32
		}
33

  
34
		if (log.isInfoEnabled()) {
35
			for (String location : expanded) {
36
				log.info("Searching property file: " + location);
37
			}
38
		}
39

  
40
		return expanded;
41
	}
42

  
43
	private String expand(final String loc) {
44
		if (getContext() == null) return loc;
45
		return loc.replace("@{webapp}", getContext());
46
	}
47

  
48
	@Override
49
	public Class<?> getObjectType() {
50
		return locations.getClass();
51
	}
52

  
53
	@Override
54
	public boolean isSingleton() {
55
		return true;
56
	}
57

  
58
	public List<String> getLocations() {
59
		return locations;
60
	}
61

  
62
	public void setLocations(final List<String> locations) {
63
		this.locations = locations;
64
	}
65

  
66
}
modules/dnet-runtime/tags/dnet-runtime-1.0.0/src/main/java/eu/dnetlib/conf/AbstractWebappContextProperty.java
1
package eu.dnetlib.conf;
2

  
3
import javax.servlet.ServletContext;
4

  
5
import org.apache.commons.logging.Log;
6
import org.apache.commons.logging.LogFactory;
7
import org.springframework.web.context.ServletContextAware;
8

  
9
/**
10
 * This spring bean detects the webapp context path, from the ServletContext. It requires servlet-api 2.5 (tomcat6 and
11
 * jetty 6.x).
12
 *
13
 * <p>
14
 * Concrete subclasses will know what to do with this information
15
 * </p>
16
 *
17
 * @author marko
18
 *
19
 */
20
public abstract class AbstractWebappContextProperty implements ServletContextAware {
21

  
22
	/**
23
	 * logger.
24
	 */
25
	private static final Log log = LogFactory.getLog(AbstractWebappContextProperty.class); // NOPMD by marko on 11/24/08 5:02 PM
26

  
27
	/**
28
	 * web application context.
29
	 */
30
	protected String context;
31

  
32
	/**
33
	 * saved servlet context.
34
	 */
35
	protected ServletContext servletContext;
36

  
37
	@Override
38
	public void setServletContext(final ServletContext servletContext) {
39
		this.servletContext = servletContext;
40

  
41
		try {
42
			context = servletContext.getContextPath().substring(1);
43
		} catch (final NoSuchMethodError e) {
44
			log.warn("cannot detect servlet context path. servlet-api 2.5 is required, falling back to property based configuration", e);
45
		}
46
	}
47

  
48
	public String getContext() {
49
		return context;
50
	}
51

  
52
	public void setContext(final String context) {
53
		this.context = context;
54
	}
55

  
56
	public ServletContext getServletContext() {
57
		return servletContext;
58
	}
59

  
60
}
modules/dnet-runtime/tags/dnet-runtime-1.0.0/src/main/java/eu/dnetlib/conf/WebappContextProperyFactory.java
1
package eu.dnetlib.conf;
2

  
3
import java.net.InetAddress;
4
import java.net.UnknownHostException;
5
import java.util.Properties;
6

  
7
import javax.servlet.ServletContext;
8

  
9
import org.apache.catalina.Container;
10
import org.apache.catalina.connector.Connector;
11
import org.apache.catalina.core.StandardContext;
12
import org.apache.catalina.core.StandardEngine;
13
import org.apache.commons.lang.reflect.FieldUtils;
14
import org.apache.commons.logging.Log;
15
import org.apache.commons.logging.LogFactory;
16
import org.springframework.beans.factory.FactoryBean;
17
import org.springframework.beans.factory.annotation.Required;
18

  
19
/**
20
 * This factory generates default properties based on the amount of information available from the servlet container.
21
 * 
22
 * @author marko
23
 * 
24
 */
25
public class WebappContextProperyFactory extends AbstractWebappContextProperty implements FactoryBean<Properties> {
26

  
27
	/**
28
	 * logger.
29
	 */
30
	private static final Log log = LogFactory.getLog(WebappContextProperyFactory.class); // NOPMD by marko on
31
																							// 11/24/08 5:02 PM
32

  
33
	/**
34
	 * If false, the ip address will be returned, otherwise a best effort attemp will be made to retrieve a meaningful host name. There is a
35
	 * risk that the hostname is obtained without domain and thus completely useless.
36
	 */
37
	private boolean resolveHostname = false;
38

  
39
	private PropertyFetcher propertyFetcher;
40

  
41
	@Override
42
	public Properties getObject() throws Exception {
43
		Properties props = new Properties();
44

  
45
		if (getContext() == null) return props;
46

  
47
		props.setProperty("container.context", getContext());
48

  
49
		log.debug("trying to autodetect port and hostame");
50

  
51
		// if the user didn't customize, then autodetect, otherwise honour the
52
		// user!
53
		if (propertyFetcher.isUnchangedPort()) {
54
			log.debug("PORT IS NOT OVERRIDDEN, autodetecting");
55
			int port = getPort(getServletContext());
56
			if (port > 0) {
57
				props.setProperty("container.port", Integer.toString(port));
58
			}
59
		} else {
60
			log.debug("PORT IS OVERRIDDEN, NOT autodetecting");
61
		}
62

  
63
		if (propertyFetcher.isUnchangedHostname()) {
64
			log.debug("HOST IS NOT OVERRIDDEN, autodetecting");
65
			String hostname = getHost(getServletContext());
66
			if (hostname != null) {
67
				props.setProperty("container.hostname", hostname);
68
			}
69
		} else {
70
			log.debug("HOST IS OVERRIDDEN, NOT autodetecting");
71
		}
72

  
73
		return props;
74
	}
75

  
76
	@Override
77
	public Class<?> getObjectType() {
78
		return Properties.class;
79
	}
80

  
81
	@Override
82
	public boolean isSingleton() {
83
		return true;
84
	}
85

  
86
	private int getPort(final ServletContext servletContext) {
87
		try {
88
			return getContainerPort(servletContext);
89
		} catch (Throwable e) {
90
			log.warn("cannot obtain port from container...strange: I thought it would work both on jetty and tomcat7...)", e);
91
			return 0;
92
		}
93
	}
94

  
95
	private int getContainerPort(final ServletContext servletContext) {
96
		try {
97
			Object o = FieldUtils.readField(servletContext, "context", true);
98
			StandardContext sCtx = (StandardContext) FieldUtils.readField(o, "context", true);
99
			Container container = sCtx;
100

  
101
			Container c = container.getParent();
102
			while ((c != null) && !(c instanceof StandardEngine)) {
103
				c = c.getParent();
104
			}
105

  
106
			if (c != null) {
107
				StandardEngine engine = (StandardEngine) c;
108
				for (Connector connector : engine.getService().findConnectors()) {
109
					if (connector.getPort() > 0) return connector.getPort();
110
				}
111
			}
112
		} catch (Exception e) {
113
			e.printStackTrace();
114
		}
115
		return 0;
116
	}
117

  
118
	private String getHost(final ServletContext servletContext) {
119
		try {
120
			if (resolveHostname) return InetAddress.getLocalHost().getCanonicalHostName();
121
			else return InetAddress.getLocalHost().toString().split("/")[1];
122
		} catch (UnknownHostException e) {
123
			log.warn("cannot obtain hostname from JVM", e);
124
		}
125

  
126
		return null;
127
	}
128

  
129
	public boolean isResolveHostname() {
130
		return resolveHostname;
131
	}
132

  
133
	public void setResolveHostname(final boolean resolveHostname) {
134
		this.resolveHostname = resolveHostname;
135
	}
136

  
137
	public PropertyFetcher getPropertyFetcher() {
138
		return propertyFetcher;
139
	}
140

  
141
	@Required
142
	public void setPropertyFetcher(final PropertyFetcher propertyFetcher) {
143
		this.propertyFetcher = propertyFetcher;
144
	}
145

  
146
}
modules/dnet-runtime/tags/dnet-runtime-1.0.0/src/main/resources/META-INF/jax-ws-catalog.xml
1
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
2
    <rewriteSystem systemIdStartString="http://www.w3.org/2006/03/addressing" rewritePrefix="classpath:/schemas/wsdl"/>
3
</catalog>
modules/dnet-runtime/tags/dnet-runtime-1.0.0/src/main/resources/eu/dnetlib/applicationContext-defaultProperties.properties
1
transport.soap.baseAddress = http://${container.hostname}:${container.port}/${container.context}/services
modules/dnet-runtime/tags/dnet-runtime-1.0.0/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<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">
3
	<parent>
4
		<groupId>eu.dnetlib</groupId>
5
		<artifactId>dnet-parent</artifactId>
6
		<version>1.0.0</version>
7
		<relativePath />
8
	</parent>
9
	<modelVersion>4.0.0</modelVersion>
10
	<groupId>eu.dnetlib</groupId>
11
	<artifactId>dnet-runtime</artifactId>
12
	<packaging>jar</packaging>
13
	<version>1.0.0</version>
14
	<scm>
15
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-runtime/tags/dnet-runtime-1.0.0</developerConnection>
16
	</scm>
17
	
18
	<dependencies>
19
		<!-- Do not remove these dependencies, even if they look like they are 
20
			unused other modules expect them to be here -->
21
		<dependency>
22
			<groupId>org.apache.cxf</groupId>
23
			<artifactId>cxf-api</artifactId>
24
			<version>${cxf.version}</version>
25
		</dependency>
26
		<dependency>
27
			<groupId>org.apache.cxf</groupId>
28
			<artifactId>cxf-rt-core</artifactId>
29
			<version>${cxf.version}</version>
30
		</dependency>
31
		<dependency>
32
			<groupId>org.apache.cxf</groupId>
33
			<artifactId>cxf-rt-bindings-soap</artifactId>
34
			<version>${cxf.version}</version>
35
		</dependency>
36
		<dependency>
37
			<groupId>org.apache.cxf</groupId>
38
			<artifactId>cxf-rt-transports-http</artifactId>
39
			<version>${cxf.version}</version>
40
		</dependency>
41
		<dependency>
42
			<groupId>org.apache.cxf</groupId>
43
			<artifactId>cxf-rt-frontend-jaxws</artifactId>
44
			<version>${cxf.version}</version>
45
		</dependency>
46
		<dependency>
47
			<groupId>commons-lang</groupId>
48
			<artifactId>commons-lang</artifactId>
49
			<version>${commons.lang.version}</version>
50
		</dependency>
51
		<dependency>
52
			<groupId>org.springframework</groupId>
53
			<artifactId>spring-web</artifactId>
54
			<version>${spring.version}</version>
55
		</dependency>
56
		<dependency>
57
			<groupId>javax.servlet</groupId>
58
			<artifactId>javax.servlet-api</artifactId>
59
			<version>${javax.servlet.version}</version>
60
			<scope>provided</scope>
61
		</dependency>
62
		
63
		<!-- For tomcat7 -->
64
		<dependency>
65
			<groupId>org.apache.tomcat</groupId>
66
			<artifactId>tomcat-catalina</artifactId>
67
			<version>7.0.47</version>
68
			<scope>provided</scope>
69
		</dependency>
70

  
71
	</dependencies>
72
</project>

Also available in: Unified diff