@Override
public void sendMessage(MessageContext msgCtx, String targetEPR, OutTransportInfo outTransportInfo) throws AxisFault{
AMQPOutTransportInfo amqpTransportInfo = null;
ConnectionDetails conDetails = null;
Session session = null;
// If targetEPR is not null, determine the addressing info from it
if (targetEPR != null) {
amqpTransportInfo = new AMQPOutTransportInfo(targetEPR);
}
// If not try to get the addressing info from the transport description
else if (outTransportInfo != null && outTransportInfo instanceof AMQPOutTransportInfo) {
amqpTransportInfo = (AMQPOutTransportInfo) outTransportInfo;
}
if (_connectionDetails.containsKey(amqpTransportInfo.getConnectionURL())){
conDetails = _connectionDetails.get(amqpTransportInfo.getConnectionURL());
}else{
// else create a new connection
Connection con = Client.createConnection();
try{
con.connect(amqpTransportInfo.getConnectionURL());
}catch(Exception e){
throw new AMQPSynapseException("Error creating a connection to the broker",e);
}
_connectionDetails.put(amqpTransportInfo.getConnectionURL(), new ConnectionDetails(con));
}
if (conDetails != null) {
session = conDetails.getSession();
}
byte[] message = null;
try {
message = createMessageData(msgCtx);
} catch (AMQPSynapseException e) {
handleException("Error creating a message from the axis message context", e);
}
// should we wait for a synchronous response on this same thread?
boolean waitForResponse = waitForSynchronousResponse(msgCtx);
DeliveryProperties deliveryProps = new DeliveryProperties();
MessageProperties msgProps = new MessageProperties();
fillMessageHeaders(msgCtx,amqpTransportInfo,session,waitForResponse,deliveryProps,msgProps);
synchronized(session){
session.header(msgProps,deliveryProps);
session.data(message);
session.endData();
}
// if we are expecting a synchronous response back for the message sent out
if (waitForResponse) {
waitForResponseAndProcess(session, msgProps, msgCtx);