Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

SPR9157 draft #19

Merged
merged 3 commits into from

2 participants

@ferengra

The converter in this very little project without any security, interceptors etc. works fine.
However, the project the issue happens is much more complex.
It might be difficult to demostrate the issue as a sample.

@rstoyanchev rstoyanchev was assigned
@ferengra

The demo for the issue is created.

I think the issue is on the line 432 in GenericConversionService.ConverterAdapter:
return this.typeInfo.getTargetType().equals(targetType.getObjectType());

In my view it should be:
return this.typeInfo.getTargetType().isAssignableFrom(targetType.getObjectType());

If you compare the version of 3.0.6 and 3.0.7 of GenericConversionService, you'll see that those lines were only added in 3.0.7.

@rstoyanchev rstoyanchev merged commit 990eadf into spring-projects:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 25, 2012
  1. Add project for SPR9157

    Ferenc Gratzer authored
Commits on Feb 27, 2012
This page is out of date. Refresh to see the latest.
View
2  SPR-9157/SPR-9157.txt
@@ -0,0 +1,2 @@
+http://localhost:8080/spr9157/environments.html
+http://localhost:8080/spr9157/environment.html?environment=name
View
90 SPR-9157/pom.xml
@@ -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>
View
11 SPR-9157/src/main/java/org/springframework/issues/spr9157/model/EnhancedEnvironment.java
@@ -0,0 +1,11 @@
+package org.springframework.issues.spr9157.model;
+
+/**
+ * Enhanced environment.
+ *
+ * @author ferengra
+ */
+public interface EnhancedEnvironment extends Environment {
+
+ String getDescription();
+}
View
28 SPR-9157/src/main/java/org/springframework/issues/spr9157/model/EnhancedEnvironmentImpl.java
@@ -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;
+ }
+}
View
11 SPR-9157/src/main/java/org/springframework/issues/spr9157/model/Environment.java
@@ -0,0 +1,11 @@
+package org.springframework.issues.spr9157.model;
+
+/**
+ * Environment.
+ *
+ * @author ferengra
+ */
+public interface Environment {
+
+ String getName();
+}
View
58 SPR-9157/src/main/java/org/springframework/issues/spr9157/model/EnvironmentImpl.java
@@ -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();
+ }
+}
View
34 SPR-9157/src/main/java/org/springframework/issues/spr9157/web/controller/EnvironmentController.java
@@ -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;
+ }
+}
View
25 SPR-9157/src/main/java/org/springframework/issues/spr9157/web/util/EnvironmentConverter.java
@@ -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());
+ }
+}
View
78 SPR-9157/src/main/resources/logback.xml
@@ -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>
View
5 SPR-9157/src/main/webapp/WEB-INF/applicationContext.xml
@@ -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>
View
54 SPR-9157/src/main/webapp/WEB-INF/spr9157-servlet.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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"
+ xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
+ xmlns:util="http://www.springframework.org/schema/util" xmlns:security="http://www.springframework.org/schema/security"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
+ http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
+ http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
+
+ <context:component-scan base-package="org.springframework.issues.spr9157.web" use-default-filters="false">
+ <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
+ </context:component-scan>
+
+ <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
+ <property name="alwaysUseFullPath" value="true" />
+ </bean>
+
+ <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
+ <property name="cacheSeconds" value="0" />
+ <property name="webBindingInitializer">
+ <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
+ <property name="conversionService" ref="conversionService" />
+ </bean>
+ </property>
+ <property name="alwaysUseFullPath" value="true" />
+ </bean>
+
+ <bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
+ <property name="order" value="0" />
+ </bean>
+
+ <!-- Resolves logical view names to JSP views -->
+ <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
+ <property name="order" value="1" />
+ <property name="prefix" value="/WEB-INF/views/" />
+ <property name="suffix" value=".jsp" />
+ </bean>
+
+ <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
+ <property name="converters">
+ <set>
+ <bean class="org.springframework.issues.spr9157.web.util.EnvironmentConverter" />
+ </set>
+ </property>
+ </bean>
+
+ <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
+ <property name="defaultErrorView" value="errorInternal" />
+ <property name="warnLogCategory" value="spr9157" />
+ </bean>
+</beans>
View
11 SPR-9157/src/main/webapp/WEB-INF/views/environment.jsp
@@ -0,0 +1,11 @@
+<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
+<jsp:text>
+ <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ]]>
+</jsp:text>
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Spring 3 Converter</title>
+</head>
+Environment: <%= request.getAttribute("environment") %>
+</html>
View
11 SPR-9157/src/main/webapp/WEB-INF/views/environments.jsp
@@ -0,0 +1,11 @@
+<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
+<jsp:text>
+ <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ]]>
+</jsp:text>
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Spring 3 Converter</title>
+</head>
+Environments
+</html>
View
19 SPR-9157/src/main/webapp/WEB-INF/views/errorInternal.jsp
@@ -0,0 +1,19 @@
+<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
+<%@ page isErrorPage="true" %>
+<%@ page import="org.slf4j.LoggerFactory" %>
+<jsp:text>
+ <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ]]>
+</jsp:text>
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Spring 3 Converter</title>
+</head>
+<body>
+Error<br/>
+<%
+LoggerFactory.getLogger("InternalError").error("Exception occured: ", exception);
+%>
+<%= exception.toString() %> <br/>
+</body>
+</html>
View
11 SPR-9157/src/main/webapp/WEB-INF/views/index.jsp
@@ -0,0 +1,11 @@
+<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
+<jsp:text>
+ <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ]]>
+</jsp:text>
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<title>Spring 3 Converter</title>
+</head>
+Index
+</html>
View
80 SPR-9157/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app id="eFrame" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+ <display-name>spr9157</display-name>
+
+ <filter>
+ <filter-name>requestScopeFilter</filter-name>
+ <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>requestScopeFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <filter>
+ <filter-name>characterEncodingFilter</filter-name>
+ <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
+ <init-param>
+ <param-name>encoding</param-name>
+ <param-value>UTF-8</param-value>
+ </init-param>
+ <init-param>
+ <param-name>forceEncoding</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>characterEncodingFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <!-- Spring listeners -->
+ <listener>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+ <listener>
+ <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
+ </listener>
+ <listener>
+ <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
+ </listener>
+
+ <servlet>
+ <servlet-name>spr9157</servlet-name>
+ <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>spr9157</servlet-name>
+ <url-pattern>*.html</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>spr9157</servlet-name>
+ <url-pattern>*.do</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>spr9157</servlet-name>
+ <url-pattern>*.json</url-pattern>
+ </servlet-mapping>
+
+ <!-- Session configuration -->
+ <session-config>
+ <session-timeout>30</session-timeout>
+ </session-config>
+
+ <!-- Welcome files -->
+ <welcome-file-list>
+ <welcome-file>index.jsp</welcome-file>
+ </welcome-file-list>
+
+ <!-- Security constraints -->
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>Forbidden methods</web-resource-name>
+ <url-pattern>/*</url-pattern>
+ <http-method>TRACE</http-method>
+ </web-resource-collection>
+ <auth-constraint />
+ </security-constraint>
+</web-app>
Something went wrong with that request. Please try again.