Author: ningjiang
Date: Fri Jun 6 06:29:15 2008
New Revision: 663935
URL: http://svn.apache.org/viewvc?rev=663935&view=rev
Log:
Add the snippet tags for the loan broker web services wiki
Modified:
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/Client.java
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBroker.java
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBrokerWS.java
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/bank/Bank.java
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/bank/BankWS.java
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/credit/CreditAgency.java
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/credit/CreditAgencyWS.java
Modified:
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java?rev=663935&r1=663934&r2=663935&view=diff
==============================================================================
---
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java
(original)
+++
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java
Fri Jun 6 06:29:15 2008
@@ -19,19 +19,21 @@
import org.apache.camel.Exchange;
import org.apache.camel.loanbroker.webservice.version.bank.BankQuote;
import org.apache.camel.processor.aggregate.AggregationStrategy;
-/**
- *
- */
+
+//START SNIPPET: aggregating
public class BankResponseAggregationStrategy implements AggregationStrategy {
public static final String BANK_QUOTE = "bank_quote";
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+ // Get the bank quote instance from the exchange
BankQuote oldQuote = oldExchange.getProperty(BANK_QUOTE,
BankQuote.class);
+ // Get the oldQute from out message body if we can't get it from the
exchange
if (oldQuote == null) {
Object[] oldResult = (Object[])oldExchange.getOut().getBody();
oldQuote = (BankQuote) oldResult[0];
}
+ // Get the newQuote
Object[] newResult = (Object[])newExchange.getOut().getBody();
BankQuote newQuote = (BankQuote) newResult[0];
Exchange result = null;
@@ -44,8 +46,9 @@
result = newExchange;
bankQuote = newQuote;
}
- // Copy the bank response together
+ // Set the lower rate BankQuote instance back to aggregated exchange
result.setProperty(BANK_QUOTE, bankQuote);
+ // Set the return message for the client
result.getOut().setBody("The best rate is " + bankQuote.toString());
return result;
@@ -53,3 +56,4 @@
}
}
+//END SNIPPET: aggregating
Modified:
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/Client.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/Client.java?rev=663935&r1=663934&r2=663935&view=diff
==============================================================================
---
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/Client.java
(original)
+++
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/Client.java
Fri Jun 6 06:29:15 2008
@@ -25,9 +25,12 @@
/**
* The client that will invoke the loan broker service
*/
+
+//START SNIPPET: client
public class Client {
public LoanBrokerWS getProxy(String address) {
+ // Now we use the simple front API to create the client proxy
ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
clientBean.setAddress(address);
@@ -55,3 +58,4 @@
}
}
+//END SNIPPET: client
\ No newline at end of file
Modified:
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBroker.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBroker.java?rev=663935&r1=663934&r2=663935&view=diff
==============================================================================
---
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBroker.java
(original)
+++
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBroker.java
Fri Jun 6 06:29:15 2008
@@ -51,17 +51,18 @@
*/
public class LoanBroker extends RouteBuilder {
- /**
- * A main() so we can easily run these routing rules in our IDE
- * @throws Exception
- */
+ //START SNIPPET: server
public static void main(String... args) throws Exception {
CamelContext context = new DefaultCamelContext();
CreditAgencyServer creditAgencyServer = new CreditAgencyServer();
+ // Start the credit server
creditAgencyServer.start();
+
+ // Start the bank server
BankServer bankServer = new BankServer();
bankServer.start();
+ // Start the camel context
context.addRoutes(new LoanBroker());
context.start();
@@ -72,21 +73,33 @@
bankServer.stop();
creditAgencyServer.stop();
}
-
+ //END SNIPPET: server
/**
* Lets configure the Camel routing rules using Java code...
*/
public void configure() {
- // Option 1 to call the bank endpoints sequentially
- from(Constants.LOANBROKER_URI).process(new
CreditScoreProcessor(Constants.CREDITAGENCY_ADDRESS))
- .multicast(new
BankResponseAggregationStrategy()).to(Constants.BANK1_URI, Constants.BANK2_URI,
Constants.BANK3_URI);
-
- // Option 2 to call the bank endpoints parallelly
- from(Constants.PARALLEL_LOANBROKER_URI).process(new
CreditScoreProcessor(Constants.CREDITAGENCY_ADDRESS))
- .multicast(new BankResponseAggregationStrategy(),
true).to(Constants.BANK1_URI, Constants.BANK2_URI, Constants.BANK3_URI);
+ // START SNIPPET: dsl
+
+ // Router 1 to call the bank endpoints sequentially
+ from(Constants.LOANBROKER_URI)
+ // Using the CreditScoreProcessor to call the credit agency service
+ .process(new CreditScoreProcessor(Constants.CREDITAGENCY_ADDRESS))
+ // Set the aggregation strategy on the multicast pattern
+ .multicast(new BankResponseAggregationStrategy())
+ // Send out the request the below three different banks
sequentially
+ .to(Constants.BANK1_URI, Constants.BANK2_URI,
Constants.BANK3_URI);
+
+ // Router 2 to call the bank endpoints parallelly
+ from(Constants.PARALLEL_LOANBROKER_URI)
+ .process(new CreditScoreProcessor(Constants.CREDITAGENCY_ADDRESS))
+ // Using the thread pool to send out message to the below
three different banks parallelly
+ .multicast(new BankResponseAggregationStrategy(), true)
+ .to(Constants.BANK1_URI, Constants.BANK2_URI,
Constants.BANK3_URI);
+ //END SNIPPET: dsl
}
+ //START SNIPPET: credit
class CreditScoreProcessor implements Processor {
private String creditAgencyAddress;
private CreditAgencyWS proxy;
@@ -97,9 +110,10 @@
}
private CreditAgencyWS getProxy() {
+ // Here we use JaxWs front end to create the proxy
JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
- clientBean.setAddress(Constants.CREDITAGENCY_ADDRESS);
+ clientBean.setAddress(creditAgencyAddress);
clientBean.setServiceClass(CreditAgencyWS.class);
clientBean.setBus(BusFactory.getDefaultBus());
return (CreditAgencyWS)proxyFactory.create();
@@ -115,7 +129,6 @@
Integer loanDuriation = (Integer)request.get(2);
int historyLength = proxy.getCreditHistoryLength(ssn);
int score = proxy.getCreditScore(ssn);
- //exchange.getOut().setBody("The ssn's historyLength is " +
historyLength + " score is " + score);
// create the invocation message for Bank client
List<Object> bankRequest = new ArrayList<Object>();
@@ -129,6 +142,6 @@
}
}
-
+ //END SNIPPET: credit
}
Modified:
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBrokerWS.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBrokerWS.java?rev=663935&r1=663934&r2=663935&view=diff
==============================================================================
---
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBrokerWS.java
(original)
+++
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBrokerWS.java
Fri Jun 6 06:29:15 2008
@@ -16,8 +16,12 @@
*/
package org.apache.camel.loanbroker.webservice.version;
+//START SNIPPET: loanBroker
+
+// This SEI has no @WebService annotation, we use the simple frontend API to
create client and server
public interface LoanBrokerWS {
String getLoanQuote(String ssn, Double loanAmount, Integer loanDuriation);
}
+//END SNIPPET: loanBroker
Modified:
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/bank/Bank.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/bank/Bank.java?rev=663935&r1=663934&r2=663935&view=diff
==============================================================================
---
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/bank/Bank.java
(original)
+++
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/bank/Bank.java
Fri Jun 6 06:29:15 2008
@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.camel.loanbroker.webservice.version.bank;
-
+//START SNIPPET: bankImpl
public class Bank implements BankWS {
private String bankName;
private double primeRate;
@@ -41,6 +41,5 @@
return result;
}
-
-
}
+//END SNIPPET: bankImpl
Modified:
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/bank/BankWS.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/bank/BankWS.java?rev=663935&r1=663934&r2=663935&view=diff
==============================================================================
---
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/bank/BankWS.java
(original)
+++
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/bank/BankWS.java
Fri Jun 6 06:29:15 2008
@@ -18,6 +18,8 @@
import javax.jws.WebService;
+//START SNIPPET: bank
+// Since we use @WebServices here, please make sure to use JaxWs frontend API
create the client and server
@WebService
public interface BankWS {
@@ -27,3 +29,4 @@
BankQuote getQuote(String ssn, double loanAmount, int loanDuration, int
creditHistory, int creditScore);
}
+//END SNIPPET: bank
\ No newline at end of file
Modified:
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/credit/CreditAgency.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/credit/CreditAgency.java?rev=663935&r1=663934&r2=663935&view=diff
==============================================================================
---
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/credit/CreditAgency.java
(original)
+++
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/credit/CreditAgency.java
Fri Jun 6 06:29:15 2008
@@ -29,3 +29,4 @@
}
}
+//END SNIPPET: creditAgencyImpl
Modified:
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/credit/CreditAgencyWS.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/credit/CreditAgencyWS.java?rev=663935&r1=663934&r2=663935&view=diff
==============================================================================
---
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/credit/CreditAgencyWS.java
(original)
+++
activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/credit/CreditAgencyWS.java
Fri Jun 6 06:29:15 2008
@@ -18,6 +18,7 @@
import javax.jws.WebService;
+//START SNIPPET: creditAgency
@WebService
public interface CreditAgencyWS {
@@ -26,3 +27,4 @@
int getCreditHistoryLength(String ssn);
}
+//END SNIPPET: creditAgency
\ No newline at end of file