use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class DefaultSMSMessageBuilderImpl method buildMessaage.
public MessageContext buildMessaage(SMSMessage msg, ConfigurationContext configurationContext) throws InvalidMessageFormatException {
String message = msg.getContent();
String sender = msg.getSender();
String receiver = msg.getReceiver();
String[] parts = message.split(":");
// may be can add feature to send message format for a request like ????
if (parts.length < 2) {
throw new InvalidMessageFormatException("format must be \"service_name \" : \"opration_name\" : " + "\"parm_1=val_1\" :..:\"param_n = val_n\"");
} else {
AxisConfiguration repo = configurationContext.getAxisConfiguration();
MessageContext messageContext = configurationContext.createMessageContext();
parts = trimSplited(parts);
try {
AxisService axisService = repo.getService(parts[0]);
if (axisService == null) {
throw new InvalidMessageFormatException("Service : " + parts[0] + "does not exsist");
} else {
messageContext.setAxisService(axisService);
AxisOperation axisOperation = axisService.getOperation(new QName(parts[1]));
if (axisOperation == null) {
throw new InvalidMessageFormatException("Operation: " + parts[1] + " does not exsist");
}
messageContext.setAxisOperation(axisOperation);
messageContext.setAxisMessage(axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
Map params = getParams(parts, 2);
SOAPEnvelope soapEnvelope = createSoapEnvelope(messageContext, params);
messageContext.setServerSide(true);
messageContext.setEnvelope(soapEnvelope);
TransportInDescription in = configurationContext.getAxisConfiguration().getTransportIn("sms");
TransportOutDescription out = configurationContext.getAxisConfiguration().getTransportOut("sms");
messageContext.setIncomingTransportName("sms");
messageContext.setProperty(SMSTransportConstents.SEND_TO, sender);
messageContext.setProperty(SMSTransportConstents.DESTINATION, receiver);
messageContext.setTransportIn(in);
messageContext.setTransportOut(out);
handleSMSProperties(msg, messageContext);
return messageContext;
}
} catch (AxisFault axisFault) {
log.debug("[DefaultSMSMessageBuilderImpl] Error while extracting the axis2Service \n" + axisFault);
}
}
return null;
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class SMSManager method sendSMS.
/**
* send a SMS form the message comming form the Axis2 Engine
* @param messageContext that is comming form the Axis2
*/
public void sendSMS(MessageContext messageContext) throws AxisFault {
try {
SMSMessage sms = messageFormatter.formatSMS(messageContext);
sms.addProperty(SMSTransportConstents.INVERT_SOURCE_AND_DESTINATION, "" + invertSourceAndDestination);
currentImplimentation.sendSMS(sms);
} catch (Exception e) {
log.error("Error while sending the SMS ", 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 MailTransportListener method processMail.
/**
* Process a mail message through Axis2
*
* @param message the email message
* @param entry the poll table entry
* @throws MessagingException on error
* @throws IOException on error
*/
private void processMail(Message message, PollTableEntry entry) throws MessagingException, IOException {
updateMetrics(message);
// populate transport headers using the mail headers
Map trpHeaders = getTransportHeaders(message, entry);
// Allow the content type to be overridden by configuration.
String contentType = entry.getContentType();
Part messagePart;
if (contentType != null) {
messagePart = message;
} else {
messagePart = getMessagePart(message, cfgCtx.getAxisConfiguration());
contentType = messagePart.getContentType();
}
// FIXME: remove this ugly hack when Axis2 has learned that content types are case insensitive...
int idx = contentType.indexOf(';');
if (idx == -1) {
contentType = contentType.toLowerCase();
} else {
contentType = contentType.substring(0, idx).toLowerCase() + contentType.substring(idx);
}
// if the content type was not found, we have an error
if (contentType == null) {
processFailure("Unable to determine Content-type for message : " + message.getMessageNumber() + " :: " + message.getSubject(), null, entry);
return;
} else if (log.isDebugEnabled()) {
log.debug("Processing message as Content-Type : " + contentType);
}
MessageContext msgContext = entry.createMessageContext();
// Extract the charset encoding from the configured content type and
// set the CHARACTER_SET_ENCODING property as e.g. SOAPBuilder relies on this.
String charSetEnc;
try {
charSetEnc = new ContentType(contentType).getParameter("charset");
} catch (ParseException ex) {
// ignore
charSetEnc = null;
}
msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
MailOutTransportInfo outInfo = buildOutTransportInfo(message, entry);
// save out transport information
msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, outInfo);
// this property only useful for supporting smtp with Sandesha2.
msgContext.setProperty(RequestResponseTransport.TRANSPORT_CONTROL, new MailRequestResponseTransport());
// set message context From
if (outInfo.getFromAddress() != null) {
msgContext.setFrom(new EndpointReference(MailConstants.TRANSPORT_PREFIX + outInfo.getFromAddress().getAddress()));
}
// save original mail message id message context MessageID
msgContext.setMessageID(outInfo.getRequestMessageID());
// set the message payload to the message context
InputStream in = messagePart.getInputStream();
try {
try {
msgContext.setEnvelope(TransportUtils.createSOAPMessage(msgContext, in, contentType));
} catch (XMLStreamException ex) {
handleException("Error parsing message", ex);
}
String soapAction = (String) trpHeaders.get(BaseConstants.SOAPACTION);
if (soapAction == null && message.getSubject() != null && message.getSubject().startsWith(BaseConstants.SOAPACTION)) {
soapAction = message.getSubject().substring(BaseConstants.SOAPACTION.length());
if (soapAction.startsWith(":")) {
soapAction = soapAction.substring(1).trim();
}
}
handleIncomingMessage(msgContext, trpHeaders, soapAction, contentType);
} finally {
in.close();
}
if (log.isDebugEnabled()) {
log.debug("Processed message : " + message.getMessageNumber() + " :: " + message.getSubject());
}
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class MSMQMessageReceiver method processThroughEngine.
/**
* Set up message properties to header as it received as MSMQ message properties
*
* @param message
* @return
* @throws AxisFault
*/
private boolean processThroughEngine(Message message) throws AxisFault {
// TODO: this only support text messages, need to improve it for binay
// messages
// Get the contentType from the MSMQ message
String contentType = message.getLabel();
if (log.isDebugEnabled()) {
log.info("Content Type of the message is : " + contentType);
}
MessageContext msgContext = endpoint.createMessageContext();
SOAPEnvelope soapEnvelope;
if (message.getCorrelationId() != null) {
msgContext.setProperty(MSMQConstants.MSMQ_CORRELATION_ID, message.getCorrelationId());
}
if (msgContext.getParameter(MSMQConstants.PARAM_CONTENT_TYPE).getValue() != null) {
// Overwrite the message's content type with the defined content type in the proxy
contentType = String.valueOf(msgContext.getParameter(MSMQConstants.PARAM_CONTENT_TYPE).getValue());
}
/*
* ContentTypeInfo contentTypeInfo =
* endpoint.getContentTypeRuleSet().getContentTypeInfo(message);
*/
MSMQUtil.setSOAPEnvelope(message, msgContext, contentType);
soapEnvelope = msgContext.getEnvelope();
msmqListener.handleIncomingMessage(msgContext, MSMQUtil.getTransportHeaders(message), null, contentType);
return true;
}
use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.
the class MSMQUtil method setSOAPEnvelope.
public static void setSOAPEnvelope(Message message, MessageContext msgContext, String contentType) throws AxisFault {
if (contentType == null) {
// TODO;we only support text/plain
contentType = "text/plain";
if (log.isDebugEnabled()) {
log.debug("No content type specified; assuming " + contentType);
}
}
int index = contentType.indexOf(';');
String type = index > 0 ? contentType.substring(0, index) : contentType;
Builder builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
String messageBody = null;
try {
messageBody = message.getBodyAsString();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (builder == null) {
if (log.isDebugEnabled()) {
log.debug("No message builder found for type' " + type + ".Using SOAP builder");
}
builder = new SOAPBuilder();
}
OMElement documentElement;
// TODO: we need to handle the message types separately. Assume text message builder format
TextMessageBuilder textMessageBuilder;
if (builder instanceof TextMessageBuilder) {
textMessageBuilder = (TextMessageBuilder) builder;
} else {
textMessageBuilder = new TextMessageBuilderAdapter(builder);
}
documentElement = textMessageBuilder.processDocument(messageBody, contentType, msgContext);
msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
}
Aggregations