Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 990eadf

Browse files
committed
Merge pull request #19 from ferengra/master
SPR9157 draft
2 parents 83dfd04 + bd89ae9 commit 990eadf

16 files changed

+528
-0
lines changed

SPR-9157/SPR-9157.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
http://localhost:8080/spr9157/environments.html
2+
http://localhost:8080/spr9157/environment.html?environment=name

SPR-9157/pom.xml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.springframework.issues</groupId>
5+
<artifactId>spr9157</artifactId>
6+
<version>0.1</version>
7+
<packaging>war</packaging>
8+
<name>SPR-9157 :: Spring3 converter</name>
9+
<description>SPR-9157 - Spring 3 converter</description>
10+
11+
<properties>
12+
<java-version>1.5</java-version>
13+
<spring.version>3.0.7.RELEASE</spring.version>
14+
<slf4j.version>1.6.4</slf4j.version>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework</groupId>
20+
<artifactId>spring-webmvc</artifactId>
21+
<version>${spring.version}</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.slf4j</groupId>
25+
<artifactId>slf4j-api</artifactId>
26+
<version>${slf4j.version}</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>ch.qos.logback</groupId>
30+
<artifactId>logback-classic</artifactId>
31+
<version>1.0.0</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>javax.servlet</groupId>
35+
<artifactId>servlet-api</artifactId>
36+
<version>2.4</version>
37+
<scope>provided</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>javax.servlet.jsp</groupId>
41+
<artifactId>jsp-api</artifactId>
42+
<version>2.0</version>
43+
<scope>provided</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>javax.servlet</groupId>
47+
<artifactId>jstl</artifactId>
48+
<version>1.1.2</version>
49+
</dependency>
50+
</dependencies>
51+
<build>
52+
<plugins>
53+
<plugin>
54+
<artifactId>maven-compiler-plugin</artifactId>
55+
<version>2.3.2</version>
56+
<configuration>
57+
<source>${java-version}</source>
58+
<target>${java-version}</target>
59+
</configuration>
60+
</plugin>
61+
<plugin>
62+
<artifactId>maven-jar-plugin</artifactId>
63+
<version>2.3.1</version>
64+
</plugin>
65+
<plugin>
66+
<artifactId>maven-source-plugin</artifactId>
67+
<version>2.1.2</version>
68+
<executions>
69+
<execution>
70+
<id>attach-sources</id>
71+
<goals>
72+
<goal>jar</goal>
73+
</goals>
74+
</execution>
75+
</executions>
76+
</plugin>
77+
<plugin>
78+
<artifactId>maven-surefire-plugin</artifactId>
79+
<version>2.11</version>
80+
<configuration>
81+
<argLine>-Xms64m -Xmx512m -XX:MaxPermSize=128m</argLine>
82+
</configuration>
83+
</plugin>
84+
<plugin>
85+
<artifactId>maven-war-plugin</artifactId>
86+
<version>2.1.1</version>
87+
</plugin>
88+
</plugins>
89+
</build>
90+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.springframework.issues.spr9157.model;
2+
3+
/**
4+
* Enhanced environment.
5+
*
6+
* @author ferengra
7+
*/
8+
public interface EnhancedEnvironment extends Environment {
9+
10+
String getDescription();
11+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.springframework.issues.spr9157.model;
2+
3+
/**
4+
* Enhanced environment implementation.
5+
*
6+
* @author ferengra
7+
*/
8+
public class EnhancedEnvironmentImpl extends EnvironmentImpl implements EnhancedEnvironment {
9+
private String description;
10+
11+
@SuppressWarnings("unused")
12+
private EnhancedEnvironmentImpl() {
13+
// Hibernate
14+
}
15+
16+
public EnhancedEnvironmentImpl(String name, String description) {
17+
super(name);
18+
this.description = description;
19+
}
20+
21+
public String getDescription() {
22+
return description;
23+
}
24+
25+
public void setDescription(String description) {
26+
this.description = description;
27+
}
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.springframework.issues.spr9157.model;
2+
3+
/**
4+
* Environment.
5+
*
6+
* @author ferengra
7+
*/
8+
public interface Environment {
9+
10+
String getName();
11+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.springframework.issues.spr9157.model;
2+
3+
/**
4+
* Environment implementation.
5+
*
6+
* @author ferengra
7+
*/
8+
public class EnvironmentImpl implements Environment {
9+
private Long id;
10+
private String name;
11+
12+
protected EnvironmentImpl() {
13+
// Hibernate
14+
}
15+
16+
public EnvironmentImpl(String name) {
17+
this.name = name;
18+
}
19+
20+
public String getName() {
21+
return name;
22+
}
23+
24+
public void setName(String name) {
25+
this.name = name;
26+
}
27+
28+
public Long getId() {
29+
return id;
30+
}
31+
32+
@Override
33+
public int hashCode() {
34+
final int prime = 31;
35+
int result = 1;
36+
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
37+
return result;
38+
}
39+
40+
@Override
41+
public boolean equals(Object obj) {
42+
if (this == obj) {
43+
return true;
44+
}
45+
if (!(obj instanceof EnhancedEnvironmentImpl)) {
46+
return false;
47+
}
48+
EnhancedEnvironmentImpl other = (EnhancedEnvironmentImpl) obj;
49+
return getName().equals(other.getName());
50+
}
51+
52+
@Override
53+
public String toString() {
54+
StringBuilder builder = new StringBuilder();
55+
builder.append("EnvironmentImpl [id=").append(id).append(", name=").append(name).append("]");
56+
return builder.toString();
57+
}
58+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.springframework.issues.spr9157.web.controller;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.issues.spr9157.model.EnhancedEnvironment;
6+
import org.springframework.stereotype.Controller;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RequestMethod;
9+
import org.springframework.web.bind.annotation.RequestParam;
10+
import org.springframework.web.servlet.ModelAndView;
11+
12+
/**
13+
* Controller for managing environment.
14+
*
15+
* @author ferengra
16+
*/
17+
@Controller
18+
public class EnvironmentController {
19+
private static final Logger LOG = LoggerFactory.getLogger(EnvironmentController.class);
20+
21+
@RequestMapping(value = "/environments.html", method = RequestMethod.GET)
22+
public ModelAndView getEnvironments() {
23+
LOG.debug("environments");
24+
return new ModelAndView("environments");
25+
}
26+
27+
@RequestMapping(value = "/environment.html", method = RequestMethod.GET)
28+
public ModelAndView getEnvironment(@RequestParam EnhancedEnvironment environment) {
29+
LOG.debug("environment: {}", environment);
30+
ModelAndView mav = new ModelAndView("environment");
31+
mav.addObject("environment", environment);
32+
return mav;
33+
}
34+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.springframework.issues.spr9157.web.util;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.core.convert.converter.Converter;
6+
import org.springframework.issues.spr9157.model.EnhancedEnvironmentImpl;
7+
import org.springframework.issues.spr9157.model.Environment;
8+
import org.springframework.util.StringUtils;
9+
10+
/**
11+
* Environment converter.
12+
*
13+
* @author ferengra
14+
*/
15+
public class EnvironmentConverter implements Converter<String, Environment> {
16+
private static final Logger LOG = LoggerFactory.getLogger(EnvironmentConverter.class);
17+
18+
public Environment convert(String source) {
19+
LOG.debug("source: {}", source);
20+
if (!StringUtils.hasText(source)) {
21+
return null;
22+
}
23+
return new EnhancedEnvironmentImpl(source.trim(), source.trim());
24+
}
25+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
4+
<!-- Makes the logger system available via JMX -->
5+
<jmxConfigurator />
6+
7+
<!-- Auto-define an appender that sends the console messages to the Logback Eclipse console plugin -->
8+
<!-- <consolePlugin /> -->
9+
10+
<!-- APPENDERS -->
11+
12+
<!-- A debug file appender -->
13+
<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
14+
<file>C:\\Temp\\logDebug.log</file>
15+
16+
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
17+
<FileNamePattern>${logback.debugFile}.%i.log</FileNamePattern>
18+
<MinIndex>1</MinIndex>
19+
<MaxIndex>5</MaxIndex>
20+
</rollingPolicy>
21+
22+
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
23+
<MaxFileSize>20MB</MaxFileSize>
24+
</triggeringPolicy>
25+
26+
<layout class="ch.qos.logback.classic.PatternLayout">
27+
<Pattern>%date %-5level %logger [%thread] [%file : %line] - %msg%n</Pattern>
28+
</layout>
29+
</appender>
30+
31+
<!-- An error file appender -->
32+
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
33+
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
34+
<level>WARN</level>
35+
</filter>
36+
37+
<file>C:\\Temp\\logError.log</file>
38+
39+
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
40+
<FileNamePattern>${logback.errorFile}.%i.log</FileNamePattern>
41+
<MinIndex>1</MinIndex>
42+
<MaxIndex>2</MaxIndex>
43+
</rollingPolicy>
44+
45+
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
46+
<MaxFileSize>20MB</MaxFileSize>
47+
</triggeringPolicy>
48+
49+
<layout class="ch.qos.logback.classic.PatternLayout">
50+
<Pattern>%date %-5level %logger [%thread] [%file : %line] - %msg%n</Pattern>
51+
</layout>
52+
</appender>
53+
54+
<!-- An appender that sends the messages to console -->
55+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
56+
<layout class="ch.qos.logback.classic.PatternLayout">
57+
<Pattern>%date %-5level %logger{36} [%thread] [%file : %line] - %msg%n</Pattern>
58+
</layout>
59+
</appender>
60+
61+
<!-- LOGGERS -->
62+
63+
<!-- The root logger sends the messages > INFO to all the appenders (the ERROR_FILE filters internally only to WARNS and ERRORS)-->
64+
<root level="INFO">
65+
<appender-ref ref="STDOUT" />
66+
<appender-ref ref="DEBUG_FILE" />
67+
<appender-ref ref="ERROR_FILE" />
68+
<!-- <appender-ref ref="lilithMultiplex" /> -->
69+
</root>
70+
71+
<!-- The root logger sends all the messages coming from package com.kiko.store to the appenders inherited from the ROOT logger-->
72+
<logger name="hu.ferengra" level="ALL">
73+
</logger>
74+
75+
<logger name="org.springframework" level="ALL">
76+
</logger>
77+
78+
</configuration>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
3+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
4+
5+
</beans>

0 commit comments

Comments
 (0)