LoanBroker now uses headers added by the gateway instead of accessing history events.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.loanbroker;
|
||||
|
||||
import java.util.List;
|
||||
@@ -25,20 +26,17 @@ import org.springframework.integration.loanbroker.domain.LoanRequest;
|
||||
* completely isolating SI developer from SI API details.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public interface LoanBrokerGateway {
|
||||
|
||||
/**
|
||||
* Will return the best {@link LoanQuote}
|
||||
*
|
||||
* @param loanRequest
|
||||
* @return
|
||||
* Will return the best {@link LoanQuote} for the given request.
|
||||
*/
|
||||
public LoanQuote getLoanQuote(LoanRequest loanRequest);
|
||||
|
||||
/**
|
||||
* Will return all {@link LoanQuote}s
|
||||
* @param loanRequest
|
||||
* @return
|
||||
* Will return all {@link LoanQuote}s for the given request.
|
||||
*/
|
||||
public List<LoanQuote> getAllLoanQuotes(LoanRequest loanRequest);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +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:util="http://www.springframework.org/schema/util"
|
||||
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/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:int-file="http://www.springframework.org/schema/integration/file"
|
||||
xmlns:util="http://www.springframework.org/schema/util">
|
||||
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
|
||||
|
||||
<util:map id="banks">
|
||||
<entry key="abcBankChannel" value="premier" />
|
||||
<entry key="efgBankChannel" value="premier" />
|
||||
|
||||
@@ -7,4 +7,5 @@
|
||||
<import resource="classpath:loan-broker-config.xml" />
|
||||
<import resource="classpath:bank-channel-mappings-config.xml" />
|
||||
<import resource="classpath:shark-detector-config.xml"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,49 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
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-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:util="http://www.springframework.org/schema/util">
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/util
|
||||
http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<int:gateway id="loanBrokerGateway"
|
||||
default-request-channel="loanBrokerPreProcessingChannel"
|
||||
service-interface="org.springframework.integration.loanbroker.LoanBrokerGateway"/>
|
||||
<gateway id="loanBrokerGateway"
|
||||
default-request-channel="loanBrokerPreProcessingChannel"
|
||||
service-interface="org.springframework.integration.loanbroker.LoanBrokerGateway">
|
||||
<method name="getLoanQuote">
|
||||
<header name="RESPONSE_TYPE" value="BEST"/>
|
||||
</method>
|
||||
<method name="getAllLoanQuotes">
|
||||
<header name="RESPONSE_TYPE" value="ALL"/>
|
||||
</method>
|
||||
</gateway>
|
||||
|
||||
<int:chain input-channel="loanBrokerPreProcessingChannel" output-channel="banksDistributionChannel">
|
||||
<int:header-enricher>
|
||||
<int:header name="RESPONSE_TYPE"
|
||||
expression="headers.history.iterator().next().attributes['method'].equals('getLoanQuote') ? 'BEST' : 'ALL'" />
|
||||
</int:header-enricher>
|
||||
<int:header-enricher>
|
||||
<int:header name="CREDIT_SCORE" ref="creditBureau" method="getCreditScore"/>
|
||||
</int:header-enricher>
|
||||
<int:header-enricher>
|
||||
<int:header name="BANKS" ref="bankSelector" method="selectBankChannels"/>
|
||||
</int:header-enricher>
|
||||
</int:chain>
|
||||
<chain input-channel="loanBrokerPreProcessingChannel" output-channel="banksDistributionChannel">
|
||||
<header-enricher>
|
||||
<header name="CREDIT_SCORE" ref="creditBureau" method="getCreditScore"/>
|
||||
</header-enricher>
|
||||
<header-enricher>
|
||||
<header name="BANKS" ref="bankSelector" method="selectBankChannels"/>
|
||||
</header-enricher>
|
||||
</chain>
|
||||
|
||||
<int:router id="bankRecipientListRouter" input-channel="banksDistributionChannel"
|
||||
expression="headers['BANKS']"
|
||||
apply-sequence="true"/>
|
||||
<router id="bankRecipientListRouter" input-channel="banksDistributionChannel"
|
||||
expression="headers['BANKS']" apply-sequence="true"/>
|
||||
|
||||
<!-- Messages are sent to the banks via bank channels and will be recieved and processed by aggregator-->
|
||||
|
||||
<int:aggregator input-channel="quotesAggregationChannel" method="aggregateQuotes">
|
||||
<bean class="org.springframework.integration.loanbroker.LoanQuoteAggregator"/>
|
||||
</int:aggregator>
|
||||
<!-- Messages are sent to the banks via bank channels and will be received and processed by an aggregator -->
|
||||
|
||||
<bean id="bankSelector" class="org.springframework.integration.loanbroker.BanksChannelSelector">
|
||||
<constructor-arg ref="banks"/>
|
||||
<property name="routingExpression">
|
||||
<aggregator input-channel="quotesAggregationChannel" method="aggregateQuotes">
|
||||
<beans:bean class="org.springframework.integration.loanbroker.LoanQuoteAggregator"/>
|
||||
</aggregator>
|
||||
|
||||
<beans:bean id="bankSelector" class="org.springframework.integration.loanbroker.BanksChannelSelector">
|
||||
<beans:constructor-arg ref="banks"/>
|
||||
<beans:property name="routingExpression">
|
||||
<!-- This expression also demonstrates 'Collection Selection' concept of SpEL
|
||||
(see http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/expressions.html#d0e11961)
|
||||
-->
|
||||
<value>
|
||||
<beans:value>
|
||||
headers['CREDIT_SCORE'].score > 780 ? #banks.?[value.equals('premier')].keySet()
|
||||
: #banks.?[value.equals('secondary')].keySet()
|
||||
</value>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
||||
</beans:value>
|
||||
</beans:property>
|
||||
</beans:bean>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip-2.0.xsd">
|
||||
|
||||
<int:channel id="quotesAggregationChannel">
|
||||
<int:interceptors>
|
||||
<int:wire-tap channel="loanSharkDetectorChannel"/>
|
||||
</int:interceptors>
|
||||
</int:channel>
|
||||
|
||||
<int:channel id="loanSharkDetectorChannel" />
|
||||
|
||||
<int:filter id="loanSharkFilter"
|
||||
input-channel="loanSharkDetectorChannel"
|
||||
output-channel="loanSharkChannel"
|
||||
expression="payload.rate > 5.2"/>
|
||||
<channel id="quotesAggregationChannel">
|
||||
<interceptors>
|
||||
<wire-tap channel="loanSharkDetectorChannel"/>
|
||||
</interceptors>
|
||||
</channel>
|
||||
|
||||
<int:channel id="loanSharkChannel" />
|
||||
|
||||
<int:transformer ref="udpTransformer"
|
||||
input-channel="loanSharkChannel"
|
||||
output-channel="sharkOutChannel"/>
|
||||
<channel id="loanSharkDetectorChannel"/>
|
||||
|
||||
<bean id="udpTransformer" class="org.springframework.integration.loanbroker.Transformer"/>
|
||||
<filter id="loanSharkFilter"
|
||||
input-channel="loanSharkDetectorChannel"
|
||||
output-channel="loanSharkChannel"
|
||||
expression="payload.rate > 5.2"/>
|
||||
|
||||
<channel id="loanSharkChannel" />
|
||||
|
||||
<transformer ref="udpTransformer"
|
||||
input-channel="loanSharkChannel"
|
||||
output-channel="sharkOutChannel"/>
|
||||
|
||||
<beans:bean id="udpTransformer" class="org.springframework.integration.loanbroker.Transformer"/>
|
||||
|
||||
<channel id="sharkOutChannel" />
|
||||
|
||||
<int:channel id="sharkOutChannel" />
|
||||
|
||||
<int-ip:outbound-channel-adapter id="udpOut"
|
||||
channel="sharkOutChannel"
|
||||
protocol="udp"
|
||||
host="225.6.7.8"
|
||||
multicast="true"
|
||||
port="11111"/>
|
||||
channel="sharkOutChannel"
|
||||
protocol="udp"
|
||||
host="225.6.7.8"
|
||||
multicast="true"
|
||||
port="11111"/>
|
||||
|
||||
</beans>
|
||||
</beans:beans>
|
||||
@@ -1,14 +1,14 @@
|
||||
<?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:int="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration">
|
||||
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">
|
||||
|
||||
<bean id="creditBureau" class="org.springframework.integration.loanbroker.stubs.CreditBureauStub" />
|
||||
|
||||
<bean id="bankStub" class="org.springframework.integration.loanbroker.stubs.BankStub"/>
|
||||
|
||||
|
||||
<!-- Bank Endpoints (to be rewired to remoting adapters) -->
|
||||
<int:service-activator input-channel="abcBankChannel" output-channel="quotesAggregationChannel" ref="bankStub"/>
|
||||
|
||||
|
||||
@@ -13,12 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.loanbroker.demo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.loanbroker.LoanBrokerGateway;
|
||||
@@ -28,18 +30,16 @@ import org.springframework.integration.loanbroker.domain.LoanRequest;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
*
|
||||
*/
|
||||
public class LoanBrokerSharkDetectorDemo {
|
||||
private static Logger logger = Logger.getLogger(LoanBrokerSharkDetectorDemo.class);
|
||||
|
||||
@Test
|
||||
public void testUdpMulticast() {
|
||||
ConfigurableApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("bootstrap-config/stubbed-loan-broker-multicast.xml");
|
||||
LoanBrokerGateway broker = context.getBean("loanBrokerGateway", LoanBrokerGateway.class);
|
||||
|
||||
ConfigurableApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("bootstrap-config/stubbed-loan-broker-multicast.xml");
|
||||
|
||||
LoanBrokerGateway broker = ac.getBean("loanBrokerGateway", LoanBrokerGateway.class);
|
||||
LoanRequest loanRequest = new LoanRequest();
|
||||
loanRequest.setCustomer(new Customer());
|
||||
|
||||
@@ -51,8 +51,7 @@ public class LoanBrokerSharkDetectorDemo {
|
||||
for (LoanQuote loanQuote : loanQuotes) {
|
||||
logger.info(loanQuote);
|
||||
}
|
||||
|
||||
ac.close();
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user