use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.
the class SMSManager method dispatchToAxis2.
/**
* Dispatch the SMS message to Axis2 Engine
* @param sms
*/
public void dispatchToAxis2(SMSMessage sms) {
try {
MessageContext msgctx = messageBuilder.buildMessaage(sms, configurationContext);
msgctx.setReplyTo(new EndpointReference("sms://" + sms.getSender() + "/"));
AxisEngine.receive(msgctx);
} catch (InvalidMessageFormatException e) {
log.debug("Invalid message format " + e);
} catch (AxisFault axisFault) {
log.debug(axisFault);
} catch (Throwable e) {
log.debug("Unknown Exception ", e);
}
}
use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.
the class TCPTransportSender method writeMessageOut.
/**
* Writing the message to the output stream of the TCP socket after applying correct message formatter
* This method is synchronized because there will be issue when formatter write to same output stream which causes
* to mixed messages
*
* @param msgContext the message context
* @param outputStream the socket output stream
* @throws AxisFault if error occurred
* @throws IOException if IO exception occurred
*/
private synchronized void writeMessageOut(MessageContext msgContext, OutputStream outputStream, String delimiter, String delimiterType) throws AxisFault, IOException {
MessageFormatter messageFormatter = BaseUtils.getMessageFormatter(msgContext);
OMOutputFormat format = BaseUtils.getOMOutputFormat(msgContext);
messageFormatter.writeTo(msgContext, format, outputStream, true);
if (delimiter != null && !delimiter.isEmpty()) {
if (TCPConstants.BYTE_DELIMITER_TYPE.equalsIgnoreCase(delimiterType)) {
outputStream.write((char) Integer.parseInt(delimiter.split("0x")[1], 16));
} else {
outputStream.write(delimiter.getBytes());
}
}
outputStream.flush();
}
use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.
the class PlainTextFormatter method writeTo.
public void writeTo(MessageContext messageContext, OMOutputFormat format, OutputStream outputStream, boolean preserve) throws AxisFault {
// preserve boolean is not used because new implementation doesn't need it. However, it's there to
// to have backward compatibility.
OMElement textElt = messageContext.getEnvelope().getBody().getFirstElement();
if (BaseConstants.DEFAULT_TEXT_WRAPPER.equals(textElt.getQName())) {
try {
Writer out = new OutputStreamWriter(outputStream, format.getCharSetEncoding());
out.write(textElt.getFirstElement() == null ? textElt.getText() : textElt.getFirstElement().toString());
out.flush();
} catch (IOException e) {
throw new AxisFault("Error writing text message to stream", e);
} catch (Exception e) {
throw new AxisFault("Error extracting the text payload from the message", e);
}
}
}
use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.
the class AbstractTransportListener method createMessageContext.
/**
* Create a new axis MessageContext for an incoming message through this transport
* @return the newly created message context
*/
public MessageContext createMessageContext() {
MessageContext msgCtx = new MessageContext();
msgCtx.setConfigurationContext(cfgCtx);
msgCtx.setIncomingTransportName(getTransportName());
msgCtx.setTransportOut(transportOut);
msgCtx.setTransportIn(transportIn);
msgCtx.setServerSide(true);
msgCtx.setMessageID(UUIDGenerator.getUUID());
// There is a discrepency in what I thought, Axis2 spawns a nes threads to
// send a message is this is TRUE - and I want it to be the other way
msgCtx.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, Boolean.valueOf(!isNonBlocking));
return msgCtx;
}
use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.
the class PlainTextFormatterTest method testGetBytes.
private void testGetBytes(String encoding) throws Exception {
MessageContext messageContext = createMessageContext(testString);
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(encoding);
byte[] bytes = new PlainTextFormatter().getBytes(messageContext, format);
assertEquals(testString, new String(bytes, encoding));
}
Aggregations