INTSAMPLES-89 - Upgrade to Spring Integration 2.2 RC3

* Test samples
* Polish documentation
* Polish code

For reference see: https://jira.springsource.org/browse/INTSAMPLES-89
This commit is contained in:
Gunnar Hillert
2012-10-28 22:51:14 -04:00
parent 251e035a18
commit 3c9c91c847
93 changed files with 1666 additions and 1454 deletions

View File

@@ -4,13 +4,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>cafe-scripted</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.2.0.BUILD-SNAPSHOT</version>
<name>Samples (Applications) - Cafe Sample (Scripted Implementation)</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.integration.version>2.1.0.RELEASE</spring.integration.version>
<spring.version>3.1.0.RELEASE</spring.version>
<log4j.version>1.2.16</log4j.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.integration.version>2.2.0.RC3</spring.integration.version>
<spring.version>3.1.3.RELEASE</spring.version>
<log4j.version>1.2.17</log4j.version>
<junit.version>4.10</junit.version>
</properties>
@@ -114,13 +114,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>2.5.1</version>
<configuration>
<source>1.5</source>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>false</showDeprecation>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>

View File

@@ -6,7 +6,7 @@
<parent>
<artifactId>cafe</artifactId>
<groupId>org.springframework.integration.samples</groupId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.2.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>cafe-amqp</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>cafe</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.2.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>cafe-jms</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<artifactId>cafe</artifactId>
<groupId>org.springframework.integration.samples</groupId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.2.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>cafe-si</artifactId>

View File

@@ -5,7 +5,7 @@
<groupId>org.springframework.integration.samples</groupId>
<artifactId>cafe</artifactId>
<packaging>pom</packaging>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.2.0.BUILD-SNAPSHOT</version>
<prerequisites>
<maven>2.2.1</maven>
@@ -21,9 +21,9 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.integration.version>2.1.0.RELEASE</spring.integration.version>
<spring.core.version>3.1.0.RELEASE</spring.core.version>
<log4j.version>1.2.16</log4j.version>
<spring.integration.version>2.2.0.RC3</spring.integration.version>
<spring.core.version>3.1.3.RELEASE</spring.core.version>
<log4j.version>1.2.17</log4j.version>
<junit.version>4.10</junit.version>
</properties>
<dependencies>
@@ -70,10 +70,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>2.5.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>

View File

