Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SPR-9566

  • Loading branch information...
commit 1336f8dd211a432733c52bb14f7081124a2b521e 1 parent 150afa6
@philwebb philwebb authored
View
5 SPR-9566/README.md
@@ -0,0 +1,5 @@
+See ArgumentConversionTest.
+
+Uses a simple SpEL expression to send a byte[] to a method, which
+simply returns its parameter. As you can see the array is copied
+before the method invocation.
View
64 SPR-9566/pom.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.springframework.samples.spring</groupId>
+ <artifactId>SPR-9566</artifactId>
+ <version>1.0.0.CI-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Spring Utility</name>
+ <url>http://www.springframework.org</url>
+ <description>
+ <![CDATA[
+ This project is a minimal jar utility with Spring configuration.
+ ]]>
+ </description>
+ <properties>
+ <maven.test.failure.ignore>true</maven.test.failure.ignore>
+ <spring.framework.version>3.2.0.BUILD-SNAPSHOT</spring.framework.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.7</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.framework.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.framework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-expression</artifactId>
+ <version>${spring.framework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
View
20 SPR-9566/src/main/java/net/gprussell/spel/ExampleService.java
@@ -0,0 +1,20 @@
+package net.gprussell.spel;
+
+import org.springframework.stereotype.Component;
+
+
+/**
+ * {@link Service} with hard-coded input data.
+ */
+@Component
+public class ExampleService implements Service {
+
+ public String getMessage() {
+ return "Hello world!";
+ }
+
+ public byte[] handleBytes(byte[] bytes) {
+ return bytes;
+ }
+
+}
View
9 SPR-9566/src/main/java/net/gprussell/spel/Service.java
@@ -0,0 +1,9 @@
+package net.gprussell.spel;
+
+public interface Service {
+
+ String getMessage();
+
+ byte[] handleBytes(byte[] bytes);
+
+}
View
10 SPR-9566/src/main/resources/META-INF/spring/app-context.xml
@@ -0,0 +1,10 @@
+<?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:context="http://www.springframework.org/schema/context"
+ 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">
+
+ <bean id="service" class="net.gprussell.spel.ExampleService"/>
+
+</beans>
View
33 SPR-9566/src/test/java/net/gprussell/spel/ArgumentConversionTest.java
@@ -0,0 +1,33 @@
+package net.gprussell.spel;
+
+import static org.junit.Assert.assertSame;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.expression.BeanFactoryResolver;
+import org.springframework.expression.Expression;
+import org.springframework.expression.spel.standard.SpelExpressionParser;
+import org.springframework.expression.spel.support.StandardEvaluationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@ContextConfiguration
+@RunWith(SpringJUnit4ClassRunner.class)
+public class ArgumentConversionTest {
+
+ @Autowired
+ private BeanFactory beanFactory;
+
+ @Test
+ public void testBytesNotCopied() throws Exception {
+ Expression expression = new SpelExpressionParser().parseExpression("@service.handleBytes(#root)");
+ byte[] bytes = new byte[100];
+ StandardEvaluationContext evaluationContext = new StandardEvaluationContext(bytes);
+ evaluationContext.setBeanResolver(new BeanFactoryResolver(this.beanFactory));
+ byte[] outBytes = expression.getValue(evaluationContext, byte[].class);
+ assertSame(bytes, outBytes);
+ }
+
+}
View
6 SPR-9566/src/test/resources/log4j.properties
@@ -0,0 +1,6 @@
+log4j.rootCategory=INFO, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n
+
View
8 SPR-9566/src/test/resources/net/gprussell/spel/ArgumentConversionTest-context.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <import resource="classpath:/META-INF/spring/app-context.xml"/>
+
+</beans>
Please sign in to comment.
Something went wrong with that request. Please try again.