Skip to content

Commit

Permalink
0003232: Upgrade Jetty to the latest version. Require Java 8.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Aug 22, 2017
1 parent bb135c0 commit 053dc4f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 157 deletions.
10 changes: 5 additions & 5 deletions symmetric-assemble/common.gradle
Expand Up @@ -69,8 +69,8 @@ subprojects { subproject ->
configurations.provided.transitive = true
configurations.optional.transitive = false

sourceCompatibility=1.6
targetCompatibility=1.6
sourceCompatibility=1.8
targetCompatibility=1.8

eclipse {
classpath {
Expand All @@ -79,8 +79,8 @@ subprojects { subproject ->
}

jdt {
sourceCompatibility = 1.7
targetCompatibility = 1.7
sourceCompatibility = 1.8
targetCompatibility = 1.8
}

project.file.whenMerged { project ->
Expand Down Expand Up @@ -194,7 +194,7 @@ subprojects { subproject ->
bouncyCastleVersion = '140'
animalSnifferVersion = '1.10'
jnaVersion = '4.1.0'
jettyVersion = '9.2.18.v20160721'
jettyVersion = '9.4.5.v20170502'
nuodbVersion = '2.6.1'
tiberoVersion = '6'
env = System.getenv()
Expand Down
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip
4 changes: 2 additions & 2 deletions symmetric-assemble/src/asciidoc/introduction.ad
Expand Up @@ -10,11 +10,11 @@ The software was designed to scale for a large number of nodes, work across low-
=== System Requirements

SymmetricDS is written in Java and requires a Java Runtime Environment (JRE) Standard Edition (SE) or Java Development Kit (JDK)
Standard Edition (SE) version 7.0 or above.
Standard Edition (SE) version 8.0 or above.
Most major operating systems and databases are supported. See the list of supported databases in the <<databases-compatibility>> section.
The minimum operating system requirements are:

* Java SE Runtime Environment 7 or above
* Java SE Runtime Environment 8 or above
* Memory - 64 (MB) available
* Disk - 256 (MB) available

Expand Down
@@ -1,3 +1,3 @@
== Troubleshooting

This is the troubleshooting section of the guilde.
This is the troubleshooting section of the guide.
Expand Up @@ -4,6 +4,7 @@

import javax.sql.DataSource;

import org.jumpmind.db.platform.generic.GenericJdbcDatabasePlatform;
import org.jumpmind.db.sql.SqlTemplateSettings;
import org.jumpmind.db.util.BasicDataSourceFactory;
import org.jumpmind.db.util.BasicDataSourcePropertyConstants;
Expand All @@ -16,7 +17,6 @@
import org.jumpmind.symmetric.ext.ISymmetricEngineAware;
import org.jumpmind.symmetric.io.data.IDataWriter;
import org.jumpmind.symmetric.io.data.writer.Conflict;
import org.jumpmind.symmetric.io.data.writer.GenericJdbcPlatform;
import org.jumpmind.symmetric.io.data.writer.IDatabaseWriterErrorHandler;
import org.jumpmind.symmetric.io.data.writer.IDatabaseWriterFilter;
import org.jumpmind.symmetric.io.data.writer.JdbcDatabaseWriter;
Expand Down Expand Up @@ -58,8 +58,7 @@ public IDataWriter getDataWriter(String sourceNodeId, ISymmetricDialect symmetri
}

DataSource dataSource = BasicDataSourceFactory.create(properties, SecurityServiceFactory.create(SecurityServiceType.CLIENT, properties));
GenericJdbcPlatform platform = new GenericJdbcPlatform(dataSource, new SqlTemplateSettings());
platform.setName(parameterService.getString("jdbc.alias"));
GenericJdbcDatabasePlatform platform = new GenericJdbcDatabasePlatform(dataSource, new SqlTemplateSettings());

return new JdbcDatabaseWriter(platform);
}
Expand Down
Expand Up @@ -20,29 +20,16 @@
*/
package org.jumpmind.symmetric;

import static org.apache.commons.lang.StringUtils.isNotBlank;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Enumeration;

import javax.management.Attribute;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.servlet.DispatcherType;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.websocket.server.ServerContainer;
import javax.websocket.server.ServerEndpointConfig;

Expand All @@ -52,6 +39,7 @@
import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.UserStore;
import org.eclipse.jetty.security.authentication.BasicAuthenticator;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration;
Expand All @@ -60,9 +48,6 @@
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.server.session.AbstractSession;
import org.eclipse.jetty.server.session.HashSessionManager;
import org.eclipse.jetty.server.session.HashedSession;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.util.security.Password;
Expand Down Expand Up @@ -277,9 +262,6 @@ public SymmetricWebServer start(int httpPort, int securePort, int httpJmxPort, M

webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", allowDirListing);

SessionManager sm = new SessionManager();
webapp.getSessionHandler().setSessionManager(sm);

FilterHolder filterHolder = new FilterHolder(HttpMethodFilter.class);
filterHolder.setInitParameter("server.allow.http.methods", allowedMethods);
filterHolder.setInitParameter("server.disallow.http.methods", disallowedMethods);
Expand Down Expand Up @@ -393,7 +375,9 @@ protected void setupBasicAuthIfNeeded(Server server) {
sh.setAuthenticator(new BasicAuthenticator());

HashLoginService loginService = new HashLoginService();
loginService.putUser(basicAuthUsername, new Password(basicAuthPassword), null);
UserStore userStore = new UserStore();
userStore.addUser(basicAuthUsername, new Password(basicAuthPassword), null);
loginService.setUserStore(userStore);
sh.setLoginService(loginService);

server.setHandler(sh);
Expand Down Expand Up @@ -628,134 +612,10 @@ public void setJmxEnabled(boolean jmxEnabled) {
public boolean isJmxEnabled() {
return jmxEnabled;
}

class SessionManager extends HashSessionManager {

public SessionManager() {
setMaxInactiveInterval(10 * 60);
setLazyLoad(true);
setDeleteUnrestorableSessions(true);
setSessionCookie(getSessionCookie() + (httpPort > 0 ? httpPort
: httpsPort));
}

@Override
protected AbstractSession newSession(HttpServletRequest request) {
return new Session(this, request);
}

@Override
protected AbstractSession newSession(long created, long accessed, String clusterId) {
return new Session(this, created, accessed, clusterId);
}

@Override
protected synchronized HashedSession restoreSession(String idInCuster) {
if (isNotBlank(idInCuster)) {
return super.restoreSession(idInCuster);
} else {
return null;
}
}

public HashedSession restoreSession(InputStream is, HashedSession session) throws Exception {
DataInputStream di = new DataInputStream(is);

String clusterId = di.readUTF();
di.readUTF(); // nodeId

long created = di.readLong();
long accessed = di.readLong();
int requests = di.readInt();

if (session == null)
session = (HashedSession) newSession(created, accessed, clusterId);
session.setRequests(requests);

int size = di.readInt();

restoreSessionAttributes(di, size, session);

try {
int maxIdle = di.readInt();
session.setMaxInactiveInterval(maxIdle);
} catch (EOFException e) {
log.debug("No maxInactiveInterval persisted for session " + clusterId, e);
}

return session;
}

private void restoreSessionAttributes(InputStream is, int size, HashedSession session) throws Exception {
if (size > 0) {
ObjectInputStream ois = new ObjectInputStream(is);
for (int i = 0; i < size; i++) {
String key = ois.readUTF();
try {
Object value = ois.readObject();
session.setAttribute(key, value);
} catch (Exception ex) {
if (ex instanceof ClassCastException || ex instanceof ClassNotFoundException) {
log.warn("Could not restore the '" + key
+ "' session object. Code has probably changed. The error message was: " + ex.getMessage());
} else {
log.error("Could not restore the '" + key + "' session object.", ex);
}
}
}
}
}

}

class Session extends HashedSession {

protected Session(HashSessionManager hashSessionManager, HttpServletRequest request) {
super(hashSessionManager, request);
}

protected Session(HashSessionManager hashSessionManager, long created, long accessed, String clusterId) {
super(hashSessionManager, created, accessed, clusterId);
}

@Override
public synchronized void save(OutputStream os) throws IOException {
DataOutputStream out = new DataOutputStream(os);
out.writeUTF(getClusterId());
out.writeUTF(getNodeId());
out.writeLong(getCreationTime());
out.writeLong(getAccessed());
out.writeInt(getRequests());

Enumeration<String> e = getAttributeNames();
int count = 0;
while (e.hasMoreElements()) {
String key = e.nextElement();
Object obj = doGet(key);
if (obj instanceof Serializable) {
count++;
}
}
out.writeInt(count);
ObjectOutputStream oos = new ObjectOutputStream(out);
e = getAttributeNames();
while (e.hasMoreElements()) {
String key = e.nextElement();
Object obj = doGet(key);
if (obj instanceof Serializable) {
oos.writeUTF(key);
oos.writeObject(obj);
}
}
oos.flush();
out.writeInt(getMaxInactiveInterval());
}

}

protected Class<?> loadRemoteStatusEndpoint() {
try {
Class clazz = ClassUtils.getClass("com.jumpmind.symmetric.console.remote.ServerEndpoint");
Class<?> clazz = ClassUtils.getClass("com.jumpmind.symmetric.console.remote.ServerEndpoint");
return clazz;
} catch (Exception ex) {
log.debug("Failed to load remote status endpoint.", ex);
Expand Down

0 comments on commit 053dc4f

Please sign in to comment.