Search in sources :

Example 21 with ParseException

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());
    }
}
Also used : ContentType(javax.mail.internet.ContentType) XMLStreamException(javax.xml.stream.XMLStreamException) MimeBodyPart(javax.mail.internet.MimeBodyPart) InputStream(java.io.InputStream) MessageContext(org.apache.axis2.context.MessageContext) ParseException(javax.mail.internet.ParseException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 22 with ParseException

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;
}
Also used : ContentType(javax.mail.internet.ContentType) WebServiceException(javax.xml.ws.WebServiceException) SOAPMessage(javax.xml.soap.SOAPMessage) MimeHeaders(javax.xml.soap.MimeHeaders) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) List(java.util.List) ParseException(javax.mail.internet.ParseException) Map(java.util.Map)

Example 23 with ParseException

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;
}
Also used : ContentType(javax.mail.internet.ContentType) WebServiceException(javax.xml.ws.WebServiceException) SOAPMessage(javax.xml.soap.SOAPMessage) MimeHeaders(javax.xml.soap.MimeHeaders) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) List(java.util.List) ParseException(javax.mail.internet.ParseException) Map(java.util.Map)

Example 24 with ParseException

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;
}
Also used : ContentType(javax.mail.internet.ContentType) WebServiceException(javax.xml.ws.WebServiceException) SOAPMessage(javax.xml.soap.SOAPMessage) MimeHeaders(javax.xml.soap.MimeHeaders) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) List(java.util.List) ParseException(javax.mail.internet.ParseException) Map(java.util.Map)

Example 25 with ParseException

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;
}
Also used : ContentType(javax.mail.internet.ContentType) WebServiceException(javax.xml.ws.WebServiceException) SOAPMessage(javax.xml.soap.SOAPMessage) MimeHeaders(javax.xml.soap.MimeHeaders) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) List(java.util.List) ParseException(javax.mail.internet.ParseException) Map(java.util.Map)

Aggregations

ParseException (javax.mail.internet.ParseException)29 ContentType (javax.mail.internet.ContentType)25 ByteString (com.linkedin.data.ByteString)6 Map (java.util.Map)6 IOException (java.io.IOException)5 List (java.util.List)5 MimeHeaders (javax.xml.soap.MimeHeaders)5 SOAPMessage (javax.xml.soap.SOAPMessage)5 InputStream (java.io.InputStream)4 WebServiceException (javax.xml.ws.WebServiceException)4 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)4 Builder (org.apache.axis2.builder.Builder)4 SOAPBuilder (org.apache.axis2.builder.SOAPBuilder)4 MultiPartMIMEReader (com.linkedin.multipart.MultiPartMIMEReader)3 BodyPart (javax.mail.BodyPart)3 MessagingException (javax.mail.MessagingException)3 MimeBodyPart (javax.mail.internet.MimeBodyPart)3 MimeMultipart (javax.mail.internet.MimeMultipart)3 Callback (com.linkedin.common.callback.Callback)2 MultiPartMIMEWriter (com.linkedin.multipart.MultiPartMIMEWriter)2