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

Commit b309ee7

Browse files
ferengraferengra
ferengra
authored and
ferengra
committed
Error in GenericConversionService.ConverterAdapter
1 parent b7ea3de commit b309ee7

File tree

10 files changed

+145
-8
lines changed

10 files changed

+145
-8
lines changed

SPR-9157/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<description>SPR-9157 - Spring 3 converter</description>
1010

1111
<properties>
12-
<java-version>1.6</java-version>
12+
<java-version>1.5</java-version>
1313
<spring.version>3.0.7.RELEASE</spring.version>
1414
<slf4j.version>1.6.4</slf4j.version>
1515
</properties>
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+
}

SPR-9157/src/main/java/org/springframework/issues/spr9157/web/controller/EnvironmentController.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.springframework.issues.spr9157.web.controller;
22

3-
43
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
6-
import org.springframework.issues.spr9157.Environment;
5+
import org.springframework.issues.spr9157.model.EnhancedEnvironment;
76
import org.springframework.stereotype.Controller;
87
import org.springframework.web.bind.annotation.RequestMapping;
98
import org.springframework.web.bind.annotation.RequestMethod;
@@ -12,6 +11,8 @@
1211

1312
/**
1413
* Controller for managing environment.
14+
*
15+
* @author ferengra
1516
*/
1617
@Controller
1718
public class EnvironmentController {
@@ -24,7 +25,7 @@ public ModelAndView getEnvironments() {
2425
}
2526

2627
@RequestMapping(value = "/environment.html", method = RequestMethod.GET)
27-
public ModelAndView getEnvironment(@RequestParam Environment environment) {
28+
public ModelAndView getEnvironment(@RequestParam EnhancedEnvironment environment) {
2829
LOG.debug("environment: {}", environment);
2930
ModelAndView mav = new ModelAndView("environment");
3031
mav.addObject("environment", environment);
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package org.springframework.issues.spr9157.web.util;
22

3-
43
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
65
import org.springframework.core.convert.converter.Converter;
7-
import org.springframework.issues.spr9157.Environment;
6+
import org.springframework.issues.spr9157.model.EnhancedEnvironmentImpl;
7+
import org.springframework.issues.spr9157.model.Environment;
88
import org.springframework.util.StringUtils;
99

1010
/**
1111
* Environment converter.
12+
*
13+
* @author ferengra
1214
*/
1315
public class EnvironmentConverter implements Converter<String, Environment> {
1416
private static final Logger LOG = LoggerFactory.getLogger(EnvironmentConverter.class);
@@ -18,6 +20,6 @@ public Environment convert(String source) {
1820
if (!StringUtils.hasText(source)) {
1921
return null;
2022
}
21-
return new Environment(source.trim());
23+
return new EnhancedEnvironmentImpl(source.trim(), source.trim());
2224
}
2325
}

SPR-9157/src/main/webapp/WEB-INF/spr9157-servlet.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,9 @@
4646
</set>
4747
</property>
4848
</bean>
49+
50+
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
51+
<property name="defaultErrorView" value="errorInternal" />
52+
<property name="warnLogCategory" value="spr9157" />
53+
</bean>
4954
</beans>

SPR-9157/src/main/webapp/WEB-INF/views/environment.jsp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
21
<%@ 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>
35

46
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
57
<head>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2+
<%@ page isErrorPage="true" %>
3+
<%@ page import="org.slf4j.LoggerFactory" %>
4+
<jsp:text>
5+
<![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ]]>
6+
</jsp:text>
7+
8+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
9+
<head>
10+
<title>Spring 3 Converter</title>
11+
</head>
12+
<body>
13+
Error<br/>
14+
<%
15+
LoggerFactory.getLogger("InternalError").error("Exception occured: ", exception);
16+
%>
17+
<%= exception.toString() %> <br/>
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)