/**
* The main workhorse method.
*/
public void run() {
AxisEngine engine = new AxisEngine(configContext);
MessageContext msgContext = null;
// create and initialize a message context
try {
TransportInDescription transportIn =
configContext.getAxisConfiguration().getTransportIn(new QName(Constants.TRANSPORT_MAIL));
TransportOutDescription transportOut =
configContext.getAxisConfiguration().getTransportOut(new QName(Constants.TRANSPORT_MAIL));
if ((transportIn != null) && (transportOut != null)) {
// create Message Context
msgContext = new MessageContext();
msgContext.setConfigurationContext(configContext);
msgContext.setTransportIn(transportIn);
msgContext.setTransportOut(transportOut);
msgContext.setServerSide(true);
msgContext.setProperty(MailSrvConstants.CONTENT_TYPE, mimeMessage.getContentType());
msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING,
mimeMessage.getEncoding());
String soapAction = getMailHeader(MailSrvConstants.HEADER_SOAP_ACTION);
msgContext.setWSAAction(soapAction);
msgContext.setSoapAction(soapAction);
msgContext.setIncomingTransportName(Constants.TRANSPORT_MAIL);
// TODO add the transport Headers to the Message Context
// Create Mail EPR, EPR is constructed using the format, foo@bar/axis2/services/echo and is constructed
// using the <to-email-address>/<email-subject>
InternetAddress[] recepainets = (InternetAddress[]) mimeMessage.getAllRecipients();
if ((recepainets != null) && (recepainets.length > 0)) {
} else {
throw new AxisFault(Messages.getMessage("noRecep4Email"));
}
// try to assume the reply to value
InternetAddress[] replyToAs = (InternetAddress[]) mimeMessage.getAllRecipients();
if ((replyToAs != null) && (replyToAs.length > 0)) {
String replyTo = replyToAs[0].getAddress();
if (replyTo != null) {
msgContext.setReplyTo(new EndpointReference(replyTo));
}
}
// Create the SOAP Message
// TODO This can we written better way, to use the streams better
String message = mimeMessage.getContent().toString();
ByteArrayInputStream bais =
new ByteArrayInputStream(message.getBytes());
XMLStreamReader reader =
XMLInputFactory.newInstance().createXMLStreamReader(bais);
String soapNamespaceURI = "";
if (mimeMessage.getContentType().indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE)
> -1) {
soapNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
} else if (mimeMessage.getContentType().indexOf(
SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
soapNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
}
StAXBuilder builder = new StAXSOAPModelBuilder(reader, soapNamespaceURI);
SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
msgContext.setEnvelope(envelope);
if (envelope.getBody().hasFault()) {
engine.receiveFault(msgContext);
} else {
engine.receive(msgContext);
}
} else {
throw new AxisFault(Messages.getMessage("unknownTransport",
Constants.TRANSPORT_MAIL));
}
} catch (Exception e) {
try {
if (msgContext != null) {
MessageContext faultContext = engine.createFaultMessageContext(msgContext, e);
engine.sendFault(faultContext);
} else {
log.error(e);
}
} catch (AxisFault e1) {
log.error(e);