You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jl...@apache.org on 2006/03/31 23:58:44 UTC
svn commit: r390515 - in
/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail:
transport/smtp/SMTPTransport.java util/TraceInputStream.java
util/TraceOutputStream.java
Author: jlaskowski
Date: Fri Mar 31 13:58:42 2006
New Revision: 390515
URL: http://svn.apache.org/viewcvs?rev=390515&view=rev
Log:
GERONIMO-1796 - Improve SMTP transport debug trace output
Submitted by: Rick McGuire
Added:
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceInputStream.java (with props)
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceOutputStream.java (with props)
Modified:
geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java
Modified: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java?rev=390515&r1=390514&r2=390515&view=diff
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java (original)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/transport/smtp/SMTPTransport.java Fri Mar 31 13:58:42 2006
@@ -49,10 +49,13 @@
import org.apache.geronimo.javamail.authentication.DigestMD5Authenticator;
import org.apache.geronimo.javamail.authentication.LoginAuthenticator;
import org.apache.geronimo.javamail.authentication.PlainAuthenticator;
+import org.apache.geronimo.javamail.authentication.PlainAuthenticator;
import org.apache.geronimo.mail.util.Base64;
import org.apache.geronimo.mail.util.XText;
import org.apache.geronimo.javamail.util.MIMEOutputStream;
+import org.apache.geronimo.javamail.util.TraceInputStream;
+import org.apache.geronimo.javamail.util.TraceOutputStream;
/**
* Simple implementation of SMTP transport. Just does plain RFC821-ish
@@ -115,6 +118,7 @@
protected static final String MAIL_SMTP_SUBMITTER = "submitter";
protected static final String MAIL_SMTP_EXTENSION = "mailextension";
protected static final String MAIL_SMTP_EHLO = "ehlo";
+ protected static final String MAIL_SMTP_ENCODE_TRACE = "encodetrace";
protected static final int MIN_MILLIS = 1000 * 60;
@@ -250,6 +254,8 @@
// get our debug output.
debugStream = session.getDebugOut();
+
+ System.out.println("Debug value in transport = " + debug);
}
@@ -770,8 +776,8 @@
host = socket.getInetAddress().getHostName();
}
// now set up the input/output streams.
- inputStream = socket.getInputStream();
- outputStream = socket.getOutputStream();
+ inputStream = new TraceInputStream(socket.getInputStream(), debugStream, debug, isProtocolPropertyTrue(MAIL_SMTP_ENCODE_TRACE)); ;
+ outputStream = new TraceOutputStream(socket.getOutputStream(), debugStream, debug, isProtocolPropertyTrue(MAIL_SMTP_ENCODE_TRACE));
}
/**
@@ -1226,8 +1232,9 @@
// and finally, as a last step, replace our input streams with the secure ones.
- inputStream = sslSocket.getInputStream();
- outputStream = sslSocket.getOutputStream();
+ // now set up the input/output streams.
+ inputStream = new TraceInputStream(sslSocket.getInputStream(), debugStream, debug, isProtocolPropertyTrue(MAIL_SMTP_ENCODE_TRACE)); ;
+ outputStream = new TraceOutputStream(sslSocket.getOutputStream(), debugStream, debug, isProtocolPropertyTrue(MAIL_SMTP_ENCODE_TRACE));
// this is our active socket now
socket = sslSocket;
@@ -1532,9 +1539,6 @@
* appropriate CRLF
*/
protected void sendLine(String data) throws MessagingException {
- if (debug) {
- debugOut("sending line to server >>>" + data + "<<<");
- }
if (socket == null || !socket.isConnected()) {
throw new MessagingException("no connection");
}
@@ -1629,9 +1633,6 @@
}
String line = buff.toString();
- if (debug) {
- debugOut("received line from server >>>" + line + "<<<");
- }
return line;
} catch (SocketException e) {
Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceInputStream.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceInputStream.java?rev=390515&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceInputStream.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceInputStream.java Fri Mar 31 13:58:42 2006
@@ -0,0 +1,114 @@
+/**
+ *
+ * Copyright 2006 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.geronimo.javamail.util;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.geronimo.mail.util.QuotedPrintableEncoderStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TraceInputStream extends FilterInputStream {
+ // the current debug setting
+ protected boolean debug = false;
+ // the target trace output stream.
+ protected OutputStream traceStream;
+
+ /**
+ * Construct a debug trace stream.
+ *
+ * @param in The source input stream.
+ * @param traceStream
+ * The side trace stream to which trace data gets written.
+ * @param encode Indicates whether we wish the Trace data to be Q-P encoded.
+ */
+ public TraceInputStream(InputStream in, OutputStream traceStream, boolean debug, boolean encode) {
+ super(in);
+ this.debug = debug;
+ if (encode) {
+ this.traceStream = new QuotedPrintableEncoderStream(traceStream);
+ }
+ else {
+ this.traceStream = traceStream;
+ }
+ }
+
+ /**
+ * Set the current setting of the debug trace stream debug flag.
+ *
+ * @param d The new debug flag settings.
+ */
+ public void setDebug(boolean d) {
+ debug = d;
+ }
+
+
+ /**
+ * Reads up to <code>len</code> bytes of data from this input stream
+ * into an array of bytes. This method blocks until some input is
+ * available.
+ * <p>
+ * This method simply performs <code>in.read(b, off, len)</code>
+ * and returns the result.
+ *
+ * @param b the buffer into which the data is read.
+ * @param off the start offset of the data.
+ * @param len the maximum number of bytes read.
+ * @return the total number of bytes read into the buffer, or
+ * <code>-1</code> if there is no more data because the end of
+ * the stream has been reached.
+ * @exception IOException if an I/O error occurs.
+ * @see java.io.FilterInputStream#in
+ */
+ public int read(byte b[], int off, int len) throws IOException {
+ int count = in.read(b, off, len);
+ if (debug && count > 0) {
+ traceStream.write(b, off, count);
+ }
+ return count;
+ }
+
+ /**
+ * Reads the next byte of data from this input stream. The value
+ * byte is returned as an <code>int</code> in the range
+ * <code>0</code> to <code>255</code>. If no byte is available
+ * because the end of the stream has been reached, the value
+ * <code>-1</code> is returned. This method blocks until input data
+ * is available, the end of the stream is detected, or an exception
+ * is thrown.
+ * <p>
+ * This method
+ * simply performs <code>in.read()</code> and returns the result.
+ *
+ * @return the next byte of data, or <code>-1</code> if the end of the
+ * stream is reached.
+ * @exception IOException if an I/O error occurs.
+ * @see java.io.FilterInputStream#in
+ */
+ public int read() throws IOException {
+ int b = in.read();
+ if (debug) {
+ traceStream.write(b);
+ }
+ return b;
+ }
+}
Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceInputStream.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceInputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceOutputStream.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceOutputStream.java?rev=390515&view=auto
==============================================================================
--- geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceOutputStream.java (added)
+++ geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceOutputStream.java Fri Mar 31 13:58:42 2006
@@ -0,0 +1,111 @@
+/**
+ *
+ * Copyright 2006 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.geronimo.javamail.util;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.geronimo.mail.util.QuotedPrintableEncoderStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TraceOutputStream extends FilterOutputStream {
+ // the current debug setting
+ protected boolean debug = false;
+ // the target trace output stream.
+ protected OutputStream traceStream;
+
+ /**
+ * Construct a debug trace stream.
+ *
+ * @param out The target out put stream.
+ * @param traceStream
+ * The side trace stream to which trace data gets written.
+ * @param encode Indicates whether we wish the Trace data to be Q-P encoded.
+ */
+ public TraceOutputStream(OutputStream out, OutputStream traceStream, boolean debug, boolean encode) {
+ super(out);
+ this.debug = debug;
+ if (encode) {
+ this.traceStream = new QuotedPrintableEncoderStream(traceStream);
+ }
+ else {
+ this.traceStream = traceStream;
+ }
+ }
+
+ /**
+ * Set the current setting of the debug trace stream debug flag.
+ *
+ * @param d The new debug flag settings.
+ */
+ public void setDebug(boolean d) {
+ debug = d;
+ }
+
+ /**
+ * Writes <code>len</code> bytes from the specified
+ * <code>byte</code> array starting at offset <code>off</code> to
+ * this output stream.
+ * <p>
+ * The <code>write</code> method of <code>FilterOutputStream</code>
+ * calls the <code>write</code> method of one argument on each
+ * <code>byte</code> to output.
+ * <p>
+ * Note that this method does not call the <code>write</code> method
+ * of its underlying input stream with the same arguments. Subclasses
+ * of <code>FilterOutputStream</code> should provide a more efficient
+ * implementation of this method.
+ *
+ * @param b the data.
+ * @param off the start offset in the data.
+ * @param len the number of bytes to write.
+ * @exception IOException if an I/O error occurs.
+ * @see java.io.FilterOutputStream#write(int)
+ */
+ public void write(byte b[], int off, int len) throws IOException {
+ if (debug) {
+ for (int i = 0; i < len; i++) {
+ traceStream.write(b[off + i]);
+ }
+ }
+ super.write(b, off, len);
+ }
+
+ /**
+ * Writes the specified <code>byte</code> to this output stream.
+ * <p>
+ * The <code>write</code> method of <code>FilterOutputStream</code>
+ * calls the <code>write</code> method of its underlying output stream,
+ * that is, it performs <tt>out.write(b)</tt>.
+ * <p>
+ * Implements the abstract <tt>write</tt> method of <tt>OutputStream</tt>.
+ *
+ * @param b the <code>byte</code>.
+ * @exception IOException if an I/O error occurs.
+ */
+ public void write(int b) throws IOException {
+ if (debug) {
+ traceStream.write(b);
+ }
+ super.write(b);
+ }
+}
+
Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceOutputStream.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: geronimo/trunk/modules/javamail-transport/src/java/org/apache/geronimo/javamail/util/TraceOutputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain