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

SPR9157 draft #19

Merged
merged 3 commits into from
Mar 1, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SPR-9157/SPR-9157.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
http://localhost:8080/spr9157/environments.html
http://localhost:8080/spr9157/environment.html?environment=name
90 changes: 90 additions & 0 deletions SPR-9157/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.issues</groupId>
<artifactId>spr9157</artifactId>
<version>0.1</version>
<packaging>war</packaging>
<name>SPR-9157 :: Spring3 converter</name>
<description>SPR-9157 - Spring 3 converter</description>

<properties>
<java-version>1.5</java-version>
<spring.version>3.0.7.RELEASE</spring.version>
<slf4j.version>1.6.4</slf4j.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<argLine>-Xms64m -Xmx512m -XX:MaxPermSize=128m</argLine>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.springframework.issues.spr9157.model;

/**
* Enhanced environment.
*
* @author ferengra
*/
public interface EnhancedEnvironment extends Environment {

String getDescription();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.springframework.issues.spr9157.model;

/**
* Enhanced environment implementation.
*
* @author ferengra
*/
public class EnhancedEnvironmentImpl extends EnvironmentImpl implements EnhancedEnvironment {
private String description;

@SuppressWarnings("unused")
private EnhancedEnvironmentImpl() {
// Hibernate
}

public EnhancedEnvironmentImpl(String name, String description) {
super(name);
this.description = description;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.springframework.issues.spr9157.model;

/**
* Environment.
*
* @author ferengra
*/
public interface Environment {

String getName();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.springframework.issues.spr9157.model;

/**
* Environment implementation.
*
* @author ferengra
*/
public class EnvironmentImpl implements Environment {
private Long id;
private String name;

protected EnvironmentImpl() {
// Hibernate
}

public EnvironmentImpl(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Long getId() {
return id;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof EnhancedEnvironmentImpl)) {
return false;
}
EnhancedEnvironmentImpl other = (EnhancedEnvironmentImpl) obj;
return getName().equals(other.getName());
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("EnvironmentImpl [id=").append(id).append(", name=").append(name).append("]");
return builder.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.springframework.issues.spr9157.web.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.issues.spr9157.model.EnhancedEnvironment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
* Controller for managing environment.
*
* @author ferengra
*/
@Controller
public class EnvironmentController {
private static final Logger LOG = LoggerFactory.getLogger(EnvironmentController.class);

@RequestMapping(value = "/environments.html", method = RequestMethod.GET)
public ModelAndView getEnvironments() {
LOG.debug("environments");
return new ModelAndView("environments");
}

@RequestMapping(value = "/environment.html", method = RequestMethod.GET)
public ModelAndView getEnvironment(@RequestParam EnhancedEnvironment environment) {
LOG.debug("environment: {}", environment);
ModelAndView mav = new ModelAndView("environment");
mav.addObject("environment", environment);
return mav;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.springframework.issues.spr9157.web.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.converter.Converter;
import org.springframework.issues.spr9157.model.EnhancedEnvironmentImpl;
import org.springframework.issues.spr9157.model.Environment;
import org.springframework.util.StringUtils;

/**
* Environment converter.
*
* @author ferengra
*/
public class EnvironmentConverter implements Converter<String, Environment> {
private static final Logger LOG = LoggerFactory.getLogger(EnvironmentConverter.class);

public Environment convert(String source) {
LOG.debug("source: {}", source);
if (!StringUtils.hasText(source)) {
return null;
}
return new EnhancedEnvironmentImpl(source.trim(), source.trim());
}
}
78 changes: 78 additions & 0 deletions SPR-9157/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<!-- Makes the logger system available via JMX -->
<jmxConfigurator />

<!-- Auto-define an appender that sends the console messages to the Logback Eclipse console plugin -->
<!-- <consolePlugin /> -->

<!-- APPENDERS -->

<!-- A debug file appender -->
<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>C:\\Temp\\logDebug.log</file>

<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<FileNamePattern>${logback.debugFile}.%i.log</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>5</MaxIndex>
</rollingPolicy>

<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>20MB</MaxFileSize>
</triggeringPolicy>

<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%date %-5level %logger [%thread] [%file : %line] - %msg%n</Pattern>
</layout>
</appender>

<!-- An error file appender -->
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>

<file>C:\\Temp\\logError.log</file>

<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<FileNamePattern>${logback.errorFile}.%i.log</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>2</MaxIndex>
</rollingPolicy>

<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>20MB</MaxFileSize>
</triggeringPolicy>

<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%date %-5level %logger [%thread] [%file : %line] - %msg%n</Pattern>
</layout>
</appender>

<!-- An appender that sends the messages to console -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%date %-5level %logger{36} [%thread] [%file : %line] - %msg%n</Pattern>
</layout>
</appender>

<!-- LOGGERS -->

<!-- The root logger sends the messages > INFO to all the appenders (the ERROR_FILE filters internally only to WARNS and ERRORS)-->
<root level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="DEBUG_FILE" />
<appender-ref ref="ERROR_FILE" />
<!-- <appender-ref ref="lilithMultiplex" /> -->
</root>

<!-- The root logger sends all the messages coming from package com.kiko.store to the appenders inherited from the ROOT logger-->
<logger name="hu.ferengra" level="ALL">
</logger>

<logger name="org.springframework" level="ALL">
</logger>

</configuration>
5 changes: 5 additions & 0 deletions SPR-9157/src/main/webapp/WEB-INF/applicationContext.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

</beans>
Loading