bank.java

来自「基于eclipse环境下开发的servicemix例程」· Java 代码 · 共 60 行

JAVA
60
字号

package houseloanbroker;

import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.InOut;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
import javax.xml.namespace.QName;

import org.apache.servicemix.MessageExchangeListener;
import org.apache.servicemix.components.util.ComponentSupport;
import org.apache.servicemix.jbi.jaxp.StringSource;

public class Bank extends ComponentSupport implements MessageExchangeListener {
    
    private double rate;
    private double firstPaidRatio;
	
	
    public Bank(int number) {
        setService(new QName("urn:sample:soa:bank", "Bank" + number));
        setEndpoint("bank");
    }
    
    public void onMessageExchange(MessageExchange exchange) throws MessagingException {
    	
        InOut inOut = (InOut) exchange;
        if (inOut.getStatus() == ExchangeStatus.DONE) {
            return;
        } else if (inOut.getStatus() == ExchangeStatus.ERROR) {
            return;
        }
        System.err.println(getService().getLocalPart() + " requested");
        try {
            String output = "<getLoanQuoteResponse xmlns=\"urn:sample:soa:bank\"><rate>" + getRate() + "</rate><firstpaidratio>" + getFirstPaidRatio() + "</firstpaidratio></getLoanQuoteResponse>";
            NormalizedMessage answer = inOut.createMessage();
            answer.setContent(new StringSource(output));
            answer(inOut, answer);
        } catch (Exception e) {
            throw new MessagingException(e);
        }
    }

	public double getFirstPaidRatio() {
		return firstPaidRatio;
	}

	public void setFirstPaidRatio(double firstPaidRatio) {
		this.firstPaidRatio = firstPaidRatio;
	}

	public double getRate() {
		return rate;
	}

	public void setRate(double rate) {
		this.rate = rate;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?