
org.apache.geronimo.mail.NNTPTransportGBean Maven / Gradle / Ivy
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*
* 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: 486195 $ $Date: 2006-12-12 10:42:02 -0500 (Tue, 12 Dec 2006) $
* @see MailGBean
*/
public class NNTPTransportGBean extends ProtocolGBean implements NNTPGBeanConstants {
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
*
* 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.
*
* Defaults to 25.
*
* 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.
*
* Default is infinite timeout.
*
* 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.
*
* Default is infinite timeout.
*
* 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
*
* Email address to use for NNTP POST command. This sets the envelope
* return address. Defaults to msg.getFrom() or InternetAddress.getLocalAddress().
*
* 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
*
* Defaults to false.
*/
public Boolean getAuth() {
return auth;
}
/**
* Sets whether an attempt will be made to authenticate the user.
*
* Defaults to false.
*
* 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.
*
* 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.
*
* 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
*
* 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.
*
* 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.
*
* 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.
*
* If set, specifies the name of a class that implements the
* javax.net.SocketFactory interface. This class will be used to create NNTP
* sockets.
*
* 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.
*
* 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.
*
* 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.
*
* 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.
*
* 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.
*
* Specifies the port to connect to when using the specified socket
* factory. If not set, the default port will be used.
*
* 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.setProperty(NNTP_PORT, port.toString());
if (connectionTimeout != null) props.setProperty(NNTP_CONNECTION_TIMEOUT, connectionTimeout.toString());
if (timeout != null) props.setProperty(NNTP_TIMEOUT, timeout.toString());
if (from != null) props.setProperty(NNTP_FROM, from);
if (auth != null) props.setProperty(NNTP_AUTH, auth.toString());
if (saslRealm != null) props.setProperty(NNTP_REALM, saslRealm);
if (quitWait != null) props.setProperty(NNTP_QUITWAIT, quitWait.toString());
if (socketFactoryClass != null) props.setProperty(NNTP_FACTORY_CLASS, socketFactoryClass);
if (socketFactoryFallback != null) props.setProperty(NNTP_FACTORY_FALLBACK, socketFactoryFallback.toString());
if (socketFactoryPort != null) props.setProperty(NNTP_FACTORY_PORT, socketFactoryPort.toString());
}
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(GBEAN_PORT, Integer.class, true);
infoFactory.addAttribute(GBEAN_CONNECTION_TIMEOUT, Integer.class, true);
infoFactory.addAttribute(GBEAN_TIMEOUT, Integer.class, true);
infoFactory.addAttribute(GBEAN_AUTH, Boolean.class, true);
infoFactory.addAttribute(GBEAN_FROM, String.class, true);
infoFactory.addAttribute(GBEAN_REALM, String.class, true);
infoFactory.addAttribute(GBEAN_QUITWAIT, Boolean.class, true);
infoFactory.addAttribute(GBEAN_FACTORY_CLASS, String.class, true);
infoFactory.addAttribute(GBEAN_FACTORY_FALLBACK, Boolean.class, true);
infoFactory.addAttribute(GBEAN_FACTORY_PORT, Integer.class, true);
infoFactory.addAttribute(GBEAN_OBJECTNAME, String.class, false);
infoFactory.addAttribute(GBEAN_PROTOCOL, String.class, true);
infoFactory.addAttribute(GBEAN_PROPERTIES, Properties.class, true);
infoFactory.addAttribute(GBEAN_HOST, String.class, true);
infoFactory.addAttribute(GBEAN_USER, String.class, true);
infoFactory.addOperation(GBEAN_ADD_OVERRIDES, new Class[]{Properties.class});
infoFactory.setConstructor(new String[]{GBEAN_OBJECTNAME, GBEAN_PROPERTIES, GBEAN_HOST, GBEAN_USER,
GBEAN_PORT,
GBEAN_CONNECTION_TIMEOUT,
GBEAN_TIMEOUT,
GBEAN_FROM,
GBEAN_AUTH,
GBEAN_REALM,
GBEAN_QUITWAIT,
GBEAN_FACTORY_CLASS,
GBEAN_FACTORY_FALLBACK,
GBEAN_FACTORY_PORT});
GBEAN_INFO = infoFactory.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy