01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package loanbroker;
18:
19: import javax.annotation.Resource;
20: import javax.jbi.messaging.DeliveryChannel;
21: import javax.jbi.messaging.ExchangeStatus;
22: import javax.jbi.messaging.InOut;
23: import javax.jbi.messaging.MessageExchange;
24: import javax.jbi.messaging.MessagingException;
25: import javax.jbi.messaging.NormalizedMessage;
26:
27: import org.apache.servicemix.MessageExchangeListener;
28: import org.apache.servicemix.jbi.jaxp.StringSource;
29:
30: public class Bank implements MessageExchangeListener {
31:
32: @Resource
33: DeliveryChannel channel;
34:
35: public void onMessageExchange(MessageExchange exchange)
36: throws MessagingException {
37: InOut inOut = (InOut) exchange;
38: if (inOut.getStatus() == ExchangeStatus.DONE) {
39: return;
40: } else if (inOut.getStatus() == ExchangeStatus.ERROR) {
41: return;
42: }
43: System.err.println(inOut.getService().getLocalPart()
44: + " requested");
45: try {
46: String output = "<getLoanQuoteResponse xmlns=\"urn:logicblaze:soa:bank\"><rate>"
47: + (Math.ceil(1000 * Math.random()) / 100)
48: + "</rate></getLoanQuoteResponse>";
49: NormalizedMessage answer = inOut.createMessage();
50: answer.setContent(new StringSource(output));
51: inOut.setOutMessage(answer);
52: channel.send(inOut);
53: } catch (Exception e) {
54: inOut.setError(e);
55: channel.send(inOut);
56: }
57: }
58: }
|