You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sa...@apache.org on 2006/12/09 11:49:22 UTC
svn commit: r484963 - in
/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2: ./
transport/mail/
Author: saminda
Date: Sat Dec 9 02:49:18 2006
New Revision: 484963
URL: http://svn.apache.org/viewvc?view=rev&rev=484963
Log:
1. Update to mail transport as per the proposed soap12 based64 draft.
2. Transport sender/receiver tally with rfc2368
Added:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailToInfo.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MimeBase64BodyPart.java
Modified:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/Constants.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java?view=diff&rev=484963&r1=484962&r2=484963
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java Sat Dec 9 02:49:18 2006
@@ -95,7 +95,7 @@
* Field TRANSPORT_TCP
*/
public static final String TRANSPORT_TCP = "tcp";
- public static final String TRANSPORT_MAIL = "mail";
+ public static final String TRANSPORT_MAIL = "mailto";
public static final String TRANSPORT_LOCAL = "local";
public static final String TRANSPORT_JMS = "jms";
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/Constants.java?view=diff&rev=484963&r1=484962&r2=484963
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/Constants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/Constants.java Sat Dec 9 02:49:18 2006
@@ -17,15 +17,14 @@
package org.apache.axis2.transport.mail;
public class Constants {
- public final static String FROM_ADDRESS = "mail.from";
- public final static String TO_ADDRESS = "mail.to";
- public final static String SUBJECT = "mail.subject";
+
public final static String HEADER_SOAP_ACTION = "mail.soapaction";
+ public final static String FROM_ADDRESS = "mail.smtp.from";
public final static String SMTP_USER = "mail.smtp.user";
public final static String SMTP_PORT = "mail.smtp.port";
public final static String SMTP_HOST = "mail.smtp.host";
- public final static String SMTP_USER_PASSWORD = "transport.mail.smtp.password";
+ public final static String SMTP_USER_PASSWORD = "transport.mail.smtp.password";
public final static String POP3_USER = "mail.pop3.user";
public final static String POP3_PORT = "mail.pop3.port";
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java?view=diff&rev=484963&r1=484962&r2=484963
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java Sat Dec 9 02:49:18 2006
@@ -20,21 +20,28 @@
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.attachments.ByteArrayDataSource;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
+import javax.activation.CommandMap;
+import javax.activation.DataSource;
+import javax.activation.MailcapCommandMap;
+import javax.activation.DataHandler;
import javax.mail.*;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
-import javax.activation.MailcapCommandMap;
-import javax.activation.CommandMap;
+import javax.mail.internet.MimeMultipart;
+import java.io.OutputStream;
+import java.io.ByteArrayOutputStream;
import java.util.Properties;
public class EMailSender {
private Properties properties;
private MessageContext messageContext;
private PasswordAuthentication passwordAuthentication;
+ private OutputStream outputStream;
static {
//Initializing the proper mime types
@@ -55,12 +62,21 @@
this.properties = properties;
}
+ public OutputStream getOutputStream() {
+ return outputStream;
+ }
+
+ public void setOutputStream(OutputStream outputStream) {
+ this.outputStream = outputStream;
+ }
+
public void setPasswordAuthentication(PasswordAuthentication passwordAuthentication) {
this.passwordAuthentication = passwordAuthentication;
}
- public void send(String subject, String targetEmail, String message, OMOutputFormat format)
+ public void send(MailToInfo mailToInfo, OMOutputFormat format)
throws AxisFault {
+
try {
Session session = Session.getInstance(properties, new Authenticator() {
@@ -70,28 +86,19 @@
});
MimeMessage msg = new MimeMessage(session);
- msg.setFrom(new InternetAddress((passwordAuthentication.getUserName())));
- msg.addRecipient(Message.RecipientType.TO, new InternetAddress(targetEmail));
- msg.setSubject(subject);
-
- String contentType = format.getContentType() != null ? format.getContentType() :
- Constants.DEFAULT_CONTENT_TYPE;
- if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
- if (messageContext.getSoapAction() != null) {
- msg.setHeader(Constants.HEADER_SOAP_ACTION,
- messageContext.getSoapAction());
- msg.setHeader("Content-Transfer-Encoding", "QUOTED-PRINTABLE");
- }
- }
- if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
- if (messageContext.getSoapAction() != null) {
- msg.setContent(message,
- contentType + "; charset=" + format.getCharSetEncoding() +
- " ; action=\"" + messageContext.getSoapAction() + "\"");
- }
- } else {
- msg.setContent(message, contentType + "; charset=" + format.getCharSetEncoding());
+ /*from address is comming from mail.smtp.from property */
+
+ msg.addRecipient(Message.RecipientType.TO,
+ new InternetAddress(mailToInfo.getEmailAddress()));
+
+// Fix Subject TODO
+ msg.setSubject("__ Axis2/Java Mail Message __");
+
+ if (mailToInfo.isxServicePath()) {
+ msg.setHeader("X-Service-Path", "\"" + mailToInfo.getContentDescription() + "\"");
}
+
+ createMailMimeMessage(msg, mailToInfo, format);
Transport.send(msg);
} catch (AddressException e) {
throw new AxisFault(e);
@@ -99,4 +106,54 @@
throw new AxisFault(e);
}
}
+
+ private void createMailMimeMessage(final MimeMessage msg, MailToInfo mailToInfo,
+ OMOutputFormat format)
+ throws MessagingException {
+
+ // Create the message part
+ BodyPart messageBodyPart = new MimeBase64BodyPart();
+ messageBodyPart.setText("");
+ Multipart multipart = new MimeMultipart();
+ multipart.addBodyPart(messageBodyPart);
+
+ DataSource source = null;
+
+ // Part two is attachment
+ if (outputStream instanceof ByteArrayOutputStream) {
+ source = new ByteArrayDataSource(((ByteArrayOutputStream) outputStream).toByteArray());
+ }
+ messageBodyPart = new MimeBase64BodyPart();
+ messageBodyPart.setDataHandler(new DataHandler(source));
+ messageBodyPart.setDisposition(Part.ATTACHMENT);
+
+ messageBodyPart
+ .addHeader("Content-Description", "\"" + mailToInfo.getContentDescription() + "\"");
+
+ String contentType = format.getContentType() != null ? format.getContentType() :
+ Constants.DEFAULT_CONTENT_TYPE;
+ if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
+ if (messageContext.getSoapAction() != null) {
+ messageBodyPart.setHeader(Constants.HEADER_SOAP_ACTION,
+ messageContext.getSoapAction());
+ }
+ }
+
+ if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
+ if (messageContext.getSoapAction() != null) {
+ messageBodyPart.setHeader("Content-Type",
+ contentType + "; charset=" + format.getCharSetEncoding() +
+ " ; action=\"" + messageContext.getSoapAction() + "\"");
+ }
+ } else {
+ messageBodyPart.setHeader("Content-Type",
+ contentType + "; charset=" + format.getCharSetEncoding());
+ }
+
+ multipart.addBodyPart(messageBodyPart);
+ msg.setContent(multipart);
+
+ }
+
+
}
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailToInfo.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailToInfo.java?view=auto&rev=484963
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailToInfo.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailToInfo.java Sat Dec 9 02:49:18 2006
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.transport.mail;
+/*
+ *
+ */
+
+public class MailToInfo {
+ private String emailAddress;
+ private String contentDescription;
+ private boolean xServicePath;
+ private String fromAddress;
+
+ public String getEmailAddress() {
+ return emailAddress;
+ }
+
+ public void setEmailAddress(String emailAddress) {
+ this.emailAddress = emailAddress;
+ }
+
+ public String getContentDescription() {
+ return contentDescription;
+ }
+
+ public void setContentDescription(String contentDescription) {
+ this.contentDescription = contentDescription;
+ }
+
+ public boolean isxServicePath() {
+ return xServicePath;
+ }
+
+ public void setxServicePath(boolean xServicePath) {
+ this.xServicePath = xServicePath;
+ }
+
+ public String getFromAddress() {
+ return fromAddress;
+ }
+
+ public void setFromAddress(String fromAddress) {
+ this.fromAddress = fromAddress;
+ }
+}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java?view=diff&rev=484963&r1=484962&r2=484963
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java Sat Dec 9 02:49:18 2006
@@ -24,11 +24,14 @@
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.description.HandlerDescription;
import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.handlers.AbstractHandler;
import org.apache.axis2.i18n.Messages;
-import org.apache.axis2.transport.AbstractTransportSender;
+import org.apache.axis2.transport.TransportSender;
import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.transport.http.HTTPTransportUtils;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.axis2.util.Utils;
@@ -39,18 +42,89 @@
import java.util.ArrayList;
import java.util.Iterator;
-public class MailTransportSender extends AbstractTransportSender {
+/**
+ * 0. For this profile we only care about SOAP 1.2
+ * 1. There should be no mime text body in this case
+ * 2. The SOAP envelope should be base64 encoded and marked with the following headers
+ * SOAP 1.2
+ * Content-Type: application/soap+xml; charset=UTF-8 ; action="soap-action-goes-here"
+ * Content-Transfer-Encoding: base64
+ * Content-Description: "/serviceName"
+ * 3. The content-description is the logical name of the service. It should be quoted.
+ * 4. The subject can be anything. Perhaps something like "SOAP Message" might be useful to people looking at the mail in a normal mail browser.
+ * 5. If there are attachments the there will be a mime multipart. There should only be one part with content-type: application/soap+xml.
+ * 6. The service URL will be created as mailto:paul@wso2.com?X-Service-Path=/axis2/services/MyService
+ * or paul@wso2.com?/axis2/services/MyService
+ * <p/>
+ * <p/>
+ * Example without attachments
+ * ========================
+ * From: rm_client@lenio.dk
+ * To: lenioserver@oiositest.dk
+ * Message-ID: <88...@hans-guldager-knudsens-computer.local>
+ * Subject: ANYTHING
+ * MIME-Version: 1.0
+ * Content-Type: application/soap+xml; charset=UTF-8 ; action="http://rep.oio.dk/oiosi/IMessageHandler/RequestRespondRequest"
+ * Content-Transfer-Encoding: base64
+ * Content-Description: /my/service/urlpath
+ * <p/>
+ * PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0ndXRmLTgnPz48c29hcGVudjpFbnZlbG9wZSB4
+ * Y3VtZW50YXRpb24uPC9EZXNjcmlwdGlvbj48L05vdGlmaWNhdGlvbj48L3NvYXBlbnY6Qm9keT48
+ * L3NvYXBlbnY6RW52ZWxvcGU+
+ * <p/>
+ * ========================
+ * <p/>
+ * Example with attachments
+ * <p/>
+ * ========================
+ * From: rm_client@lenio.dk
+ * To: lenioserver@oiositest.dk
+ * Message-ID: <88...@hans-guldager-knudsens-computer.local>
+ * Subject: ANYTHING
+ * MIME-Version: 1.0
+ * content-type: multipart/mixed; boundary=--boundary_0_9fdec710-2336-4dc9-8bcd-45f2c06cf605
+ * <p/>
+ * ----boundary_0_9fdec710-2336-4dc9-8bcd-45f2c06cf605
+ * Content-Type: application/soap+xml; charset=UTF-8 ; action="http://rep.oio.dk/oiosi/IMessageHandler/RequestRespondRequest"
+ * Content-Transfer-Encoding: base64
+ * Content-Description: /my/service/urlpath
+ * <p/>
+ * PD94bWwgdmVyc2lvbj0nMS4wJyBlbmNvZGluZz0ndXRmLTgnPz48c29hcGVudjpFbnZlbG9wZSB4
+ * Y3VtZW50YXRpb24uPC9EZXNjcmlwdGlvbj48L05vdGlmaWNhdGlvbj48L3NvYXBlbnY6Qm9keT48
+ * L3NvYXBlbnY6RW52ZWxvcGU+
+ * <p/>
+ * ----boundary_0_9fdec710-2336-4dc9-8bcd-45f2c06cf605
+ * ----boundary_0_9fdec710-2336-4dc9-8bcd-45f2c06cf605
+ * content-type: application/octet-stream
+ * content-transfer-encoding: base64
+ * <p/>
+ * PHM6RW52ZWxvcGUgeG1sbnM6cz0iaHR0cDovL3d3dy53My5vcmcvMjAwMy8wNS9zb2FwLWVu
+ * dmVsb3BlIiB4bWxuczphPSJodHRwOi8vd3d3LnczLm9yZy8yMDA1LzA4L2FkZHJlc3Npbmci
+ * IHhtbG5zOnU9Imh0dHA6Ly9kb2NzLm9hc2lzLW9wZW4ub3JnL3dzcy8yMDA0LzAxL29hc2lz
+ * LTIwMDQwMS13c3Mtd3NzZWN1cml0eS11dGlsaXR5LTEuMC54c2QiPjxzOkhlYWRlcj48YTpB
+ * Y3Rpb24gczptdXN0VW5kZXJzdGFuZD0iMSI+aHR0cDovL3JlcC5vaW8uZGsvb2lvc2kvSU1l
+ * c3NhZ2VIYW5kbGVyL1JlcXVlc3RSZXNwb25kUmVxdWVzdDwvYTpBY3Rpb24+PGE6TWVzc2Fn
+ */
+public class MailTransportSender extends AbstractHandler implements TransportSender {
/* smtpProperties holds all the parameters needed to Java Mail. This will be filled either from Axis2.xml or
from runtime.
*/
- private java.util.Properties smtpProperties = new java.util.Properties();
+ private final java.util.Properties smtpProperties = new java.util.Properties();
private PasswordAuthentication passwordAuthentication;
private ByteArrayOutputStream byteArrayOutputStream;
// assosiation with OMOutputFormat
- private OMOutputFormat format = new OMOutputFormat();
+ private final OMOutputFormat format = new OMOutputFormat();
+
+ private final MailToInfo mailToInfo = new MailToInfo();
+
+ private final static String NAME = "MailTransportSender";
+
+ public MailTransportSender() {
+ init(new HandlerDescription(NAME));
+ }
public void init(ConfigurationContext configurationContext,
@@ -78,22 +152,18 @@
if (paramKey.equals(Constants.SMTP_USER_PASSWORD)) {
password = paramValue;
}
+ if (paramKey.equals(Constants.RAPLY_TO)) {
+ mailToInfo.setFromAddress(paramValue);
+ }
}
passwordAuthentication = new PasswordAuthentication(username, password);
}
- public MailTransportSender() {
- }
public void cleanup(MessageContext msgContext) throws AxisFault {
}
- public void finalizeSendWithOutputStreamFromIncomingConnection(MessageContext msgContext,
- OutputStream out)
- throws AxisFault {
- }
-
private void runtimeMailParameterSetting(MessageContext msgContext) {
Object obj = msgContext.getProperty(HTTPConstants.MAIL_SMTP);
if (obj != null) {
@@ -111,19 +181,17 @@
}
- public void finalizeSendWithToAddress(MessageContext msgContext, OutputStream out)
- throws AxisFault {
+ public void sendMimeMessage(MessageContext msgContext) throws AxisFault {
try {
// Override with runtime settings
runtimeMailParameterSetting(msgContext);
EMailSender sender = new EMailSender();
+ sender.setOutputStream(byteArrayOutputStream);
sender.setMessageContext(msgContext);
sender.setProperties(smtpProperties);
sender.setPasswordAuthentication(passwordAuthentication);
- String eprAddress = msgContext.getTo().getAddress();
-
// In mail char set is what is being used. Charset encoding is not what is expected here.
String charSet =
(String) msgContext.getProperty(
@@ -135,53 +203,52 @@
format.setSOAP11(msgContext.isSOAP11());
format.setCharSetEncoding(charSet);
- int mailNameIndex = eprAddress.indexOf("mail:");
- if (mailNameIndex > -1) {
- eprAddress = eprAddress.substring(mailNameIndex + 5);
- }
- int index = eprAddress.indexOf('/');
- String subject = "";
- String email;
-
- if (index >= 0) {
- subject = eprAddress.substring(index + 1);
- email = eprAddress.substring(0, index);
- } else {
- email = eprAddress;
- }
- int emailColon = email.indexOf(":");
- if (emailColon >= 0) {
- email = email.substring(emailColon + 1);
- }
+ parseMailToAddress(msgContext.getTo());
- sender.send(subject, email, new String(byteArrayOutputStream.toByteArray()),
- format);
+ sender.send(mailToInfo, format);
} catch (IOException e) {
throw new AxisFault(e);
}
}
- protected OutputStream openTheConnection(EndpointReference epr, MessageContext msgContext)
- throws AxisFault {
- byteArrayOutputStream = new ByteArrayOutputStream();
+ private void parseMailToAddress(EndpointReference epr) {
+ String eprAddress = epr.getAddress();
+ //TODO URl validation according to rfc : http://www.ietf.org/rfc/rfc2368.txt
+
+ int mailToIndex = eprAddress.indexOf("mailto:");
+ if (mailToIndex > -1) {
+ eprAddress = eprAddress.substring(mailToIndex + 7);
+ }
+ int index = eprAddress.indexOf('?');
+ String contentDescription = "";
+ String email;
+ boolean xServicePath = false;
- return byteArrayOutputStream;
- }
- // Output Stream based cases are not supported
- public OutputStream startSendWithOutputStreamFromIncomingConnection(MessageContext msgContext,
- OutputStream out)
- throws AxisFault {
- throw new UnsupportedOperationException();
- }
+ if (index > -1) {
+ email = eprAddress.substring(0, index);
+ } else {
+ email = eprAddress;
+ }
+
+ if (eprAddress.indexOf("x-service-path".toLowerCase()) > -1) {
+ index = eprAddress.indexOf('=');
+ if (index > -1) {
+ xServicePath = true;
+ contentDescription = eprAddress.substring(index + 1);
+ }
+ } else {
+ contentDescription = eprAddress.substring(index + 1);
+
+ }
+ mailToInfo.setContentDescription(contentDescription);
+ mailToInfo.setEmailAddress(email);
+ mailToInfo.setxServicePath(xServicePath);
- public OutputStream startSendWithToAddress(MessageContext msgContext, OutputStream out)
- throws AxisFault {
- return out;
}
- public void writeMessage(MessageContext msgContext, OutputStream out) throws AxisFault {
+ public void writeMimeMessage(MessageContext msgContext, OutputStream out) throws AxisFault {
SOAPEnvelope envelope = msgContext.getEnvelope();
OMElement outputMessage = envelope;
@@ -209,4 +276,41 @@
public void stop() {
}
+ /**
+ * TODO
+ *
+ * @param msgContext
+ * @return
+ * @throws AxisFault
+ */
+ public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
+
+ msgContext.setDoingMTOM(HTTPTransportUtils.doWriteMTOM(msgContext));
+ msgContext.setDoingSwA(HTTPTransportUtils.doWriteSwA(msgContext));
+
+ EndpointReference epr = null;
+
+ if (msgContext.getTo() != null && !msgContext.getTo().hasAnonymousAddress()) {
+ epr = msgContext.getTo();
+ }
+
+ if (epr != null) {
+ if (!epr.hasNoneAddress()) {
+
+ byteArrayOutputStream = new ByteArrayOutputStream();
+
+ writeMimeMessage(msgContext, byteArrayOutputStream);
+
+ sendMimeMessage(msgContext);
+ }
+ } else {
+ // TODO If epr is null or anonymous, then the flow shold be as
+ // replyto : from : or reply-path;
+ if (msgContext.isServerSide()) {
+
+ }
+ }
+
+ return InvocationResponse.CONTINUE;
+ }
}
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MimeBase64BodyPart.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MimeBase64BodyPart.java?view=auto&rev=484963
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MimeBase64BodyPart.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MimeBase64BodyPart.java Sat Dec 9 02:49:18 2006
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.transport.mail;
+
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.MessagingException;
+
+/**
+ * The main purpose of this class is to encode mime body part with
+ * base64 encoding
+ */
+
+public class MimeBase64BodyPart extends MimeBodyPart {
+
+ protected void updateHeaders() throws MessagingException {
+ super.updateHeaders();
+ setHeader("Content-Transfer-Encoding","base64");
+ }
+}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java?view=diff&rev=484963&r1=484962&r2=484963
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java Sat Dec 9 02:49:18 2006
@@ -39,20 +39,18 @@
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.transport.TransportListener;
import org.apache.axis2.transport.TransportUtils;
-import org.apache.axis2.util.threadpool.DefaultThreadFactory;
import org.apache.axis2.util.Utils;
+import org.apache.axis2.util.threadpool.DefaultThreadFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import javax.mail.Flags;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.URLName;
+import javax.mail.*;
import javax.mail.internet.MimeMessage;
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
@@ -83,7 +81,7 @@
* Time has been put from best guest. Let the default be 3 mins.
* This value is configuralble from Axis2.xml. Under mail transport listener
* simply set the following parameter.
- * <parameter name="transport.listener.interval ">[custom listener interval]</parameter>
+ * <parameter name="transport.listener.interval">[custom listener interval]</parameter>
*/
private int listenerWaitInterval = 1000 * 60 * 3;
@@ -146,8 +144,10 @@
}
}
- if (password.length() == 0 || user.length() == 0 || host.length() == 0 || protocol.length() == 0) {
- throw new AxisFault("One or more of Password, User, Host and Protocol are null or empty");
+ if (password.length() == 0 || user.length() == 0 || host.length() == 0 ||
+ protocol.length() == 0) {
+ throw new AxisFault(
+ "One or more of Password, User, Host and Protocol are null or empty");
}
if (port.length() == 0) {
@@ -177,7 +177,8 @@
File repo = new File(path);
if (repo.exists()) {
configurationContext =
- ConfigurationContextFactory.createConfigurationContextFromFileSystem(path,axis2xml);
+ ConfigurationContextFactory
+ .createConfigurationContextFromFileSystem(path, axis2xml);
} else {
printUsage();
throw new AxisFault("repository not found");
@@ -267,71 +268,110 @@
msgContext.setServerSide(true);
msgContext.setProperty(org.apache.axis2.transport.mail.Constants.CONTENT_TYPE,
msg.getContentType());
-
- if (TransportUtils.getCharSetEncoding(msg.getContentType()) != null) {
- msgContext.setProperty(
- org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,
- TransportUtils.getCharSetEncoding(
- msg.getContentType()));
- } else {
- msgContext.setProperty(
- org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,
- MessageContext.DEFAULT_CHAR_SET_ENCODING);
+ msgContext.setIncomingTransportName(org.apache.axis2.Constants.TRANSPORT_MAIL);
+ if (msg.getFrom() != null && msg.getFrom().length > 0) {
+ msgContext.setFrom(new EndpointReference((msg.getFrom()[0]).toString()));
}
- msgContext.setIncomingTransportName(org.apache.axis2.Constants.TRANSPORT_MAIL);
- String soapAction = getMailHeader(msg,
- org.apache.axis2.transport.mail.Constants.HEADER_SOAP_ACTION);
- msgContext.setSoapAction(soapAction);
- if (msg.getSubject() != null) {
- msgContext.setTo(new EndpointReference(msg.getSubject()));
- }
-
- // Create the SOAP Message
- // SMTP basically a text protocol, thus, following would be the optimal way to build the
- // SOAP11/12 body from it.
- String message = msg.getContent().toString();
- ByteArrayInputStream bais =
- new ByteArrayInputStream(message.getBytes());
- XMLStreamReader reader =
- StAXUtils.createXMLStreamReader(bais);
- String soapNamespaceURI;
- if (msg.getContentType().indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE)
- > -1) {
- soapNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
- // set the soapAction if available
- int index = msg.getContentType().indexOf("action");
- if (index > -1) {
- String transientString = msg.getContentType().substring(index, msg.getContentType().length());
- int equal = transientString.indexOf("=");
- int firstSemiColon = transientString.indexOf(";");
- if (firstSemiColon > -1) {
- soapAction = transientString.substring(equal + 1, firstSemiColon);
- } else {
- soapAction = transientString.substring(equal + 1, transientString.length());
- }
- if ((soapAction != null) && soapAction.startsWith("\"")
- && soapAction.endsWith("\"")) {
- soapAction = soapAction
- .substring(1, soapAction.length() - 1);
- }
- msgContext.setSoapAction(soapAction);
+ buildSOAPEnvelope(msg, msgContext);
+ }
+ return msgContext;
+ }
+ private void buildSOAPEnvelope(MimeMessage msg, MessageContext msgContext)
+ throws AxisFault {
+ //TODO we assume for the time being that there is only one attachement and this attachement contains the soap evelope
+ try {
+ Multipart mp = (Multipart) msg.getContent();
+ if (mp != null) {
+ for (int i = 0, n = mp.getCount(); i < n; i++) {
+ Part part = mp.getBodyPart(i);
+
+ String disposition = part.getDisposition();
+
+ if (disposition != null && disposition.equals(Part.ATTACHMENT)) {
+ String soapAction = "";
+ String soapNamespaceURI = "";
+
+ /* Set the Charactorset Encoding */
+ if (TransportUtils.getCharSetEncoding(part.getContentType()) != null) {
+ msgContext.setProperty(
+ org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,
+ TransportUtils.getCharSetEncoding(
+ part.getContentType()));
+ } else {
+ msgContext.setProperty(
+ org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,
+ MessageContext.DEFAULT_CHAR_SET_ENCODING);
+ }
+
+ /* SOAP Action */
+ soapAction = getMailHeaderFromPart(part,
+ org.apache.axis2.transport.mail.Constants.HEADER_SOAP_ACTION);
+ msgContext.setSoapAction(soapAction);
+
+ String contentDescription =
+ getMailHeaderFromPart(part, "Content-Description");
+
+ /* As an input stream - using the getInputStream() method.
+ Any mail-specific encodings are decoded before this stream is returned.*/
+ if (contentDescription != null) {
+ msgContext.setTo(new EndpointReference(contentDescription));
+ }
+
+ XMLStreamReader reader =
+ StAXUtils.createXMLStreamReader(part.getInputStream());
+
+ if (part.getContentType().indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE)
+ > -1) {
+ soapNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
+ // set the soapAction if available
+ int index = part.getContentType().indexOf("action");
+ if (index > -1) {
+ String transientString =
+ part.getContentType()
+ .substring(index, part.getContentType().length());
+ int equal = transientString.indexOf("=");
+ int firstSemiColon = transientString.indexOf(";");
+ if (firstSemiColon > -1) {
+ soapAction =
+ transientString.substring(equal + 1, firstSemiColon);
+ } else {
+ soapAction = transientString
+ .substring(equal + 1, transientString.length());
+ }
+ if ((soapAction != null) && soapAction.startsWith("\"")
+ && soapAction.endsWith("\"")) {
+ soapAction = soapAction
+ .substring(1, soapAction.length() - 1);
+ }
+ msgContext.setSoapAction(soapAction);
+
+ }
+ } else if (part.getContentType().indexOf(
+ SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
+ soapNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
+ } else {
+ log.warn(
+ "MailWorker found a message other than text/xml or application/soap+xml");
+ }
+
+ StAXBuilder builder = new StAXSOAPModelBuilder(reader, soapNamespaceURI);
+ SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
+ msgContext.setEnvelope(envelope);
+ }
}
- } else if (msg.getContentType().indexOf(
- SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
- soapNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
- } else {
- log.warn(
- "MailWorker found a message other than text/xml or application/soap+xml");
- return null;
- }
- StAXBuilder builder = new StAXSOAPModelBuilder(reader, soapNamespaceURI);
- SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
- msgContext.setEnvelope(envelope);
+
+ }
+ } catch (IOException e) {
+ throw new AxisFault(e);
+ }
+ catch (MessagingException e) {
+ throw new AxisFault(e);
+ } catch (XMLStreamException e) {
+ throw new AxisFault(e);
}
- return msgContext;
}
private String getMailHeader(MimeMessage msg, String headerName) throws AxisFault {
@@ -348,6 +388,20 @@
}
}
+ private String getMailHeaderFromPart(Part part, String headerName) throws AxisFault {
+ try {
+ String values[] = part.getHeader(headerName);
+
+ if (values != null) {
+ return values[0];
+ } else {
+ return null;
+ }
+ } catch (MessagingException e) {
+ throw new AxisFault(e);
+ }
+ }
+
/**
* Start this listener
*/
@@ -388,7 +442,7 @@
public EndpointReference[] getEPRsForService(String serviceName, String ip) throws AxisFault {
return new EndpointReference[]{new EndpointReference(Constants.TRANSPORT_MAIL + ":" +
- replyTo + configurationContext
+ replyTo + "?" + configurationContext
.getServiceContextPath() + "/" + serviceName)};
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org