Giter Club home page Giter Club logo

spring-session-data-couchbase's Introduction

Spring Session Couchbase

Spring Session Couchbase provides a solution for Spring Session in a Couchbase data store.

  • Accessing a session from any environment (i.e. web, messaging infrastructure, etc)

  • In a web environment

    • Support for clustering in a vendor neutral way

    • Pluggable strategy for determining the session id

    • Easily keep the HttpSession alive when a WebSocket is active

Import Spring Session Couchbase

Simply add to your pom.xml the following dependency pom.xml

<dependency>
	<groupId>io.github.couchbaselabs</groupId>
	<artifactId>spring-session-data-couchbase</artifactId>
	<version>1.1</version>
</dependency>

Spring Configuration

After adding the required dependencies, we can create our Spring configuration. The Spring configuration is responsible for creating a Servlet Filter that replaces the HttpSession implementation with an implementation backed by Spring Session.

All you have to do is to add the following Spring Configuration:

@SpringBootApplication
@EnableCouchbaseHttpSession
public class MyApplication {

	public static void main(String[] args) {
		SpringApplication.run(MyApplication.class, args);
	}

}
  1. The @EnableCouchbaseHttpSession annotation creates a Spring Bean with the name of springSessionRepositoryFilter that implements Filter. The filter is what is in charge of replacing the HttpSession implementation to be backed by Spring Session. In this instance Spring Session is backed by Couchbase.

The @EnableCouchbaseHttpSession has 4 properties:

  • maxInactiveIntervalInSeconds (default 1800 seconds) - How long the session will live before expiring

  • typeName (default "_type" ) - The name of the attribute that is going to be used as the type of the document

  • typeValue (default "sessions" ) - The value of the type attribute that is going to be used to differentiate this document from others.

  • keepStringAsLiteral (default false) - Any attribute in the session which is a String will be saved as a document attribute instead of being serialized in a binary format. This is really useful if you need to query the user’s session via N1QL (Ex: create a dashboard of what users have in their sessions). Check out this example to see it working

Configuring the Couchbase Connection

Spring Boot automatically creates a Couchbase connection and connects Spring Session to a Couchbase Server. You can configure this connection by defining a @Configuration class which extends org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration or via application.properties :

src/main/resources/application.properties
spring.couchbase.bootstrap-hosts=localhost
spring.couchbase.bucket.name=sessionstore
spring.couchbase.bucket.password=password

Servlet Container Initialization

Our Spring Configuration created a Spring Bean named springSessionRepositoryFilter that implements Filter. The springSessionRepositoryFilter bean is responsible for replacing the HttpSession with a custom implementation that is backed by Spring Session.

In order for our Filter to do its magic, Spring needs to load our Config class. Last we need to ensure that our Servlet Container (i.e. Tomcat) uses our springSessionRepositoryFilter for every request. Fortunately, Spring Boot takes care of both of these steps for us.

Couchbase Sample Application

The https://github.com/couchbaselabs/session-store-java repo contains a fully functional example, please check the documentation in the sample to find out how to run it.

Spring Session Project Site

You can find the documentation, issue management, support, samples, and guides for using Spring Session Couchbase at http://projects.spring.io/spring-session-data-couchbase/

License

Spring Session is Open Source software released under the Apache 2.0 license.

Support

This is a community project mainly supported by me. If you have any questions feel free to ping me at @deniswsrosa

spring-session-data-couchbase's People

Contributors

deniswsrosa avatar

Stargazers

Jesse Yang avatar deadman avatar Mehul Bhatt avatar Jon Repp avatar  avatar  avatar

Watchers

Steve Yen avatar Thuan Nguyen avatar Sarath Lakshman avatar  avatar Jeffry Morris avatar James Cloos avatar Brett Lawson avatar  avatar Wayne Siu avatar Sundar Sridharan avatar  avatar  avatar Dan Owen avatar Dave Finlay avatar  avatar  avatar  avatar Adam Fraser avatar  avatar Keshav Murthy avatar Laura Czajkowski avatar  avatar

spring-session-data-couchbase's Issues

Unable to retrieve maven artifact

