Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

108205: Merged 5.0.N (5.0.3) to HEAD-BUG-FIX (5.1/Cloud)
      108186:       Reverse merged 5.0.N (5.0.3)
               << Better solution found >>
               106968: Merged DEV to 5.0.N (5.0.3)
                  106962: MNT-13706 : Admin console unusable after we set any  busy port in Port Number Value for subsystem
                     - Implemented fix for Transformations (JodConverter), FTP, SMTP and IMAP.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@108221 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-07-14 07:03:15 +00:00
parent 576d2a0afd
commit f13dc0a415
8 changed files with 1533 additions and 1843 deletions

View File

@@ -464,9 +464,6 @@
<property name="persister">
<bean class="org.alfresco.config.AlfrescoPropertiesPersister"/>
</property>
<property name="loggableErrorEventMatcher">
<value>^.*ServerConfigurationBean.*$</value>
</property>
</bean>
<bean id="fileServerConfiguration" class="org.alfresco.repo.management.subsystems.SubsystemProxyFactory">
@@ -513,9 +510,6 @@
</entry>
</map>
</property>
<property name="loggableErrorEventMatcher">
<value>^.*AlfrescoImapServer.*$</value>
</property>
</bean>
<!-- Outbound Email subsystem -->
@@ -552,9 +546,6 @@
<property name="autoStart">
<value>true</value>
</property>
<property name="loggableErrorEventMatcher">
<value>^.*EmailServer.*$</value>
</property>
</bean>
<!-- Subscription Service subsystem -->

View File

@@ -89,13 +89,6 @@ system.usage.err.limit_documents_exceeded=The allowable content limit of {0} has
system.usage.err.limit_license_expiring=The Alfresco license will expire in {0} days.
system.usage.err.limit_license_expired=The Alfresco license has expired.
# Subsystems error messages
system.loggable_error_event.unspecified_error=Unspecified error.
system.jodconverter.err.failed_start=Unable to start JodConverter library. Cause: {0}.
system.imap.err.port_in_use=The port chosen for IMAP is already in use: {0}.
system.smtp.err.port_in_use=The port chosen for SMTP is already in use: {0}.
system.ftp.err.port_in_use=The port chosen for FTP is already in use: {0}.
# License
system.license.msg.unknown=Unknown
system.license.msg.unlimited=Unlimited

View File

@@ -28,7 +28,6 @@ import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.service.cmr.email.EmailMessageException;
import org.alfresco.service.cmr.email.EmailService;
import org.alfresco.util.PortUtil;
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
import org.alfresco.util.PropertyCheck;
import org.springframework.beans.BeansException;
@@ -43,7 +42,6 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
public abstract class EmailServer extends AbstractLifecycleBean
{
private static final String ERR_SENDER_BLOCKED = "email.server.err.sender_blocked";
private static final String SMTP_PORT_OCCUPIED_MESSAGE = "system.smtp.err.port_in_use";
private boolean enabled;
private String domain;
@@ -250,13 +248,6 @@ public abstract class EmailServer extends AbstractLifecycleBean
{
throw new AlfrescoRuntimeException("Property 'port' is incorrect");
}
// Check if port is occupied.
if (!PortUtil.isPortFree(port))
{
throw new AlfrescoRuntimeException(SMTP_PORT_OCCUPIED_MESSAGE, new String[] { "" + port });
}
PropertyCheck.mandatory(this, "emailService", emailService);
// Startup
startup();

View File

@@ -83,11 +83,7 @@ import org.alfresco.jlan.util.Platform;
import org.alfresco.jlan.util.StringList;
import org.alfresco.jlan.util.X64;
import org.alfresco.repo.management.subsystems.ActivateableBean;
import org.alfresco.repo.management.subsystems.LoggableErrorEvent;
import org.alfresco.util.PortUtil;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.extensions.config.element.GenericConfigElement;
@@ -103,10 +99,8 @@ import org.springframework.extensions.config.element.GenericConfigElement;
* @author dward
* @author mrogers
*/
public class ServerConfigurationBean extends AbstractServerConfigurationBean implements DisposableBean, ApplicationEventPublisherAware
public class ServerConfigurationBean extends AbstractServerConfigurationBean implements DisposableBean
{
private static final String FTP_PORT_OCCUPIED_MESSAGE = "system.ftp.err.port_in_use";
private CIFSConfigBean cifsConfigBean;
private FTPConfigBean ftpConfigBean;
private NFSConfigBean nfsConfigBean;
@@ -116,7 +110,6 @@ public class ServerConfigurationBean extends AbstractServerConfigurationBean imp
private ThreadRequestPool threadPool;
protected ClusterConfigBean clusterConfigBean;
private ApplicationEventPublisher applicationEventPublisher;
/**
* Default constructor
@@ -1227,13 +1220,6 @@ public class ServerConfigurationBean extends AbstractServerConfigurationBean imp
ftpConfig.setFTPPort(port);
if (ftpConfig.getFTPPort() <= 0 || ftpConfig.getFTPPort() >= 65535)
throw new AlfrescoRuntimeException("FTP server port out of valid range");
// Check if port is occupied.
if (!PortUtil.isPortFree(port))
{
applicationEventPublisher.publishEvent(new LoggableErrorEvent(this,
new AlfrescoRuntimeException(FTP_PORT_OCCUPIED_MESSAGE, new String[] { "" + port })));
}
}
else
{
@@ -2382,10 +2368,4 @@ public class ServerConfigurationBean extends AbstractServerConfigurationBean imp
}
}
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
{
this.applicationEventPublisher = applicationEventPublisher;
}
}

View File

@@ -37,27 +37,12 @@ import com.icegreen.greenmail.util.ServerSetup;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLServerSocket;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.management.subsystems.LoggableErrorEvent;
import org.alfresco.util.PortUtil;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
/**
* @author Mike Shavnev
*/
public class AlfrescoImapServer extends AbstractLifecycleBean implements ApplicationEventPublisherAware
public class AlfrescoImapServer extends AbstractLifecycleBean
{
private static final String IMAP_PORT_OCCUPIED_MESSAGE = "system.imap.err.port_in_use";
private ApplicationEventPublisher applicationEventPublisher;
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
{
this.applicationEventPublisher = applicationEventPublisher;
}
private class SecureImapServer extends ImapServer
{
@@ -265,13 +250,6 @@ public class AlfrescoImapServer extends AbstractLifecycleBean implements Applica
if(isImapEnabled())
{
// Check if port is occupied.
if (!PortUtil.isPortFree(port))
{
applicationEventPublisher.publishEvent(new LoggableErrorEvent(this,
new AlfrescoRuntimeException(IMAP_PORT_OCCUPIED_MESSAGE, new String[] { "" + port })));
}
AtomicReference<Exception> serverOpeningExceptionRef = new AtomicReference<Exception>();
serverImpl = new DefaultImapServer(new ServerSetup(port, host, ServerSetup.PROTOCOL_IMAP), imapManagers, serverOpeningExceptionRef);
serverImpl.startService(null);

View File

@@ -28,7 +28,6 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.alfresco.error.AlfrescoRuntimeException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -93,7 +92,6 @@ public abstract class AbstractPropertyBackedBean implements PropertyBackedBean,
/** Resolves placeholders in the property defaults. */
private DefaultResolver defaultResolver = new DefaultResolver();
private LoggableErrorEvent loggableErrorEvent;
/** The lifecycle states. */
protected enum RuntimeState {UNINITIALIZED, STOPPED, PENDING_BROADCAST_START, STARTED};
@@ -103,29 +101,9 @@ public abstract class AbstractPropertyBackedBean implements PropertyBackedBean,
/** The state. */
private PropertyBackedBeanState state;
private int timeoutForLoggableErrorEventMonitoringThread = 60000;
private int incrementForLoggableErrorEventMonitoringThread = 100;
/** Lock for concurrent access. */
protected ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
private String loggableErrorEventMatcher = "";
public void setLoggableErrorEventMatcher(String loggableErrorEventMatcher)
{
this.loggableErrorEventMatcher = loggableErrorEventMatcher;
}
public void setTimeoutForLoggableErrorEventMonitoringThread(int timeout)
{
timeoutForLoggableErrorEventMonitoringThread = timeout;
}
public void setIncrementForLoggableErrorEventMonitoringThread(int increment)
{
incrementForLoggableErrorEventMonitoringThread = increment;
}
/**
* Used in conjunction with {@link #localSetProperties} to control setting of
* properties from either a JMX client or by code in the local Alfresco
@@ -624,23 +602,6 @@ public abstract class AbstractPropertyBackedBean implements PropertyBackedBean,
this.lock.writeLock().unlock();
}
}
else if (event instanceof LoggableErrorEvent)
{
Object source = event.getSource();
if ((source != null) && source.getClass().getName().matches(loggableErrorEventMatcher))
{
this.lock.writeLock().lock();
try
{
this.loggableErrorEvent = (LoggableErrorEvent) event;
}
finally
{
this.lock.writeLock().unlock();
}
}
}
}
/**
@@ -1012,89 +973,15 @@ public abstract class AbstractPropertyBackedBean implements PropertyBackedBean,
}
}
private class LoggableErrorEventMonitoringThread extends Thread
{
private int counter = 0;
private AlfrescoRuntimeException caughtException = null;
public void run()
{
while (true)
{
AbstractPropertyBackedBean.this.lock.readLock().lock();
try
{
if (loggableErrorEvent != null)
{
caughtException = loggableErrorEvent.getException();
}
}
finally
{
AbstractPropertyBackedBean.this.lock.readLock().unlock();
}
if (counter >= timeoutForLoggableErrorEventMonitoringThread || caughtException != null)
{
break;
}
try
{
Thread.sleep(incrementForLoggableErrorEventMonitoringThread);
counter += incrementForLoggableErrorEventMonitoringThread;
}
catch (InterruptedException ie)
{
if (logger.isDebugEnabled())
{
logger.debug(ie.toString());
}
}
}
if (caughtException != null)
{
if (logger.isErrorEnabled())
{
logger.error(caughtException.toString());
}
loggableErrorEvent = null;
throw caughtException;
}
}
}
/**
* {@inheritDoc}
*/
public final void start()
{
this.lock.writeLock().lock();
try
{
start(true, false);
if (loggableErrorEvent != null)
{
AlfrescoRuntimeException caughtException = loggableErrorEvent.getException();
if (logger.isErrorEnabled())
{
logger.error(caughtException.toString());
}
loggableErrorEvent = null;
throw caughtException;
}
else
{
(new LoggableErrorEventMonitoringThread()).start();
}
}
finally
{

View File

@@ -1,59 +0,0 @@
/*
* Copyright (C) 2005-2015 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.management.subsystems;
import org.alfresco.error.AlfrescoRuntimeException;
import org.springframework.context.ApplicationEvent;
/**
* Alfresco custom ApplicationEvent class used for publishing errors in subsystems.
*/
public class LoggableErrorEvent extends ApplicationEvent
{
private static final String UNSPECIFIED_ERROR_MESSAGE = "system.loggable_error_event.unspecified_error";
private AlfrescoRuntimeException exception;
/**
* Create a new LoggableErrorEvent.
* @param source the component that published the event (never {@code null})
* @param exception the error to publish
*/
public LoggableErrorEvent(Object source, AlfrescoRuntimeException exception)
{
super(source);
this.exception = exception;
}
/**
* Get this LoggableErrorEvent's exception.
* @return the stored exception if not null, otherwise a new RuntimeException
*/
public AlfrescoRuntimeException getException()
{
if (exception != null)
{
return exception;
}
else
{
return new AlfrescoRuntimeException(UNSPECIFIED_ERROR_MESSAGE);
}
}
}

View File

@@ -1,71 +0,0 @@
/*
* Copyright (C) 2005-2015 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.util;
import java.io.IOException;
import java.net.ServerSocket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Alfresco port-related utility functions.
*/
public class PortUtil
{
private static Log logger = LogFactory.getLog(PortUtil.class);
/**
* Check if specified port is free.
* @param port port number to check
* @return true if port is free or false if it's already in use
*/
public static boolean isPortFree(int port)
{
boolean isFree = true;
ServerSocket serverSocket = null;
try
{
serverSocket = new ServerSocket(port);
}
catch (IOException ioe)
{
isFree = false;
}
finally
{
if (serverSocket != null)
{
try
{
serverSocket.close();
}
catch (IOException ioe)
{
if (logger.isDebugEnabled())
{
logger.debug(ioe.toString());
}
}
}
}
return isFree;
}
}