Skip to content

Commit 1336f8d

Browse files
committed
SPR-9566
1 parent 150afa6 commit 1336f8d

File tree

8 files changed

+155
-0
lines changed

8 files changed

+155
-0
lines changed

SPR-9566/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
See ArgumentConversionTest.
2+
3+
Uses a simple SpEL expression to send a byte[] to a method, which
4+
simply returns its parameter. As you can see the array is copied
5+
before the method invocation.

SPR-9566/pom.xml

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>org.springframework.samples.spring</groupId>
7+
<artifactId>SPR-9566</artifactId>
8+
<version>1.0.0.CI-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
<name>Spring Utility</name>
11+
<url>http://www.springframework.org</url>
12+
<description>
13+
<![CDATA[
14+
This project is a minimal jar utility with Spring configuration.
15+
]]>
16+
</description>
17+
<properties>
18+
<maven.test.failure.ignore>true</maven.test.failure.ignore>
19+
<spring.framework.version>3.2.0.BUILD-SNAPSHOT</spring.framework.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>junit</groupId>
25+
<artifactId>junit</artifactId>
26+
<version>4.7</version>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework</groupId>
31+
<artifactId>spring-test</artifactId>
32+
<version>${spring.framework.version}</version>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework</groupId>
37+
<artifactId>spring-context</artifactId>
38+
<version>${spring.framework.version}</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.springframework</groupId>
42+
<artifactId>spring-expression</artifactId>
43+
<version>${spring.framework.version}</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>log4j</groupId>
47+
<artifactId>log4j</artifactId>
48+
<version>1.2.14</version>
49+
</dependency>
50+
</dependencies>
51+
52+
<build>
53+
<plugins>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-compiler-plugin</artifactId>
57+
<configuration>
58+
<source>1.5</source>
59+
<target>1.5</target>
60+
</configuration>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package net.gprussell.spel;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
6+
/**
7+
* {@link Service} with hard-coded input data.
8+
*/
9+
@Component
10+
public class ExampleService implements Service {
11+
12+
public String getMessage() {
13+
return "Hello world!";
14+
}
15+
16+
public byte[] handleBytes(byte[] bytes) {
17+
return bytes;
18+
}
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package net.gprussell.spel;
2+
3+
public interface Service {
4+
5+
String getMessage();
6+
7+
byte[] handleBytes(byte[] bytes);
8+
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:context="http://www.springframework.org/schema/context"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
6+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
7+
8+
<bean id="service" class="net.gprussell.spel.ExampleService"/>
9+
10+
</beans>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package net.gprussell.spel;
2+
3+
import static org.junit.Assert.assertSame;
4+
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.BeanFactory;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.context.expression.BeanFactoryResolver;
10+
import org.springframework.expression.Expression;
11+
import org.springframework.expression.spel.standard.SpelExpressionParser;
12+
import org.springframework.expression.spel.support.StandardEvaluationContext;
13+
import org.springframework.test.context.ContextConfiguration;
14+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15+
16+
@ContextConfiguration
17+
@RunWith(SpringJUnit4ClassRunner.class)
18+
public class ArgumentConversionTest {
19+
20+
@Autowired
21+
private BeanFactory beanFactory;
22+
23+
@Test
24+
public void testBytesNotCopied() throws Exception {
25+
Expression expression = new SpelExpressionParser().parseExpression("@service.handleBytes(#root)");
26+
byte[] bytes = new byte[100];
27+
StandardEvaluationContext evaluationContext = new StandardEvaluationContext(bytes);
28+
evaluationContext.setBeanResolver(new BeanFactoryResolver(this.beanFactory));
29+
byte[] outBytes = expression.getValue(evaluationContext, byte[].class);
30+
assertSame(bytes, outBytes);
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
log4j.rootCategory=INFO, stdout
2+
3+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5+
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
5+
6+
<import resource="classpath:/META-INF/spring/app-context.xml"/>
7+
8+
</beans>

0 commit comments

Comments
 (0)