Search in sources :

Example 6 with AxisRabbitMQException

use of org.apache.axis2.transport.rabbitmq.utils.AxisRabbitMQException in project wso2-axis2-transports by wso2.

the class RabbitMQSender method init.

/**
 * Initialize the transport sender by reading pre-defined connection factories for
 * outgoing messages.
 *
 * @param cfgCtx       the configuration context
 * @param transportOut the transport sender definition from axis2.xml
 * @throws AxisFault on error
 */
@Override
public void init(ConfigurationContext cfgCtx, TransportOutDescription transportOut) throws AxisFault {
    try {
        super.init(cfgCtx, transportOut);
        SecretResolver secretResolver = cfgCtx.getAxisConfiguration().getSecretResolver();
        // initialize connection factory and pool
        rabbitMQConnectionFactory = new RabbitMQConnectionFactory();
        int poolSize = RabbitMQUtils.resolveTransportDescription(transportOut, secretResolver, rabbitMQConnectionFactory);
        RabbitMQConnectionPool rabbitMQConnectionPool = new RabbitMQConnectionPool(rabbitMQConnectionFactory, poolSize);
        // initialize channel factory and pool
        RabbitMQChannelFactory rabbitMQChannelFactory = new RabbitMQChannelFactory(rabbitMQConnectionPool);
        rabbitMQChannelPool = new RabbitMQChannelPool(rabbitMQChannelFactory, poolSize);
        // initialize confirm channel factory and pool
        RabbitMQConfirmChannelFactory rabbitMQConfirmChannelFactory = new RabbitMQConfirmChannelFactory(rabbitMQConnectionPool);
        rabbitMQConfirmChannelPool = new RabbitMQChannelPool(rabbitMQConfirmChannelFactory, poolSize);
        log.info("RabbitMQ AMQP Transport Sender initialized...");
    } catch (AxisRabbitMQException e) {
        throw new AxisFault("Error occurred while initializing the RabbitMQ AMQP Transport Sender.", e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) SecretResolver(org.wso2.securevault.SecretResolver)

Example 7 with AxisRabbitMQException

use of org.apache.axis2.transport.rabbitmq.utils.AxisRabbitMQException in project wso2-axis2-transports by wso2.

the class RabbitMQRPCMessageSender method send.

public RabbitMQMessage send(RabbitMQMessage message, MessageContext msgContext) throws AxisRabbitMQException, IOException {
    publish(message, msgContext);
    RabbitMQMessage responseMessage = processResponse(message.getCorrelationId());
    // release the dual channel to the pool
    try {
        connectionFactory.pushRPCChannel(dualChannel);
    } catch (InterruptedException e) {
        handleException(e.getMessage());
    }
    return responseMessage;
}
Also used : RabbitMQMessage(org.apache.axis2.transport.rabbitmq.RabbitMQMessage)

Example 8 with AxisRabbitMQException

use of org.apache.axis2.transport.rabbitmq.utils.AxisRabbitMQException in project wso2-axis2-transports by wso2.

the class RabbitMQSender method sendOverAMQP.

/**
 * Perform actual sending of the AMQP message
 */
private void sendOverAMQP(RabbitMQConnectionFactory factory, MessageContext msgContext, String targetEPR) throws AxisFault {
    try {
        RabbitMQMessage message = new RabbitMQMessage(msgContext);
        Hashtable<String, String> epProperties = BaseUtils.getEPRProperties(targetEPR);
        if (!StringUtils.isEmpty(epProperties.get(RabbitMQConstants.REPLY_TO_NAME))) {
            // request-response scenario
            RabbitMQRPCMessageSender sender = new RabbitMQRPCMessageSender(factory, targetEPR, epProperties);
            RabbitMQMessage responseMessage = sender.send(message, msgContext);
            MessageContext responseMsgCtx = createResponseMessageContext(msgContext);
            RabbitMQUtils.setSOAPEnvelope(responseMessage, responseMsgCtx, responseMessage.getContentType());
            handleIncomingMessage(responseMsgCtx, RabbitMQUtils.getTransportHeaders(responseMessage), responseMessage.getSoapAction(), responseMessage.getContentType());
        } else {
            // Basic out only publish
            RabbitMQMessageSender sender = new RabbitMQMessageSender(factory, targetEPR, epProperties);
            sender.send(message, msgContext);
        }
    } catch (AxisRabbitMQException e) {
        handleException("Error occurred while sending message out", e);
    } catch (IOException e) {
        handleException("Error occurred while sending message out", e);
    }
}
Also used : RabbitMQRPCMessageSender(org.apache.axis2.transport.rabbitmq.rpc.RabbitMQRPCMessageSender) AxisRabbitMQException(org.apache.axis2.transport.rabbitmq.utils.AxisRabbitMQException) MessageContext(org.apache.axis2.context.MessageContext) IOException(java.io.IOException)

Aggregations

AxisFault (org.apache.axis2.AxisFault)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)3 MessageFormatter (org.apache.axis2.transport.MessageFormatter)3 AxisRabbitMQException (org.apache.axis2.transport.rabbitmq.utils.AxisRabbitMQException)3 AMQP (com.rabbitmq.client.AMQP)2 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)2 SecretResolver (org.wso2.securevault.SecretResolver)2 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMElement (org.apache.axiom.om.OMElement)1 MessageContext (org.apache.axis2.context.MessageContext)1 Parameter (org.apache.axis2.description.Parameter)1 ParameterIncludeImpl (org.apache.axis2.description.ParameterIncludeImpl)1 RabbitMQMessage (org.apache.axis2.transport.rabbitmq.RabbitMQMessage)1 RabbitMQRPCMessageSender (org.apache.axis2.transport.rabbitmq.rpc.RabbitMQRPCMessageSender)1 SecureVaultException (org.wso2.securevault.SecureVaultException)1