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

Commit b7ea3de

Browse files
Ferenc GratzerFerenc Gratzer
Ferenc Gratzer
authored and
Ferenc Gratzer
committed
Add project for SPR9157
1 parent 4a9d255 commit b7ea3de

File tree

12 files changed

+448
-0
lines changed

12 files changed

+448
-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.6</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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.springframework.issues.spr9157;
2+
3+
/**
4+
* Environment.
5+
*/
6+
public class Environment {
7+
private Long id;
8+
private String name;
9+
10+
@SuppressWarnings("unused")
11+
private Environment() {
12+
// Hibernate
13+
}
14+
15+
public Environment(String name) {
16+
this.name = name;
17+
}
18+
19+
public String getName() {
20+
return name;
21+
}
22+
23+
public void setName(String name) {
24+
this.name = name;
25+
}
26+
27+
public Long getId() {
28+
return id;
29+
}
30+
31+
@Override
32+
public int hashCode() {
33+
final int prime = 31;
34+
int result = 1;
35+
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
36+
return result;
37+
}
38+
39+
@Override
40+
public boolean equals(Object obj) {
41+
if (this == obj) {
42+
return true;
43+
}
44+
if (!(obj instanceof Environment)) {
45+
return false;
46+
}
47+
Environment other = (Environment) obj;
48+
return getName().equals(other.getName());
49+
}
50+
51+
@Override
52+
public String toString() {
53+
StringBuilder builder = new StringBuilder();
54+
builder.append("Environment [id=").append(id).append(", name=").append(name).append("]");
55+
return builder.toString();
56+
}
57+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.springframework.issues.spr9157.web.controller;
2+
3+
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
import org.springframework.issues.spr9157.Environment;
7+
import org.springframework.stereotype.Controller;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RequestMethod;
10+
import org.springframework.web.bind.annotation.RequestParam;
11+
import org.springframework.web.servlet.ModelAndView;
12+
13+
/**
14+
* Controller for managing environment.
15+
*/
16+
@Controller
17+
public class EnvironmentController {
18+
private static final Logger LOG = LoggerFactory.getLogger(EnvironmentController.class);
19+
20+
@RequestMapping(value = "/environments.html", method = RequestMethod.GET)
21+
public ModelAndView getEnvironments() {
22+
LOG.debug("environments");
23+
return new ModelAndView("environments");
24+
}
25+
26+
@RequestMapping(value = "/environment.html", method = RequestMethod.GET)
27+
public ModelAndView getEnvironment(@RequestParam Environment environment) {
28+
LOG.debug("environment: {}", environment);
29+
ModelAndView mav = new ModelAndView("environment");
30+
mav.addObject("environment", environment);
31+
return mav;
32+
}
33+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.springframework.issues.spr9157.web.util;
2+
3+
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
import org.springframework.core.convert.converter.Converter;
7+
import org.springframework.issues.spr9157.Environment;
8+
import org.springframework.util.StringUtils;
9+
10+
/**
11+
* Environment converter.
12+
*/
13+
public class EnvironmentConverter implements Converter<String, Environment> {
14+
private static final Logger LOG = LoggerFactory.getLogger(EnvironmentConverter.class);
15+
16+
public Environment convert(String source) {
17+
LOG.debug("source: {}", source);
18+
if (!StringUtils.hasText(source)) {
19+
return null;
20+
}
21+
return new Environment(source.trim());
22+
}
23+
}
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>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
4+
xmlns:util="http://www.springframework.org/schema/util" xmlns:security="http://www.springframework.org/schema/security"
5+
xsi:schemaLocation="
6+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
7+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
8+
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
9+
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
10+
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
11+
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
12+
13+
<context:component-scan base-package="org.springframework.issues.spr9157.web" use-default-filters="false">
14+
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
15+
</context:component-scan>
16+
17+
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
18+
<property name="alwaysUseFullPath" value="true" />
19+
</bean>
20+
21+
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
22+
<property name="cacheSeconds" value="0" />
23+
<property name="webBindingInitializer">
24+
<bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
25+
<property name="conversionService" ref="conversionService" />
26+
</bean>
27+
</property>
28+
<property name="alwaysUseFullPath" value="true" />
29+
</bean>
30+
31+
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
32+
<property name="order" value="0" />
33+
</bean>
34+
35+
<!-- Resolves logical view names to JSP views -->
36+
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
37+
<property name="order" value="1" />
38+
<property name="prefix" value="/WEB-INF/views/" />
39+
<property name="suffix" value=".jsp" />
40+
</bean>
41+
42+
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
43+
<property name="converters">
44+
<set>
45+
<bean class="org.springframework.issues.spr9157.web.util.EnvironmentConverter" />
46+
</set>
47+
</property>
48+
</bean>
49+
</beans>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
3+
4+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5+
<head>
6+
<title>Spring 3 Converter</title>
7+
</head>
8+
Environment: <%= request.getAttribute("environment") %>
9+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2+
<jsp:text>
3+
<![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ]]>
4+
</jsp:text>
5+
6+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7+
<head>
8+
<title>Spring 3 Converter</title>
9+
</head>
10+
Environments
11+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2+
<jsp:text>
3+
<![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ]]>
4+
</jsp:text>
5+
6+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7+
<head>
8+
<title>Spring 3 Converter</title>
9+
</head>
10+
Index
11+
</html>

0 commit comments

Comments
 (0)