use of javax.mail.internet.ParseException 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()));
}
// set the Mail Message ID as the Message ID of the MessageContext if Mail Message ID is not null
if (outInfo.getRequestMessageID() != null) {
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 javax.mail.internet.ParseException in project jbossws-cxf by jbossws.
the class SOAP11ClientHandler method getContentType.
protected ContentType getContentType(MessageContext msgContext) {
ContentType contentType = null;
try {
// Metro does not process this header into the message
@SuppressWarnings("unchecked") Map<String, List<String>> headers = (Map<String, List<String>>) msgContext.get(MessageContext.HTTP_REQUEST_HEADERS);
List<String> ctype = (headers == null) ? null : headers.get("Content-Type");
if (ctype == null) {
// Cxf stores it in lower case
ctype = (headers == null) ? null : headers.get("content-type");
}
log.info("ctype=" + ctype);
if (ctype == null) {
// Native has already processed this header into the message
SOAPMessage soapMessage = ((SOAPMessageContext) msgContext).getMessage();
MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
String[] ct = mimeHeaders.getHeader("Content-Type");
log.info("ct=" + ct);
if (ct != null) {
contentType = new ContentType(ct[0]);
}
} else {
contentType = new ContentType(ctype.get(0));
}
} catch (ParseException e) {
throw new WebServiceException(e);
}
return contentType;
}
use of javax.mail.internet.ParseException in project jbossws-cxf by jbossws.
the class SOAP11ServerHandler method getContentType.
protected ContentType getContentType(MessageContext msgContext) {
ContentType contentType = null;
try {
// Metro does not process this header into the message
@SuppressWarnings("unchecked") Map<String, List<String>> headers = (Map<String, List<String>>) msgContext.get(MessageContext.HTTP_REQUEST_HEADERS);
List<String> ctype = (headers == null) ? null : headers.get("Content-Type");
if (ctype == null) {
// Cxf stores it in lower case
ctype = (headers == null) ? null : headers.get("content-type");
}
log.info("ctype=" + ctype);
if (ctype == null) {
// Native has already processed this header into the message
SOAPMessage soapMessage = ((SOAPMessageContext) msgContext).getMessage();
MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
String[] ct = mimeHeaders.getHeader("Content-Type");
log.info("ct=" + ct);
if (ct != null) {
contentType = new ContentType(ct[0]);
}
} else {
contentType = new ContentType(ctype.get(0));
}
} catch (ParseException e) {
throw new WebServiceException(e);
}
return contentType;
}
use of javax.mail.internet.ParseException in project jbossws-cxf by jbossws.
the class SOAP12ClientHandler method getContentType.
protected ContentType getContentType(MessageContext msgContext) {
ContentType contentType = null;
try {
// Metro does not process this header into the message
@SuppressWarnings("unchecked") Map<String, List<String>> headers = (Map<String, List<String>>) msgContext.get(MessageContext.HTTP_REQUEST_HEADERS);
List<String> ctype = (headers == null) ? null : headers.get("Content-Type");
if (ctype == null) {
// Cxf stores it in lower case
ctype = (headers == null) ? null : headers.get("content-type");
}
log.info("ctype=" + ctype);
if (ctype == null) {
// Native has already processed this header into the message
SOAPMessage soapMessage = ((SOAPMessageContext) msgContext).getMessage();
MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
String[] ct = mimeHeaders.getHeader("Content-Type");
log.info("ct=" + ct);
if (ct != null) {
contentType = new ContentType(ct[0]);
}
} else {
contentType = new ContentType(ctype.get(0));
}
} catch (ParseException e) {
throw new WebServiceException(e);
}
return contentType;
}
use of javax.mail.internet.ParseException in project jbossws-cxf by jbossws.
the class SOAP12ServerHandler method getContentType.
protected ContentType getContentType(SOAPMessageContext msgContext) {
ContentType contentType = null;
try {
// Metro does not process this header into the message
@SuppressWarnings("unchecked") Map<String, List<String>> headers = (Map<String, List<String>>) msgContext.get(MessageContext.HTTP_REQUEST_HEADERS);
List<String> ctype = (headers == null) ? null : headers.get("Content-Type");
if (ctype == null) {
// Cxf stores it in lower case
ctype = (headers == null) ? null : headers.get("content-type");
}
log.info("ctype=" + ctype);
if (ctype == null) {
// Native has already processed this header into the message
SOAPMessage soapMessage = ((SOAPMessageContext) msgContext).getMessage();
MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
String[] ct = mimeHeaders.getHeader("Content-Type");
log.info("ct=" + ct);
if (ct != null) {
contentType = new ContentType(ct[0]);
}
} else {
contentType = new ContentType(ctype.get(0));
}
} catch (ParseException e) {
throw new WebServiceException(e);
}
return contentType;
}
Aggregations