Create an empty maven project with a dependency on this project:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>test</groupId>
  <artifactId>test</artifactId>
  <version>1.0-SNAPSHOT</version>


  <dependencies>
    <!-- https://mvnrepository.com/artifact/io.github.couchbaselabs/spring-session-data-couchbase -->
    <dependency>
      <groupId>io.github.couchbaselabs</groupId>
      <artifactId>spring-session-data-couchbase</artifactId>
      <version>1.1</version>
    </dependency>

  </dependencies>


</project>

When you try to build the project with mvn install, you get the following error:

test3$ mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------------< test:test >------------------------------
[INFO] Building test 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.184 s
[INFO] Finished at: 2019-08-27T09:25:11-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project test: Could not resolve dependencies for project test:test:jar:1.0-SNAPSHOT: Failed to collect dependencies at io.github.couchbaselabs:spring-session-data-couchbase:jar:1.1: Failed to read artifact descriptor for io.github.couchbaselabs:spring-session-data-couchbase:jar:1.1: Failure to find org.springframework:spring-framework-bom:pom:5.2.0.BUILD-SNAPSHOT in https://oss.sonatype.org/content/repositories/snapshots was cached in the local repository, resolution will not be reattempted until the update interval of sonatype-nexus-snapshots has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

Issue in dependency

Hi,
I am trying to use this library in my application, but getting following error while trying to build it.

Also tried to build and run https://github.com/couchbaselabs/session-store-java, but getting same error.

Caused by: org.eclipse.aether.collection.DependencyCollectionException: Failed to collect dependencies at io.github.couchbaselabs:spring-session-data-couchbase:jar:1.1
	at org.eclipse.aether.internal.impl.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:293)
	at org.eclipse.aether.internal.impl.DefaultRepositorySystem.collectDependencies(DefaultRepositorySystem.java:282)
	at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:169)
	... 24 more
Caused by: org.eclipse.aether.resolution.ArtifactDescriptorException: Failed to read artifact descriptor for io.github.couchbaselabs:spring-session-data-couchbase:jar:1.1
	at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:323)
	at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:192)
	at org.eclipse.aether.internal.impl.DefaultDependencyCollector.resolveCachedArtifactDescriptor(DefaultDependencyCollector.java:539)
	at org.eclipse.aether.internal.impl.DefaultDependencyCollector.getArtifactDescriptorResult(DefaultDependencyCollector.java:522)
	at org.eclipse.aether.internal.impl.DefaultDependencyCollector.processDependency(DefaultDependencyCollector.java:411)
	at org.eclipse.aether.internal.impl.DefaultDependencyCollector.processDependency(DefaultDependencyCollector.java:365)
	at org.eclipse.aether.internal.impl.DefaultDependencyCollector.process(DefaultDependencyCollector.java:353)
	at org.eclipse.aether.internal.impl.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:256)
	... 26 more
Caused by: org.apache.maven.model.resolution.UnresolvableModelException: Could not find artifact org.springframework:spring-framework-bom:pom:5.2.0.BUILD-SNAPSHOT in sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots)
	at org.apache.maven.repository.internal.DefaultModelResolver.resolveModel(DefaultModelResolver.java:178)
	at org.apache.maven.model.building.DefaultModelBuilder.importDependencyManagement(DefaultModelBuilder.java:1247)
	at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:458)
	at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:424)
	at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:414)
	at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:314)
	... 33 more
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not find artifact org.springframework:spring-framework-bom:pom:5.2.0.BUILD-SNAPSHOT in sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots)
	at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:422)
	at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:224)
	at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:201)
	at org.apache.maven.repository.internal.DefaultModelResolver.resolveModel(DefaultModelResolver.java:174)

Doesn't replace the default in memory session store

I created a hello world project with azure ad for oauth and connfigured spring-session-data-couchbase as couchbase session store by following the tutorial.

It was able to store the sessions in the couchbase bucket however, when I deleted the sessions from couchbase admin console manually and refreshed the application, the sessions reappeared in couchbase.

It seems like the default in memory session store is still in the filter chain and somewhere along the line it is resetting the cookie and session from wherever it is storing, and then later on in the chain the couchbase filter is picking it up and thinking it is a new session.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.