Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
caopu16
whatsmars
提交
916692c1
W
whatsmars
项目概览
caopu16
/
whatsmars
与 Fork 源项目一致
Fork自
武汉红喜 / whatsmars
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
916692c1
编写于
1月 08, 2018
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
spring-boot session
上级
636bce5c
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
268 addition
and
0 deletion
+268
-0
whatsmars-spring-boot-samples/pom.xml
whatsmars-spring-boot-samples/pom.xml
+32
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/pom.xml
...spring-boot-samples/whatsmars-boot-sample-session/pom.xml
+110
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/java/org/hongxi/whatsmars/boot/sample/session/HelloRestController.java
...xi/whatsmars/boot/sample/session/HelloRestController.java
+16
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/java/org/hongxi/whatsmars/boot/sample/session/SampleSessionApplication.java
...atsmars/boot/sample/session/SampleSessionApplication.java
+13
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/resources/application.yml
...rs-boot-sample-session/src/main/resources/application.yml
+10
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/resources/hazelcast.xml
...mars-boot-sample-session/src/main/resources/hazelcast.xml
+20
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/test/java/org/hongxi/whatsmars/boot/sample/session/SampleSessionApplicationTests.java
...rs/boot/sample/session/SampleSessionApplicationTests.java
+67
-0
未找到文件。
whatsmars-spring-boot-samples/pom.xml
浏览文件 @
916692c1
...
...
@@ -15,8 +15,13 @@
<description>
Spring Boot Samples
</description>
<modules>
<module>
whatsmars-boot-sample-aop
</module>
<module>
whatsmars-boot-sample-session
</module>
</modules>
<properties>
<spring-boot.version>
2.0.0.M7
</spring-boot.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
...
...
@@ -38,5 +43,32 @@
</plugins>
</build>
<repositories>
<repository>
<id>
spring-repo
</id>
<name>
Spring Repo
</name>
<url>
http://repo.spring.io/milestone/
</url>
<releases>
<enabled>
true
</enabled>
</releases>
<snapshots>
<enabled>
false
</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>
spring-repo
</id>
<name>
Spring Repo
</name>
<url>
http://repo.spring.io/milestone/
</url>
<releases>
<enabled>
true
</enabled>
</releases>
<snapshots>
<enabled>
false
</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/pom.xml
0 → 100644
浏览文件 @
916692c1
<?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"
>
<parent>
<artifactId>
whatsmars-spring-boot-samples
</artifactId>
<groupId>
org.hongxi
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
whatsmars-boot-sample-session
</artifactId>
<name>
${project.artifactId}
</name>
<dependencies>
<!-- Compile -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-security
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<!-- Test -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>
redis
</id>
<!--<activation>-->
<!--<activeByDefault>true</activeByDefault>-->
<!--</activation>-->
<dependencies>
<dependency>
<groupId>
org.springframework.session
</groupId>
<artifactId>
spring-session-data-redis
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>
jdbc
</id>
<activation>
<activeByDefault>
true
</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>
org.springframework.session
</groupId>
<artifactId>
spring-session-jdbc
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-jdbc
</artifactId>
</dependency>
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>
hazelcast
</id>
<dependencies>
<dependency>
<groupId>
org.springframework.session
</groupId>
<artifactId>
spring-session-hazelcast
</artifactId>
</dependency>
<dependency>
<groupId>
com.hazelcast
</groupId>
<artifactId>
hazelcast
</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>
mongodb
</id>
<dependencies>
<dependency>
<groupId>
org.springframework.session
</groupId>
<artifactId>
spring-session-data-mongodb
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-mongodb
</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/java/org/hongxi/whatsmars/boot/sample/session/HelloRestController.java
0 → 100644
浏览文件 @
916692c1
package
org.hongxi.whatsmars.boot.sample.session
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
public
class
HelloRestController
{
@GetMapping
(
"/"
)
String
uid
(
HttpSession
session
)
{
return
session
.
getId
();
}
}
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/java/org/hongxi/whatsmars/boot/sample/session/SampleSessionApplication.java
0 → 100644
浏览文件 @
916692c1
package
org.hongxi.whatsmars.boot.sample.session
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
SampleSessionApplication
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SpringApplication
.
run
(
SampleSessionApplication
.
class
);
}
}
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/resources/application.yml
0 → 100644
浏览文件 @
916692c1
---
spring
:
security
:
user
:
password
:
password
name
:
user
management
:
endpoints
:
web
:
expose
:
*
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/main/resources/hazelcast.xml
0 → 100644
浏览文件 @
916692c1
<hazelcast
xsi:schemaLocation=
"http://www.hazelcast.com/schema/config hazelcast-config-3.9.xsd"
xmlns=
"http://www.hazelcast.com/schema/config"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
>
<map
name=
"spring:session:sessions"
>
<attributes>
<attribute
extractor=
"org.springframework.session.hazelcast.PrincipalNameExtractor"
>
principalName
</attribute>
</attributes>
<indexes>
<index>
principalName
</index>
</indexes>
</map>
<network>
<join>
<multicast
enabled=
"false"
/>
</join>
</network>
</hazelcast>
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-session/src/test/java/org/hongxi/whatsmars/boot/sample/session/SampleSessionApplicationTests.java
0 → 100644
浏览文件 @
916692c1
package
org.hongxi.whatsmars.boot.sample.session
;
import
java.net.URI
;
import
java.util.Base64
;
import
org.junit.Test
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.RequestEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestTemplate
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SampleSessionApplication}.
*
* @author Andy Wilkinson
* @author Vedran Pavic
*/
public
class
SampleSessionApplicationTests
{
@Test
public
void
sessionExpiry
()
throws
Exception
{
ConfigurableApplicationContext
context
=
createContext
();
String
port
=
context
.
getEnvironment
().
getProperty
(
"local.server.port"
);
URI
uri
=
URI
.
create
(
"http://localhost:"
+
port
+
"/"
);
RestTemplate
restTemplate
=
new
RestTemplate
();
ResponseEntity
<
String
>
firstResponse
=
firstRequest
(
restTemplate
,
uri
);
String
sessionId1
=
firstResponse
.
getBody
();
String
cookie
=
firstResponse
.
getHeaders
().
getFirst
(
"Set-Cookie"
);
String
sessionId2
=
nextRequest
(
restTemplate
,
uri
,
cookie
).
getBody
();
assertThat
(
sessionId1
).
isEqualTo
(
sessionId2
);
Thread
.
sleep
(
1000
);
String
loginPage
=
nextRequest
(
restTemplate
,
uri
,
cookie
).
getBody
();
assertThat
(
loginPage
).
containsIgnoringCase
(
"login"
);
}
private
ConfigurableApplicationContext
createContext
()
{
ConfigurableApplicationContext
context
=
new
SpringApplicationBuilder
()
.
sources
(
SampleSessionApplication
.
class
)
.
properties
(
"server.port:0"
,
"server.session.timeout:1"
)
.
initializers
(
new
ServerPortInfoApplicationContextInitializer
()).
run
();
return
context
;
}
private
ResponseEntity
<
String
>
firstRequest
(
RestTemplate
restTemplate
,
URI
uri
)
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
set
(
"Authorization"
,
"Basic "
+
Base64
.
getEncoder
().
encodeToString
(
"user:password"
.
getBytes
()));
RequestEntity
<
Object
>
request
=
new
RequestEntity
<>(
headers
,
HttpMethod
.
GET
,
uri
);
return
restTemplate
.
exchange
(
request
,
String
.
class
);
}
private
ResponseEntity
<
String
>
nextRequest
(
RestTemplate
restTemplate
,
URI
uri
,
String
cookie
)
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
set
(
"Cookie"
,
cookie
);
RequestEntity
<
Object
>
request
=
new
RequestEntity
<>(
headers
,
HttpMethod
.
GET
,
uri
);
return
restTemplate
.
exchange
(
request
,
String
.
class
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录