use of org.apache.axis2.transport.msmq.util.Message 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);
}
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class RabbitMQUtils method setSOAPEnvelope.
public static void setSOAPEnvelope(RabbitMQMessage message, MessageContext msgContext, String contentType) throws AxisFault {
int index = contentType.indexOf(';');
String type = index > 0 ? contentType.substring(0, index) : contentType;
Builder builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
if (builder == null) {
if (log.isDebugEnabled()) {
log.debug("No message builder found for type '" + type + "'. Falling back to SOAP.");
}
builder = new SOAPBuilder();
}
OMElement documentElement;
String charSetEnc = null;
try {
if (contentType != null) {
charSetEnc = new ContentType(contentType).getParameter("charset");
}
} catch (ParseException ex) {
log.debug("Parse error", ex);
}
msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
documentElement = builder.processDocument(new ByteArrayInputStream(message.getBody()), contentType, msgContext);
msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class GSMImplManager method sendSMS.
public void sendSMS(SMSMessage sm) throws AxisFault {
if (service == null && !serviceRepo.gatewayInUse(gsmTransportOutDetails.getGatewayId())) {
// Operating in the Out Only mode
service = new Service();
gateway = new SerialModemGateway(gsmTransportOutDetails.getGatewayId(), gsmTransportOutDetails.getComPort(), gsmTransportOutDetails.getBaudRate(), gsmTransportOutDetails.getManufacturer(), gsmTransportOutDetails.getModel());
// Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
gateway.setProtocol(AGateway.Protocols.PDU);
// Do we want the Gateway to be used for Outbound messages?
gateway.setOutbound(true);
// Let SMSLib know which is the SIM PIN.
gateway.setSimPin("0000");
try {
// Add the Gateway to the Service object.
this.service.addGateway(gateway);
// Similarly, you may define as many Gateway objects, representing
// various GSM modems, add them in the Service object and control all of them.
// Start! (i.e. connect to all defined Gateways)
this.service.startService();
} catch (Exception e) {
throw new AxisFault(e.getMessage(), e);
}
} else if (serviceRepo.gatewayInUse(gsmTransportOutDetails.getGatewayId())) {
service = serviceRepo.getService(gsmTransportOutDetails.getGatewayId());
}
OutboundMessage msg = new OutboundMessage(sm.getReceiver(), sm.getContent());
try {
// a blocking call.This will be blocked untill the message is sent.
// normal rate is about 6msgs per minute
service.sendMessage(msg);
} catch (Exception e) {
throw new AxisFault(e.getMessage(), e);
}
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class SMPPDispatcher method dispatch.
void dispatch(String source, String receiver, String message, Map<String, Object> properties) throws AxisFault {
synchronized (this) {
smsMessage = new SMSMessage(source, receiver, message, SMSMessage.IN_MESSAGE);
smsMessage.getProperties().putAll(properties);
}
manager.dispatchToAxis2(smsMessage);
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class AxisTestClient method afterReceive.
public void afterReceive() throws Exception {
if (sender instanceof ManagementSupport) {
ManagementSupport sender = (ManagementSupport) this.sender;
synchronized (metrics) {
long start = System.currentTimeMillis();
while (true) {
try {
Assert.assertEquals(1, metrics.getMessagesSent());
Assert.assertEquals(messagesSent + 1, sender.getMessagesSent());
long thisBytesSent = metrics.getBytesSent();
Assert.assertTrue("No increase in bytes sent in message level metrics", thisBytesSent != 0);
long newBytesSent = sender.getBytesSent();
Assert.assertTrue("No increase in bytes sent in transport level metrics", newBytesSent > bytesSent);
Assert.assertEquals("Mismatch between message and transport level metrics", thisBytesSent, newBytesSent - bytesSent);
break;
} catch (AssertionFailedError ex) {
// SYNAPSE-491: Maybe the transport sender didn't finish updating the
// metrics yet. We give it a couple of seconds to do so.
long remaining = start + 5000 - System.currentTimeMillis();
if (remaining <= 0) {
throw ex;
} else {
log.debug("The transport sender didn't update the metrics yet (" + ex.getMessage() + "). Waiting for " + remaining + " ms.");
metrics.wait(remaining);
}
}
}
}
log.debug("Message level metrics check OK");
}
}
Aggregations