Skip to content

add Tomcat 8 and Tomcat8.5 #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ example-app/.gradle/*
.rspec
*.iml
.idea/*
gradle*
81 changes: 6 additions & 75 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'

group = 'com.orangefunction'
version = '2.0.0'
version = '2.1.1'

repositories {
mavenLocal()
maven {
url "https://maven.aliyun.com/nexus/content/groups/public"
}
mavenCentral()
}

Expand All @@ -15,10 +17,9 @@ compileJava {
}

dependencies {
compile group: 'org.apache.tomcat', name: 'tomcat-catalina', version: '7.0.27'
compile group: 'org.apache.tomcat', name: 'tomcat-catalina', version: '8.5.31'
compile group: 'redis.clients', name: 'jedis', version: '2.5.2'
compile group: 'org.apache.commons', name: 'commons-pool2', version: '2.2'
//compile group: 'commons-codec', name: 'commons-codec', version: '1.9'

testCompile group: 'junit', name: 'junit', version: '4.+'
testCompile 'org.hamcrest:hamcrest-core:1.3'
Expand All @@ -27,73 +28,3 @@ dependencies {
testCompile group: 'org.apache.tomcat', name: 'tomcat-coyote', version: '7.0.27'
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from 'build/docs/javadoc'
}

task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}

artifacts {
archives jar

archives javadocJar
archives sourcesJar
}

signing {
sign configurations.archives
}

uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}
//repository(url: "https://oss.sonatype.org/content/repositories/snapshots") {
// authentication(userName: sonatypeUsername, password: sonatypePassword)
//}

pom.project {
name 'tomcat-redis-session-manager'
packaging 'jar'
description 'Tomcat Redis Session Manager is a Tomcat extension to store sessions in Redis'
url 'https://github.com/jcoleman/tomcat-redis-session-manager'

issueManagement {
url 'https://github.com:jcoleman/tomcat-redis-session-manager/issues'
system 'GitHub Issues'
}

scm {
url 'https://github.com:jcoleman/tomcat-redis-session-manager'
connection 'scm:git:git://github.com/jcoleman/tomcat-redis-session-manager.git'
developerConnection 'scm:git:[email protected]:jcoleman/tomcat-redis-session-manager.git'
}

licenses {
license {
name 'MIT'
url 'http://opensource.org/licenses/MIT'
distribution 'repo'
}
}

developers {
developer {
id 'jcoleman'
name 'James Coleman'
email '[email protected]'
url 'https://github.com/jcoleman'
}
}
}
}
}
}
4 changes: 4 additions & 0 deletions example-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ apply plugin: 'war'
version = '0.1'

repositories {
mavenLocal()
maven {
url "https://maven.aliyun.com/nexus/content/groups/public"
}
mavenCentral()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,81 +1,89 @@
package com.orangefunction.tomcat.redissessions;

import org.apache.catalina.util.CustomObjectInputStream;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;

import javax.servlet.http.HttpSession;

import java.util.Enumeration;
import java.util.HashMap;
import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Enumeration;
import java.util.HashMap;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;

/**
* <p>Title: Godfather1103's Github</p>
* <p>Copyright: Copyright (c) 2020</p>
* <p>Company: https://github.com/godfather1103</p>
*
* @author 作者: Jack Chu E-mail: [email protected]
* 创建时间:2020-07-01 17:20
* @version 1.0
* @since 1.0
*/
public class JavaSerializer implements Serializer {
private ClassLoader loader;
private ClassLoader loader;

private final Log log = LogFactory.getLog(JavaSerializer.class);
private final Log log = LogFactory.getLog(JavaSerializer.class);

@Override
public void setClassLoader(ClassLoader loader) {
this.loader = loader;
}

public byte[] attributesHashFrom(RedisSession session) throws IOException {
HashMap<String,Object> attributes = new HashMap<String,Object>();
for (Enumeration<String> enumerator = session.getAttributeNames(); enumerator.hasMoreElements();) {
String key = enumerator.nextElement();
attributes.put(key, session.getAttribute(key));
@Override
public void setClassLoader(ClassLoader loader) {
this.loader = loader;
}

byte[] serialized = null;
@Override
public byte[] attributesHashFrom(RedisSession session) throws IOException {
HashMap<String, Object> attributes = new HashMap<String, Object>();
for (Enumeration<String> enumerator = session.getAttributeNames(); enumerator.hasMoreElements(); ) {
String key = enumerator.nextElement();
attributes.put(key, session.getAttribute(key));
}

try (
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(bos));
) {
oos.writeUnshared(attributes);
oos.flush();
serialized = bos.toByteArray();
}
byte[] serialized = null;

MessageDigest digester = null;
try {
digester = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
log.error("Unable to get MessageDigest instance for MD5");
try (
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(bos));
) {
oos.writeUnshared(attributes);
oos.flush();
serialized = bos.toByteArray();
}

MessageDigest digester = null;
try {
digester = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
log.error("Unable to get MessageDigest instance for MD5");
}
return digester.digest(serialized);
}
return digester.digest(serialized);
}

@Override
public byte[] serializeFrom(RedisSession session, SessionSerializationMetadata metadata) throws IOException {
byte[] serialized = null;
@Override
public byte[] serializeFrom(RedisSession session, SessionSerializationMetadata metadata) throws IOException {
byte[] serialized = null;

try (
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(bos));
) {
oos.writeObject(metadata);
session.writeObjectData(oos);
oos.flush();
serialized = bos.toByteArray();
}
try (
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(bos));
) {
oos.writeObject(metadata);
session.writeObjectData(oos);
oos.flush();
serialized = bos.toByteArray();
}

return serialized;
}
return serialized;
}

@Override
public void deserializeInto(byte[] data, RedisSession session, SessionSerializationMetadata metadata) throws IOException, ClassNotFoundException {
try(
BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(data));
ObjectInputStream ois = new CustomObjectInputStream(bis, loader);
) {
SessionSerializationMetadata serializedMetadata = (SessionSerializationMetadata)ois.readObject();
metadata.copyFieldsFrom(serializedMetadata);
session.readObjectData(ois);
@Override
public void deserializeInto(byte[] data, RedisSession session, SessionSerializationMetadata metadata) throws IOException, ClassNotFoundException {
try (
BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(data));
ObjectInputStream ois = new CustomObjectInputStream(bis, loader);
) {
SessionSerializationMetadata serializedMetadata = (SessionSerializationMetadata) ois.readObject();
metadata.copyFieldsFrom(serializedMetadata);
session.readObjectData(ois);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.orangefunction.tomcat.redissessions;

import java.security.Principal;
import org.apache.catalina.Manager;
import org.apache.catalina.session.StandardSession;
import java.util.HashMap;
import java.io.IOException;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;

import java.io.IOException;
import java.security.Principal;
import java.util.HashMap;


public class RedisSession extends StandardSession {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.orangefunction.tomcat.redissessions;

import org.apache.catalina.Session;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.valves.ValveBase;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;

import javax.servlet.ServletException;
import java.io.IOException;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;


public class RedisSessionHandlerValve extends ValveBase {
private final Log log = LogFactory.getLog(RedisSessionManager.class);
Expand Down
Loading