@@ -4,13 +4,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>loan-broker</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.2.0.BUILD-SNAPSHOT</version>
<name>Samples (Applications) - Loan Broker</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.integration.version>2.1.0.RELEASE</spring.integration.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.integration.version>2.2.0.RC3</spring.integration.version>
<commons-logging.version>1.1.1</commons-logging.version>
<log4j.version>1.2.16</log4j.version>
<log4j.version>1.2.17</log4j.version>
<junit.version>4.10</junit.version>
</properties>
<dependencies>
@@ -41,13 +41,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>2.5.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>false</showDeprecation>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,19 +24,21 @@ import org.springframework.integration.samples.loanbroker.domain.LoanRequest;
/**
* POJI Gateway that connects method invocations to the request-channel.
* This completely isolates the developer from Spring Integration API details.
*
*
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
public interface LoanBrokerGateway {
/**
* Will return the best {@link LoanQuote} for the given request.
*/
public LoanQuote getBestLoanQuote(LoanRequest loanRequest);
LoanQuote getBestLoanQuote(LoanRequest loanRequest);
/**
* Will return all {@link LoanQuote}s for the given request.
*/
public List<LoanQuote> getAllLoanQuotes(LoanRequest loanRequest);
List<LoanQuote> getAllLoanQuotes(LoanRequest loanRequest);
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.loanbroker.loanshark.domain;
import java.util.ArrayList;
@@ -24,151 +39,163 @@ import flexjson.JSONSerializer;
@Entity
public class LoanShark {
private String name;
private String name;
private Long counter;
private Long counter;
private Double averageRate;
private Double averageRate;
public String toJson() {
return new JSONSerializer().exclude("*.class").serialize(this);
}
return new JSONSerializer().exclude("*.class").serialize(this);
}
public static LoanShark fromJsonToLoanShark(String json) {
return new JSONDeserializer<LoanShark>().use(null, LoanShark.class).deserialize(json);
}
return new JSONDeserializer<LoanShark>().use(null, LoanShark.class).deserialize(json);
}
public static String toJsonArray(Collection<LoanShark> collection) {
return new JSONSerializer().exclude("*.class").serialize(collection);
}
return new JSONSerializer().exclude("*.class").serialize(collection);
}
public static Collection<LoanShark> fromJsonArrayToLoanSharks(String json) {
return new JSONDeserializer<List<LoanShark>>().use(null, ArrayList.class).use("values", LoanShark.class).deserialize(json);
}
return new JSONDeserializer<List<LoanShark>>().use(null, ArrayList.class).use("values", LoanShark.class).deserialize(json);
}
@PersistenceContext
transient EntityManager entityManager;
transient EntityManager entityManager;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Version
@Column(name = "version")
private Integer version;
@Column(name = "version")
private Integer version;
public Long getId() {
return this.id;
}
return this.id;
}
public void setId(Long id) {
this.id = id;
}
this.id = id;
}
public Integer getVersion() {
return this.version;
}
return this.version;
}
public void setVersion(Integer version) {
this.version = version;
}
this.version = version;
}
@Transactional
public void persist() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.persist(this);
}
public void persist() {
if (this.entityManager == null) {
this.entityManager = entityManager();
}
this.entityManager.persist(this);
}
@Transactional
public void remove() {
if (this.entityManager == null) this.entityManager = entityManager();
if (this.entityManager.contains(this)) {
this.entityManager.remove(this);
} else {
LoanShark attached = this.entityManager.find(this.getClass(), this.id);
this.entityManager.remove(attached);
}
}
public void remove() {
if (this.entityManager == null) {
this.entityManager = entityManager();
}
if (this.entityManager.contains(this)) {
this.entityManager.remove(this);
} else {
LoanShark attached = this.entityManager.find(this.getClass(), this.id);
this.entityManager.remove(attached);
}
}
@Transactional
public void flush() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.flush();
}
public void flush() {
if (this.entityManager == null) {
this.entityManager = entityManager();
}
this.entityManager.flush();
}
@Transactional
public LoanShark merge() {
if (this.entityManager == null) this.entityManager = entityManager();
LoanShark merged = this.entityManager.merge(this);
this.entityManager.flush();
return merged;
}
public LoanShark merge() {
if (this.entityManager == null) {
this.entityManager = entityManager();
}
LoanShark merged = this.entityManager.merge(this);
this.entityManager.flush();
return merged;
}
public static final EntityManager entityManager() {
EntityManager em = new LoanShark().entityManager;
if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
return em;
}
EntityManager em = new LoanShark().entityManager;
if (em == null) {
throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
}
return em;
}
public static long countLoanSharks() {
return ((Number) entityManager().createQuery("select count(o) from LoanShark o").getSingleResult()).longValue();
}
return ((Number) entityManager().createQuery("select count(o) from LoanShark o").getSingleResult()).longValue();
}
@SuppressWarnings("unchecked")
public static List<LoanShark> findAllLoanSharks() {
return entityManager().createQuery("select o from LoanShark o").getResultList();
}
public static List<LoanShark> findAllLoanSharks() {
return entityManager().createQuery("select o from LoanShark o").getResultList();
}
public static LoanShark findLoanShark(Long id) {
if (id == null) return null;
return entityManager().find(LoanShark.class, id);
}
if (id == null) return null;
return entityManager().find(LoanShark.class, id);
}
@SuppressWarnings("unchecked")
public static List<LoanShark> findLoanSharkEntries(int firstResult, int maxResults) {
return entityManager().createQuery("select o from LoanShark o").setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
}
public static List<LoanShark> findLoanSharkEntries(int firstResult, int maxResults) {
return entityManager().createQuery("select o from LoanShark o").setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
}
public String getName() {
return this.name;
}
return this.name;
}
public void setName(String name) {
this.name = name;
}
this.name = name;
}
public Long getCounter() {
return this.counter;
}
return this.counter;
}
public void setCounter(Long counter) {
this.counter = counter;
}
this.counter = counter;
}
public Double getAverageRate() {
return this.averageRate;
}
return this.averageRate;
}
public void setAverageRate(Double averageRate) {
this.averageRate = averageRate;
}
this.averageRate = averageRate;
}
public static Query findLoanSharksByName(String name) {
if (name == null || name.length() == 0) throw new IllegalArgumentException("The name argument is required");
EntityManager em = LoanShark.entityManager();
Query q = em.createQuery("SELECT LoanShark FROM LoanShark AS loanshark WHERE loanshark.name = :name");
q.setParameter("name", name);
return q;
}
if (name == null || name.length() == 0) {
throw new IllegalArgumentException("The name argument is required");
}
EntityManager em = LoanShark.entityManager();
Query q = em.createQuery("SELECT LoanShark FROM LoanShark AS loanshark WHERE loanshark.name = :name");
q.setParameter("name", name);
return q;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Id: ").append(getId()).append(", ");
sb.append("Version: ").append(getVersion()).append(", ");
sb.append("Name: ").append(getName()).append(", ");
sb.append("Counter: ").append(getCounter()).append(", ");
sb.append("AverageRate: ").append(getAverageRate());
return sb.toString();
}
StringBuilder sb = new StringBuilder();
sb.append("Id: ").append(getId()).append(", ");
sb.append("Version: ").append(getVersion()).append(", ");
sb.append("Name: ").append(getName()).append(", ");
sb.append("Counter: ").append(getCounter()).append(", ");
sb.append("AverageRate: ").append(getAverageRate());
return sb.toString();
}
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.loanbroker.loanshark.web;
import javax.validation.Valid;
@@ -24,115 +39,115 @@ import org.springframework.web.bind.annotation.ResponseBody;
public class SharkController {
@RequestMapping(method = RequestMethod.POST)
public String create(@Valid LoanShark loanShark, BindingResult result, Model model) {
if (result.hasErrors()) {
model.addAttribute("loanShark", loanShark);
return "loansharks/create";
}
loanShark.persist();
return "redirect:/loansharks/" + loanShark.getId();
}
public String create(@Valid LoanShark loanShark, BindingResult result, Model model) {
if (result.hasErrors()) {
model.addAttribute("loanShark", loanShark);
return "loansharks/create";
}
loanShark.persist();
return "redirect:/loansharks/" + loanShark.getId();
}
@RequestMapping(params = "form", method = RequestMethod.GET)
public String createForm(Model model) {
model.addAttribute("loanShark", new LoanShark());
return "loansharks/create";
}
public String createForm(Model model) {
model.addAttribute("loanShark", new LoanShark());
return "loansharks/create";
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String show(@PathVariable("id") Long id, Model model) {
model.addAttribute("loanshark", LoanShark.findLoanShark(id));
model.addAttribute("itemId", id);
return "loansharks/show";
}
public String show(@PathVariable("id") Long id, Model model) {
model.addAttribute("loanshark", LoanShark.findLoanShark(id));
model.addAttribute("itemId", id);
return "loansharks/show";
}
@RequestMapping(method = RequestMethod.GET)
public String list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model model) {
if (page != null || size != null) {
int sizeNo = size == null ? 10 : size.intValue();
model.addAttribute("loansharks", LoanShark.findLoanSharkEntries(page == null ? 0 : (page.intValue() - 1) * sizeNo, sizeNo));
float nrOfPages = (float) LoanShark.countLoanSharks() / sizeNo;
model.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));
} else {
model.addAttribute("loansharks", LoanShark.findAllLoanSharks());
}
return "loansharks/list";
}
public String list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model model) {
if (page != null || size != null) {
int sizeNo = size == null ? 10 : size.intValue();
model.addAttribute("loansharks", LoanShark.findLoanSharkEntries(page == null ? 0 : (page.intValue() - 1) * sizeNo, sizeNo));
float nrOfPages = (float) LoanShark.countLoanSharks() / sizeNo;
model.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));
} else {
model.addAttribute("loansharks", LoanShark.findAllLoanSharks());
}
return "loansharks/list";
}
@RequestMapping(method = RequestMethod.PUT)
public String update(@Valid LoanShark loanShark, BindingResult result, Model model) {
if (result.hasErrors()) {
model.addAttribute("loanShark", loanShark);
return "loansharks/update";
}
loanShark.merge();
return "redirect:/loansharks/" + loanShark.getId();
}
public String update(@Valid LoanShark loanShark, BindingResult result, Model model) {
if (result.hasErrors()) {
model.addAttribute("loanShark", loanShark);
return "loansharks/update";
}
loanShark.merge();
return "redirect:/loansharks/" + loanShark.getId();
}
@RequestMapping(value = "/{id}", params = "form", method = RequestMethod.GET)
public String updateForm(@PathVariable("id") Long id, Model model) {
model.addAttribute("loanShark", LoanShark.findLoanShark(id));
return "loansharks/update";
}
public String updateForm(@PathVariable("id") Long id, Model model) {
model.addAttribute("loanShark", LoanShark.findLoanShark(id));
return "loansharks/update";
}
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public String delete(@PathVariable("id") Long id, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model model) {
LoanShark.findLoanShark(id).remove();
model.addAttribute("page", (page == null) ? "1" : page.toString());
model.addAttribute("size", (size == null) ? "10" : size.toString());
return "redirect:/loansharks?page=" + ((page == null) ? "1" : page.toString()) + "&size=" + ((size == null) ? "10" : size.toString());
}
public String delete(@PathVariable("id") Long id, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model model) {
LoanShark.findLoanShark(id).remove();
model.addAttribute("page", (page == null) ? "1" : page.toString());
model.addAttribute("size", (size == null) ? "10" : size.toString());
return "redirect:/loansharks?page=" + ((page == null) ? "1" : page.toString()) + "&size=" + ((size == null) ? "10" : size.toString());
}
@RequestMapping(params = { "find=ByName", "form" }, method = RequestMethod.GET)
public String findLoanSharksByNameForm(Model model) {
return "loansharks/findLoanSharksByName";
}
public String findLoanSharksByNameForm(Model model) {
return "loansharks/findLoanSharksByName";
}
@RequestMapping(params = "find=ByName", method = RequestMethod.GET)
public String findLoanSharksByName(@RequestParam("name") String name, Model model) {
model.addAttribute("loansharks", LoanShark.findLoanSharksByName(name).getResultList());
return "loansharks/list";
}
public String findLoanSharksByName(@RequestParam("name") String name, Model model) {
model.addAttribute("loansharks", LoanShark.findLoanSharksByName(name).getResultList());
return "loansharks/list";
}
Converter<LoanShark, String> getLoanSharkConverter() {
return new Converter<LoanShark, String>() {
public String convert(LoanShark loanShark) {
return new StringBuilder().append(loanShark.getName()).append(" ").append(loanShark.getCounter()).append(" ").append(loanShark.getAverageRate()).toString();
}
};
}
return new Converter<LoanShark, String>() {
public String convert(LoanShark loanShark) {
return new StringBuilder().append(loanShark.getName()).append(" ").append(loanShark.getCounter()).append(" ").append(loanShark.getAverageRate()).toString();
}
};
}
@InitBinder
void registerConverters(WebDataBinder binder) {
if (binder.getConversionService() instanceof GenericConversionService) {
GenericConversionService conversionService = (GenericConversionService) binder.getConversionService();
conversionService.addConverter(getLoanSharkConverter());
}
}
void registerConverters(WebDataBinder binder) {
if (binder.getConversionService() instanceof GenericConversionService) {
GenericConversionService conversionService = (GenericConversionService) binder.getConversionService();
conversionService.addConverter(getLoanSharkConverter());
}
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
@ResponseBody
public String showJson(@PathVariable("id") Long id) {
return LoanShark.findLoanShark(id).toJson();
}
@ResponseBody
public String showJson(@PathVariable("id") Long id) {
return LoanShark.findLoanShark(id).toJson();
}
@RequestMapping(method = RequestMethod.POST, headers = "Accept=application/json")
public ResponseEntity<String> createFromJson(@RequestBody String json) {
LoanShark.fromJsonToLoanShark(json).persist();
return new ResponseEntity<String>("LoanShark created", HttpStatus.CREATED);
}
public ResponseEntity<String> createFromJson(@RequestBody String json) {
LoanShark.fromJsonToLoanShark(json).persist();
return new ResponseEntity<String>("LoanShark created", HttpStatus.CREATED);
}
@RequestMapping(headers = "Accept=application/json")
@ResponseBody
public String listJson() {
return LoanShark.toJsonArray(LoanShark.findAllLoanSharks());
}
@ResponseBody
public String listJson() {
return LoanShark.toJsonArray(LoanShark.findAllLoanSharks());
}
@RequestMapping(value = "/jsonArray", method = RequestMethod.POST, headers = "Accept=application/json")
public ResponseEntity<String> createFromJsonArray(@RequestBody String json) {
for (LoanShark loanshark: LoanShark.fromJsonArrayToLoanSharks(json)) {
loanshark.persist();
}
return new ResponseEntity<String>("LoanShark created", HttpStatus.CREATED);
}
public ResponseEntity<String> createFromJsonArray(@RequestBody String json) {
for (LoanShark loanshark: LoanShark.fromJsonArrayToLoanSharks(json)) {
loanshark.persist();
}
return new ResponseEntity<String>("LoanShark created", HttpStatus.CREATED);
}
}

View File

@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>applications</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.2.0.BUILD-SNAPSHOT</version>
<name>Spring Integration Samples - Applications</name>
<packaging>pom</packaging>