geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlaskow...@apache.org
Subject svn commit: r387218 - in /geronimo/trunk/modules/mail/src: java/org/apache/geronimo/mail/ test/org/apache/geronimo/mail/
Date Mon, 20 Mar 2006 15:12:39 GMT
Author: jlaskowski
Date: Mon Mar 20 07:12:37 2006
New Revision: 387218

URL: http://svn.apache.org/viewcvs?rev=387218&view=rev
Log:
GERONIMO-1754 - Add GBeans for configuring NNTPTransport and NNTPStore access
Submitted by: Rick McGuire

Added:
    geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPStoreGBean.java   (with
props)
    geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPTransportGBean.java
  (with props)
Modified:
    geronimo/trunk/modules/mail/src/test/org/apache/geronimo/mail/MailGBeanTest.java
    geronimo/trunk/modules/mail/src/test/org/apache/geronimo/mail/TestTransport.java

Added: geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPStoreGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPStoreGBean.java?rev=387218&view=auto
==============================================================================
--- geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPStoreGBean.java (added)
+++ geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPStoreGBean.java Mon
Mar 20 07:12:37 2006
@@ -0,0 +1,386 @@
+/**
+ *
+ * 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.mail;
+
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+
+/**
+ * A GBean that provides for the configuration of a JavaMail NNTP transport
+ * protocol.
+ * <p/>
+ * NNTP transport properties that are common to all NNTP transports are
+ * provided via member variables of this class.  Values that are set in the
+ * individual member variables will override any of the corresponding values
+ * that have been set in the properties set.
+ *
+ * @version $Rev$ $Date$
+ * @see MailGBean
+ */
+public class NNTPStoreGBean extends ProtocolGBean {
+
+    private final Log log = LogFactory.getLog(NNTPTransportGBean.class);
+
+    private Integer port;
+    private Integer connectionTimeout;
+    private Integer timeout;
+    private Boolean auth;
+    private String saslRealm;
+    private Boolean quitWait;
+    private String socketFactoryClass;
+    private Boolean socketFactoryFallback;
+    private Integer socketFactoryPort;
+
+
+    /**
+     * Construct an instance of NNTPStoreGBean
+     * <p/>
+     * Values that are set in the individual member variables will override any of
+     * the corresponding values that have been set in the properties set.
+     *
+     * @param objectName            the object name of the protocol
+     * @param properties            the set of default properties for the protocol
+     * @param host                  the host the protocol connects to
+     * @param user                  the default name for the protocol
+     * @param port                  the NNTP server port
+     * @param connectionTimeout     the socket connection timeout value in milliseconds
+     * @param timeout               the socket I/O timeout value in milliseconds
+     * @param auth                  whether an attempt will be made to authenticate the user
+     * @param saslRealm             the realm to use with DIGEST-MD5 authentication
+     * @param quitWait              whether the transport will wait for the response to the
QUIT command
+     * @param socketFactoryClass    the class that will be used to create NNTP sockets
+     * @param socketFactoryFallback whether java.net.Socket class will be created if the
specified
+     *                              socket factory class cannot be created
+     * @param socketFactoryPort     whether java.net.Socket class will be created if the
specified
+     *                              socket factory class cannot be created
+     */
+    public NNTPStoreGBean(String objectName, Properties properties, String host, String user,
+                              Integer port,
+                              Integer connectionTimeout,
+                              Integer timeout,
+                              Boolean auth,
+                              String saslRealm,
+                              Boolean quitWait,
+                              String socketFactoryClass,
+                              Boolean socketFactoryFallback,
+                              Integer socketFactoryPort) {
+        super(objectName, "nntp", properties, host, user);
+
+        setPort(port);
+        setConnectionTimeout(connectionTimeout);
+        setTimeout(timeout);
+        setAuth(auth);
+        setSaslRealm(saslRealm);
+        setQuitWait(quitWait);
+        setSocketFactoryClass(socketFactoryClass);
+        setSocketFactoryFallback(socketFactoryFallback);
+        setSocketFactoryPort(socketFactoryPort);
+    }
+
+    /**
+     * Returns the NNTP server port to connect to, if the connect() method
+     * doesn't explicitly specify one.
+     */
+    public Integer getPort() {
+        return port;
+    }
+
+    /**
+     * Sets the NNTP server port to connect to, if the connect() method
+     * doesn't explicitly specify one.
+     * <p/>
+     * Defaults to 25.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param port the NNTP server port to connect to
+     */
+    public void setPort(Integer port) {
+        this.port = port;
+    }
+
+    /**
+     * Returns the socket connection timeout value in milliseconds.
+     */
+    public Integer getConnectionTimeout() {
+        return connectionTimeout;
+    }
+
+    /**
+     * Sets the socket connection timeout value in milliseconds.
+     * <p/>
+     * Default is infinite timeout.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param connectionTimeout the socket connection timeout value in milliseconds.
+     */
+    public void setConnectionTimeout(Integer connectionTimeout) {
+        this.connectionTimeout = connectionTimeout;
+    }
+
+    /**
+     * Returns the socket I/O timeout value in milliseconds.
+     */
+    public Integer getTimeout() {
+        return timeout;
+    }
+
+    /**
+     * Sets the socket I/O timeout value in milliseconds.
+     * <p/>
+     * Default is infinite timeout.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param timeout the socket I/O timeout value in milliseconds
+     */
+    public void setTimeout(Integer timeout) {
+        this.timeout = timeout;
+    }
+
+
+    /**
+     * Returns whether an attempt will be made to authenticate the user.
+     * <p/>
+     * Defaults to false.
+     */
+    public Boolean getAuth() {
+        return auth;
+    }
+
+    /**
+     * Sets whether an attempt will be made to authenticate the user.
+     * <p/>
+     * Defaults to false.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param auth whether an attempt will be made to authenticate the user.
+     */
+    public void setAuth(Boolean auth) {
+        this.auth = auth;
+    }
+
+    /**
+     * Returns the realm to use with DIGEST-MD5 authentication.
+     */
+    public String getSaslRealm() {
+        return saslRealm;
+    }
+
+    /**
+     * Sets the realm to use with DIGEST-MD5 authentication.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param saslRealm the realm to use with DIGEST-MD5 authentication
+     */
+    public void setSaslRealm(String saslRealm) {
+        this.saslRealm = saslRealm;
+    }
+
+    /**
+     * Returns whether the transport will wait for the response to the QUIT command.
+     * <p/>
+     * If set to true, causes the transport to wait for the response to the QUIT
+     * command. If set to false (the default), the QUIT command is sent and the
+     * connection is immediately closed.
+     */
+    public Boolean getQuitWait() {
+        return quitWait;
+    }
+
+    /**
+     * Sets whether the transport will wait for the response to the QUIT command
+     * <p/>
+     * If set to true, causes the transport to wait for the response to the QUIT
+     * command. If set to false (the default), the QUIT command is sent and the
+     * connection is immediately closed.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param quitWait whether the transport will wait for the response to the QUIT command
+     */
+    public void setQuitWait(Boolean quitWait) {
+        this.quitWait = quitWait;
+    }
+
+    /**
+     * Returns the class that will be used to create NNTP sockets.
+     * <p/>
+     * If set, specifies the name of a class that implements the
+     * javax.net.SocketFactory interface. This class will be used to create NNTP
+     * sockets.
+     */
+    public String getSocketFactoryClass() {
+        return socketFactoryClass;
+    }
+
+    /**
+     * Sets the class that will be used to create NNTP sockets.
+     * <p/>
+     * If set, specifies the name of a class that implements the
+     * javax.net.SocketFactory interface. This class will be used to create NNTP
+     * sockets.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param socketFactoryClass the class that will be used to create NNTP sockets
+     */
+    public void setSocketFactoryClass(String socketFactoryClass) {
+        this.socketFactoryClass = socketFactoryClass;
+    }
+
+    /**
+     * Returns whether java.net.Socket class will be created if the specified
+     * socket factory class cannot be created.
+     * <p/>
+     * If set to true, failure to create a socket using the specified socket
+     * factory class will cause the socket to be created using the
+     * java.net.Socket class. Defaults to true.
+     */
+    public Boolean getSocketFactoryFallback() {
+        return socketFactoryFallback;
+    }
+
+    /**
+     * Sets whether java.net.Socket class will be created if the specified
+     * socket factory class cannot be created.
+     * <p/>
+     * If set to true, failure to create a socket using the specified socket
+     * factory class will cause the socket to be created using the
+     * java.net.Socket class. Defaults to true.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param socketFactoryFallback whether java.net.Socket class will be created if the
specified
+     *                              socket factory class cannot be created
+     */
+    public void setSocketFactoryFallback(Boolean socketFactoryFallback) {
+        this.socketFactoryFallback = socketFactoryFallback;
+    }
+
+    /**
+     * Returns the port to connect to when using the specified socket factory.
+     * <p/>
+     * Specifies the port to connect to when using the specified socket
+     * factory. If not set, the default port will be used.
+     */
+    public Integer getSocketFactoryPort() {
+        return socketFactoryPort;
+    }
+
+    /**
+     * Sets the port to connect to when using the specified socket factory.
+     * <p/>
+     * Specifies the port to connect to when using the specified socket
+     * factory. If not set, the default port will be used.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param socketFactoryPort the port to connect to when using the specified socket factory
+     */
+    public void setSocketFactoryPort(Integer socketFactoryPort) {
+        this.socketFactoryPort = socketFactoryPort;
+    }
+
+    /**
+     * Add the overrides from the member variables to the properties file.
+     */
+    public void addOverrides(Properties props) {
+        super.addOverrides(props);
+
+        if (port != null) props.put("mail.nntp.port", port);
+        if (connectionTimeout != null) props.put("mail.nntp.connectiontimeout", connectionTimeout);
+        if (timeout != null) props.put("mail.nntp.timeout", timeout);
+        if (auth != null) props.put("mail.nntp.auth", auth);
+        if (saslRealm != null) props.put("mail.nntp.sasl.realm", saslRealm);
+        if (quitWait != null) props.put("mail.nntp.quitwait", quitWait);
+        if (socketFactoryClass != null) props.put("mail.nntp.socketFactory.class", socketFactoryClass);
+        if (socketFactoryFallback != null) props.put("mail.nntp.socketFactory.fallback",
socketFactoryFallback);
+        if (socketFactoryPort != null) props.put("mail.nntp.socketFactory.port", socketFactoryPort);
+    }
+
+    public void doStart() throws Exception {
+        log.debug("Started " + getObjectName());
+    }
+
+    public void doStop() throws Exception {
+        log.debug("Stopped " + getObjectName());
+    }
+
+    public void doFail() {
+        log.warn("Failed " + getObjectName());
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(NNTPStoreGBean.class);
+
+        infoFactory.addAttribute("port", Integer.class, true);
+        infoFactory.addAttribute("connectionTimeout", Integer.class, true);
+        infoFactory.addAttribute("timeout", Integer.class, true);
+        infoFactory.addAttribute("auth", Boolean.class, true);
+        infoFactory.addAttribute("saslRealm", String.class, true);
+        infoFactory.addAttribute("quitWait", Boolean.class, true);
+        infoFactory.addAttribute("socketFactoryClass", String.class, true);
+        infoFactory.addAttribute("socketFactoryFallback", Boolean.class, true);
+        infoFactory.addAttribute("socketFactoryPort", Integer.class, true);
+
+        infoFactory.addAttribute("objectName", String.class, false);
+        infoFactory.addAttribute("protocol", String.class, false);
+        infoFactory.addAttribute("properties", Properties.class, true);
+        infoFactory.addAttribute("host", String.class, true);
+        infoFactory.addAttribute("user", String.class, true);
+        infoFactory.addOperation("addOverrides", new Class[]{Properties.class});
+
+        infoFactory.setConstructor(new String[]{"objectName", "properties", "host", "user",
+                                                "port",
+                                                "connectionTimeout",
+                                                "timeout",
+                                                "auth",
+                                                "saslRealm",
+                                                "quitWait",
+                                                "socketFactoryClass",
+                                                "socketFactoryFallback",
+                                                "socketFactoryPort"});
+
+        GBEAN_INFO = infoFactory.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+}
+
+

Propchange: geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPStoreGBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPStoreGBean.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPStoreGBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPTransportGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPTransportGBean.java?rev=387218&view=auto
==============================================================================
--- geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPTransportGBean.java
(added)
+++ geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPTransportGBean.java
Mon Mar 20 07:12:37 2006
@@ -0,0 +1,413 @@
+/**
+ *
+ * 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.mail;
+
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+
+/**
+ * A GBean that provides for the configuration of a JavaMail NNTP transport
+ * protocol.
+ * <p/>
+ * NNTP transport properties that are common to all NNTP transports are
+ * provided via member variables of this class.  Values that are set in the
+ * individual member variables will override any of the corresponding values
+ * that have been set in the properties set.
+ *
+ * @version $Rev$ $Date$
+ * @see MailGBean
+ */
+public class NNTPTransportGBean extends ProtocolGBean {
+
+    private final Log log = LogFactory.getLog(NNTPTransportGBean.class);
+
+    private Integer port;
+    private Integer connectionTimeout;
+    private Integer timeout;
+    private String from;
+    private Boolean auth;
+    private String saslRealm;
+    private Boolean quitWait;
+    private String socketFactoryClass;
+    private Boolean socketFactoryFallback;
+    private Integer socketFactoryPort;
+
+
+    /**
+     * Construct an instance of NNTPTransportGBean
+     * <p/>
+     * Values that are set in the individual member variables will override any of
+     * the corresponding values that have been set in the properties set.
+     *
+     * @param objectName            the object name of the protocol
+     * @param properties            the set of default properties for the protocol
+     * @param host                  the host the protocol connects to
+     * @param user                  the default name for the protocol
+     * @param port                  the NNTP server port
+     * @param connectionTimeout     the socket connection timeout value in milliseconds
+     * @param timeout               the socket I/O timeout value in milliseconds
+     * @param from                  the email address to use for NNTP POST command
+     * @param auth                  whether an attempt will be made to authenticate the user
+     * @param saslRealm             the realm to use with DIGEST-MD5 authentication
+     * @param quitWait              whether the transport will wait for the response to the
QUIT command
+     * @param socketFactoryClass    the class that will be used to create NNTP sockets
+     * @param socketFactoryFallback whether java.net.Socket class will be created if the
specified
+     *                              socket factory class cannot be created
+     * @param socketFactoryPort     whether java.net.Socket class will be created if the
specified
+     *                              socket factory class cannot be created
+     */
+    public NNTPTransportGBean(String objectName, Properties properties, String host, String
user,
+                              Integer port,
+                              Integer connectionTimeout,
+                              Integer timeout,
+                              String from,
+                              Boolean auth,
+                              String saslRealm,
+                              Boolean quitWait,
+                              String socketFactoryClass,
+                              Boolean socketFactoryFallback,
+                              Integer socketFactoryPort) {
+        super(objectName, "nntp-post", properties, host, user);
+
+        setPort(port);
+        setConnectionTimeout(connectionTimeout);
+        setTimeout(timeout);
+        setFrom(from);
+        setAuth(auth);
+        setSaslRealm(saslRealm);
+        setQuitWait(quitWait);
+        setSocketFactoryClass(socketFactoryClass);
+        setSocketFactoryFallback(socketFactoryFallback);
+        setSocketFactoryPort(socketFactoryPort);
+    }
+
+    /**
+     * Returns the NNTP server port to connect to, if the connect() method
+     * doesn't explicitly specify one.
+     */
+    public Integer getPort() {
+        return port;
+    }
+
+    /**
+     * Sets the NNTP server port to connect to, if the connect() method
+     * doesn't explicitly specify one.
+     * <p/>
+     * Defaults to 25.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param port the NNTP server port to connect to
+     */
+    public void setPort(Integer port) {
+        this.port = port;
+    }
+
+    /**
+     * Returns the socket connection timeout value in milliseconds.
+     */
+    public Integer getConnectionTimeout() {
+        return connectionTimeout;
+    }
+
+    /**
+     * Sets the socket connection timeout value in milliseconds.
+     * <p/>
+     * Default is infinite timeout.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param connectionTimeout the socket connection timeout value in milliseconds.
+     */
+    public void setConnectionTimeout(Integer connectionTimeout) {
+        this.connectionTimeout = connectionTimeout;
+    }
+
+    /**
+     * Returns the socket I/O timeout value in milliseconds.
+     */
+    public Integer getTimeout() {
+        return timeout;
+    }
+
+    /**
+     * Sets the socket I/O timeout value in milliseconds.
+     * <p/>
+     * Default is infinite timeout.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param timeout the socket I/O timeout value in milliseconds
+     */
+    public void setTimeout(Integer timeout) {
+        this.timeout = timeout;
+    }
+
+    /**
+     * Returns the email address to use for NNTP POST command.
+     */
+    public String getFrom() {
+        return from;
+    }
+
+    /**
+     * Sets the email address to use for NNTP POST command
+     * <p/>
+     * Email address to use for NNTP POST command. This sets the envelope
+     * return address. Defaults to msg.getFrom() or InternetAddress.getLocalAddress().
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param from the email address to use for NNTP POST command
+     */
+    public void setFrom(String from) {
+        this.from = from;
+    }
+
+    /**
+     * Returns whether an attempt will be made to authenticate the user
+     * <p/>
+     * Defaults to false.
+     */
+    public Boolean getAuth() {
+        return auth;
+    }
+
+    /**
+     * Sets whether an attempt will be made to authenticate the user.
+     * <p/>
+     * Defaults to false.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param auth whether an attempt will be made to authenticate the user.
+     */
+    public void setAuth(Boolean auth) {
+        this.auth = auth;
+    }
+
+    /**
+     * Returns the realm to use with DIGEST-MD5 authentication.
+     */
+    public String getSaslRealm() {
+        return saslRealm;
+    }
+
+    /**
+     * Sets the realm to use with DIGEST-MD5 authentication.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param saslRealm the realm to use with DIGEST-MD5 authentication
+     */
+    public void setSaslRealm(String saslRealm) {
+        this.saslRealm = saslRealm;
+    }
+
+    /**
+     * Returns whether the transport will wait for the response to the QUIT command.
+     * <p/>
+     * If set to true, causes the transport to wait for the response to the QUIT
+     * command. If set to false (the default), the QUIT command is sent and the
+     * connection is immediately closed.
+     */
+    public Boolean getQuitWait() {
+        return quitWait;
+    }
+
+    /**
+     * Sets whether the transport will wait for the response to the QUIT command
+     * <p/>
+     * If set to true, causes the transport to wait for the response to the QUIT
+     * command. If set to false (the default), the QUIT command is sent and the
+     * connection is immediately closed.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param quitWait whether the transport will wait for the response to the QUIT command
+     */
+    public void setQuitWait(Boolean quitWait) {
+        this.quitWait = quitWait;
+    }
+
+    /**
+     * Returns the class that will be used to create NNTP sockets.
+     * <p/>
+     * If set, specifies the name of a class that implements the
+     * javax.net.SocketFactory interface. This class will be used to create NNTP
+     * sockets.
+     */
+    public String getSocketFactoryClass() {
+        return socketFactoryClass;
+    }
+
+    /**
+     * Sets the class that will be used to create NNTP sockets.
+     * <p/>
+     * If set, specifies the name of a class that implements the
+     * javax.net.SocketFactory interface. This class will be used to create NNTP
+     * sockets.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param socketFactoryClass the class that will be used to create NNTP sockets
+     */
+    public void setSocketFactoryClass(String socketFactoryClass) {
+        this.socketFactoryClass = socketFactoryClass;
+    }
+
+    /**
+     * Returns whether java.net.Socket class will be created if the specified
+     * socket factory class cannot be created.
+     * <p/>
+     * If set to true, failure to create a socket using the specified socket
+     * factory class will cause the socket to be created using the
+     * java.net.Socket class. Defaults to true.
+     */
+    public Boolean getSocketFactoryFallback() {
+        return socketFactoryFallback;
+    }
+
+    /**
+     * Sets whether java.net.Socket class will be created if the specified
+     * socket factory class cannot be created.
+     * <p/>
+     * If set to true, failure to create a socket using the specified socket
+     * factory class will cause the socket to be created using the
+     * java.net.Socket class. Defaults to true.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param socketFactoryFallback whether java.net.Socket class will be created if the
specified
+     *                              socket factory class cannot be created
+     */
+    public void setSocketFactoryFallback(Boolean socketFactoryFallback) {
+        this.socketFactoryFallback = socketFactoryFallback;
+    }
+
+    /**
+     * Returns the port to connect to when using the specified socket factory.
+     * <p/>
+     * Specifies the port to connect to when using the specified socket
+     * factory. If not set, the default port will be used.
+     */
+    public Integer getSocketFactoryPort() {
+        return socketFactoryPort;
+    }
+
+    /**
+     * Sets the port to connect to when using the specified socket factory.
+     * <p/>
+     * Specifies the port to connect to when using the specified socket
+     * factory. If not set, the default port will be used.
+     * <p/>
+     * Values that are set here will override any of the corresponding value
+     * that has been set in the properties.
+     *
+     * @param socketFactoryPort the port to connect to when using the specified socket factory
+     */
+    public void setSocketFactoryPort(Integer socketFactoryPort) {
+        this.socketFactoryPort = socketFactoryPort;
+    }
+
+    /**
+     * Add the overrides from the member variables to the properties file.
+     */
+    public void addOverrides(Properties props) {
+        super.addOverrides(props);
+
+        if (port != null) props.put("mail.nntp.port", port);
+        if (connectionTimeout != null) props.put("mail.nntp.connectiontimeout", connectionTimeout);
+        if (timeout != null) props.put("mail.nntp.timeout", timeout);
+        if (from != null) props.put("mail.nntp.from", from);
+        if (auth != null) props.put("mail.nntp.auth", auth);
+        if (saslRealm != null) props.put("mail.nntp.sasl.realm", saslRealm);
+        if (quitWait != null) props.put("mail.nntp.quitwait", quitWait);
+        if (socketFactoryClass != null) props.put("mail.nntp.socketFactory.class", socketFactoryClass);
+        if (socketFactoryFallback != null) props.put("mail.nntp.socketFactory.fallback",
socketFactoryFallback);
+        if (socketFactoryPort != null) props.put("mail.nntp.socketFactory.port", socketFactoryPort);
+    }
+
+    public void doStart() throws Exception {
+        log.debug("Started " + getObjectName());
+    }
+
+    public void doStop() throws Exception {
+        log.debug("Stopped " + getObjectName());
+    }
+
+    public void doFail() {
+        log.warn("Failed " + getObjectName());
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(NNTPTransportGBean.class);
+
+        infoFactory.addAttribute("port", Integer.class, true);
+        infoFactory.addAttribute("connectionTimeout", Integer.class, true);
+        infoFactory.addAttribute("timeout", Integer.class, true);
+        infoFactory.addAttribute("from", String.class, true);
+        infoFactory.addAttribute("auth", Boolean.class, true);
+        infoFactory.addAttribute("saslRealm", String.class, true);
+        infoFactory.addAttribute("quitWait", Boolean.class, true);
+        infoFactory.addAttribute("socketFactoryClass", String.class, true);
+        infoFactory.addAttribute("socketFactoryFallback", Boolean.class, true);
+        infoFactory.addAttribute("socketFactoryPort", Integer.class, true);
+
+        infoFactory.addAttribute("objectName", String.class, false);
+        infoFactory.addAttribute("protocol", String.class, false);
+        infoFactory.addAttribute("properties", Properties.class, true);
+        infoFactory.addAttribute("host", String.class, true);
+        infoFactory.addAttribute("user", String.class, true);
+        infoFactory.addOperation("addOverrides", new Class[]{Properties.class});
+
+        infoFactory.setConstructor(new String[]{"objectName", "properties", "host", "user",
+                                                "port",
+                                                "connectionTimeout",
+                                                "timeout",
+                                                "from",
+                                                "auth",
+                                                "saslRealm",
+                                                "quitWait",
+                                                "socketFactoryClass",
+                                                "socketFactoryFallback",
+                                                "socketFactoryPort"});
+
+        GBEAN_INFO = infoFactory.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+}
+

Propchange: geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPTransportGBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPTransportGBean.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: geronimo/trunk/modules/mail/src/java/org/apache/geronimo/mail/NNTPTransportGBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/trunk/modules/mail/src/test/org/apache/geronimo/mail/MailGBeanTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/mail/src/test/org/apache/geronimo/mail/MailGBeanTest.java?rev=387218&r1=387217&r2=387218&view=diff
==============================================================================
--- geronimo/trunk/modules/mail/src/test/org/apache/geronimo/mail/MailGBeanTest.java (original)
+++ geronimo/trunk/modules/mail/src/test/org/apache/geronimo/mail/MailGBeanTest.java Mon Mar
20 07:12:37 2006
@@ -140,11 +140,53 @@
         kernel.stopGBean(mailName);
     }
 
+    public void testNNTPPostOverrides() throws Exception {
+        Properties properties = new Properties();
+        properties.put("mail.store.protocol", "POOKIE");
+        properties.put("mail.transport.protocol", "BEAR");
+        properties.put("mail.nntp.quitwait", "true");
+
+        mailName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,J2EEType=JavaMailResource,name=default");
+        GBeanData cmf = new GBeanData(mailName, MailGBean.getGBeanInfo());
+        cmf.setReferencePattern("Protocols", new ObjectName("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,type=JavaMailProtocol,*"));
+        cmf.setAttribute("useDefault", new Boolean(true));
+        cmf.setAttribute("properties", properties);
+        cmf.setAttribute("storeProtocol", "test");
+        cmf.setAttribute("transportProtocol", "test");
+
+
+        kernel.loadGBean(cmf, MailGBean.class.getClassLoader());
+        kernel.startGBean(mailName);
+
+        protocolName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,type=JavaMailProtocol,name=nntp-post");
+        GBeanData nntp = new GBeanData(protocolName, NNTPTransportGBean.getGBeanInfo());
+        kernel.loadGBean(nntp, NNTPTransportGBean.class.getClassLoader());
+        kernel.startGBean(protocolName);
+
+        Object proxy = kernel.invoke(mailName, "$getResource");
+
+        assertNotNull(proxy);
+        assertTrue(proxy instanceof Session);
+
+        Store store = ((Session) proxy).getStore();
+        assertNotNull(store);
+        assertTrue(store instanceof TestStore);
+
+        Transport transport = ((Session) proxy).getTransport();
+        assertNotNull(transport);
+        assertTrue(transport instanceof TestTransport);
+
+        TestTransport testTransport = (TestTransport) transport;
+        assertFalse(testTransport.isQuitWait());
+
+        kernel.stopGBean(protocolName);
+        kernel.stopGBean(mailName);
+    }
+
     public void testPOP3Overrides() throws Exception {
         Properties properties = new Properties();
         properties.put("mail.store.protocol", "POOKIE");
         properties.put("mail.transport.protocol", "BEAR");
-        properties.put("mail.pop3.ehlo", "true");
 
         mailName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,J2EEType=JavaMailResource,name=default");
         GBeanData cmf = new GBeanData(mailName, MailGBean.getGBeanInfo());
@@ -157,8 +199,46 @@
         kernel.startGBean(mailName);
 
         protocolName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,type=JavaMailProtocol,name=pop3");
-        GBeanData pop3 = new GBeanData(protocolName, SMTPTransportGBean.getGBeanInfo());
// todo shouldn't this be POP3Store?
-        kernel.loadGBean(pop3, SMTPTransportGBean.class.getClassLoader());
+        GBeanData pop3 = new GBeanData(protocolName, POP3StoreGBean.getGBeanInfo());
+        kernel.loadGBean(pop3, POP3StoreGBean.class.getClassLoader());
+        kernel.startGBean(protocolName);
+
+        Object proxy = kernel.invoke(mailName, "$getResource");
+
+        assertNotNull(proxy);
+        assertTrue(proxy instanceof Session);
+
+        Store store = ((Session) proxy).getStore();
+        assertNotNull(store);
+        assertTrue(store instanceof TestStore);
+
+        Transport transport = ((Session) proxy).getTransport();
+        assertNotNull(transport);
+        assertTrue(transport instanceof TestTransport);
+
+        kernel.stopGBean(protocolName);
+        kernel.stopGBean(mailName);
+    }
+
+    public void testNNTPStoreOverrides() throws Exception {
+        Properties properties = new Properties();
+        properties.put("mail.store.protocol", "POOKIE");
+        properties.put("mail.transport.protocol", "BEAR");
+        properties.put("mail.nntp.quitwait", "true");
+
+        mailName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,J2EEType=JavaMailResource,name=default");
+        GBeanData cmf = new GBeanData(mailName, MailGBean.getGBeanInfo());
+        cmf.setReferencePattern("Protocols", new ObjectName("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,type=JavaMailProtocol,*"));
+        cmf.setAttribute("useDefault", new Boolean(true));
+        cmf.setAttribute("properties", properties);
+        cmf.setAttribute("storeProtocol", "test");
+        cmf.setAttribute("transportProtocol", "test");
+        kernel.loadGBean(cmf, MailGBean.class.getClassLoader());
+        kernel.startGBean(mailName);
+
+        protocolName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,type=JavaMailProtocol,name=nntp");
+        GBeanData nntp = new GBeanData(protocolName, NNTPStoreGBean.getGBeanInfo());
+        kernel.loadGBean(nntp, NNTPStoreGBean.class.getClassLoader());
         kernel.startGBean(protocolName);
 
         Object proxy = kernel.invoke(mailName, "$getResource");
@@ -182,7 +262,6 @@
         Properties properties = new Properties();
         properties.put("mail.store.protocol", "POOKIE");
         properties.put("mail.transport.protocol", "BEAR");
-        properties.put("mail.imap.ehlo", "true");
 
         mailName = ObjectName.getInstance("geronimo.server:J2EEServer=geronimo,J2EEApplication=null,J2EEType=JavaMailResource,name=default");
         GBeanData cmf = new GBeanData(mailName, MailGBean.getGBeanInfo());

Modified: geronimo/trunk/modules/mail/src/test/org/apache/geronimo/mail/TestTransport.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/mail/src/test/org/apache/geronimo/mail/TestTransport.java?rev=387218&r1=387217&r2=387218&view=diff
==============================================================================
--- geronimo/trunk/modules/mail/src/test/org/apache/geronimo/mail/TestTransport.java (original)
+++ geronimo/trunk/modules/mail/src/test/org/apache/geronimo/mail/TestTransport.java Mon Mar
20 07:12:37 2006
@@ -39,4 +39,8 @@
     public boolean isEHLO() {
         return "true".equals(session.getProperties().getProperty("mail.smtp.ehlo"));
     }
+
+    public boolean isQuitWait() {
+        return "true".equals(session.getProperties().getProperty("mail.nntp.quitwait"));
+    }
 }



Mime
View raw message