追加パッケー�2.context.MessageContext;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.builder.BuilderUtil;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
+import javax.mail.Part;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeBodyPart;
-
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.IOException;
+import javax.mail.internet.ContentType;
+import javax.mail.internet.ParseException;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.activation.DataHandler;
+
+import java.io.*;
+import java.util.List;
+import java.util.ArrayList;
public class MailUtils extends BaseUtils {
@@ -145,4 +164,161 @@
}
}
+ @Override
+ public void setSOAPEnvelope(Object message, MessageContext
msgContext, String contentType) throws AxisFault {
+
+ if (message instanceof MimeMessage &&
+ (contentType.toLowerCase().contains("multipart/
alternative") ||
+ contentType.toLowerCase().contains("multipart/
mixed"))) {
+
+ MultipartParser mp = new MultipartParser((MimeMessage)
message);
+ try {
+ mp.parse();
+ } catch (Exception e) {
+ throw new AxisFault("Error parsing multipart
message", e);
+ }
+
+ SOAPFactory soapFactory = new SOAP11Factory();
+ SOAPEnvelope envelope = null;
+ StAXBuilder builder = null;
+ String charSetEnc = null;
+
+ try {
+ if (mp.getMainTextContentType() != null) {
+ charSetEnc = new
ContentType(mp.getMainTextContentType()).getParameter("charset");
+ }
+ } catch (ParseException ignore) {
+ charSetEnc =
MessageContext.DEFAULT_CHAR_SET_ENCODING;
+ }
+
+ try {
+ // select primary message - in the following order
of priority
+ // SOAP 1.2, SOAP 1.1 / POX, text/plain, text/html
+ if
(mp
.getMainTextContentType
().contains(SOAP12Constants.SOAP_12_CONTENT_TYPE) ||
+
mp
.getMainTextContentType
().contains((SOAP11Constants.SOAP_11_CONTENT_TYPE))) {
+ builder = BuilderUtil.getSOAPBuilder(
+ new
ByteArrayInputStream(mp.getMainText().getBytes(charSetEnc)),
charSetEnc);
+ envelope = (SOAPEnvelope)
builder.getDocumentElement();
+
+ } else if
(mp.getMainTextContentType().toLowerCase().contains(("text/plain"))) {
+
+ // pick the name of the element that will act
as the wrapper element for the
+ // non-xml payload. If service doesn't define
one, default
+ Parameter wrapperParam =
msgContext.getAxisService().
+ getParameter(BaseConstants.WRAPPER_PARAM);
+
+ QName wrapperQName = null;
+ OMElement wrapper = null;
+ if (wrapperParam != null) {
+ wrapperQName =
BaseUtils.getQNameFromString(wrapperParam.getValue());
+ }
+
+ OMTextImpl textData = (OMTextImpl)
soapFactory.createOMText(mp.getMainText());
+
+ if (wrapperQName == null) {
+ wrapperQName =
BaseConstants.DEFAULT_TEXT_WRAPPER;
+ }
+ wrapper =
soapFactory.createOMElement(wrapperQName, null);
+ wrapper.addChild(textData);
+
+ envelope = soapFactory.getDefaultEnvelope();
+ envelope.getBody().addChild(wrapper);
+ }
+ } catch (XMLStreamException e) {
+ handleException("Error building SOAP or POX
payload", e);
+ } catch (UnsupportedEncodingException e) {
+ handleException("Encoding error building SOAP or
POX payload", e);
+ }
+
+ // Set the encoding scheme in the message context
+
msgContext
.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
charSetEnc);
+
+ String charEncOfMessage =
+ builder == null ? null :
+ builder.getDocument() == null ? null :
builder.getDocument().getCharsetEncoding();
+
+ if (StringUtils.isNotBlank(charEncOfMessage) &&
+ StringUtils.isNotBlank(charSetEnc) &&
+ !charSetEnc.equalsIgnoreCase(charEncOfMessage)) {
+ handleException("Charset encodings differs from
whats used in the payload");
+ }
+
+ msgContext.setEnvelope(envelope);
+
+ int cid = 1;
+ for (DataHandler dh : mp.getAttachments()) {
+ msgContext.addAttachment(Integer.toString(cid++),
dh);
+ }
+
+ } else {
+ super.setSOAPEnvelope(message, msgContext, contentType);
+ }
+ }
+
+ private class MultipartParser {
+
+ final MimeMessage msg;
+ private String mainText = null;
+ private String mainTextContentType = null;
+ private List<DataHandler> attachments = new
ArrayList<DataHandler>();
+
+ MultipartParser(MimeMessage msg) {
+ this.msg = msg;
+ }
+
+ public void parse() throws MessagingException, IOException {
+ Multipart mp = (Multipart) msg.getContent();
+ for (int i=0; i<mp.getCount(); i++) {
+ buildContentMap(mp.getBodyPart(i));
+ }
+ }
+
+ private void buildContentMap(Part p) throws
MessagingException, IOException {
+
+ if (p.isMimeType("multipart/alternative")) {
+
+ Multipart mp = (Multipart) p.getContent();
+ for (int i = 0; i < mp.getCount(); i++) {
+
+ Part bp = mp.getBodyPart(i);
+ processBodyPart(bp);
+ }
+
+ } else if (p.isMimeType("multipart/*")) {
+ Multipart mp = (Multipart) p.getContent();
+ for (int i = 0; i < mp.getCount(); i++) {
+ buildContentMap(mp.getBodyPart(i));
+ }
+
+ } else {
+ processBodyPart(p);
+ }
+ }
+
+ private void processBodyPart(Part bp) throws
MessagingException, IOException {
+ if (bp.isMimeType(SOAP12Constants.SOAP_12_CONTENT_TYPE)
||
+ bp.isMimeType(SOAP11Constants.SOAP_11_CONTENT_TYPE)
||
+ bp.isMimeType("text/plain")) {
+
+ if (mainText == null) {
+ mainText = (String) bp.getContent();
+ mainTextContentType = bp.getContentType();
+ }
+ } else {
+ attachments.add(bp.getDataHandler());
+ }
+ }
+
+ public String getMainText() {
+ return mainText;
+ }
+
+ public String getMainTextContentType() {
+ return mainTextContentType;
+ }
+
+ public List<DataHandler> getAttachments() {
+ return attachments;
+ }
+ }
}
Modified: synapse/trunk/java/modules/transports/src/main/java/org/
apache/synapse/transport/mail/PollTableEntry.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/mail/PollTableEntry.java?rev=694732&r1=694731&r2=694732&view=diff
=
=
=
=
=
=
=
=
======================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/
synapse/transport/mail/PollTableEntry.java (original)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/
synapse/transport/mail/PollTableEntry.java Fri Sep 12 09:22:45 2008
@@ -40,6 +40,7 @@
// operation after mail check
public static final int DELETE = 0;
public static final int MOVE = 1;
+ public static final int LEAVE = 2;
/** The email address mapped to the service */
private InternetAddress emailAddress = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]