forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#1440 from mkouba/issue-703-session-context
Basic custom CDI contexts support and HttpSessionContext
- Loading branch information
Showing
47 changed files
with
1,159 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ons/arc/deployment/src/main/java/io/quarkus/arc/deployment/ContextRegistrarBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2019 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.quarkus.arc.deployment; | ||
|
||
import org.jboss.builder.item.MultiBuildItem; | ||
|
||
import io.quarkus.arc.processor.BeanRegistrar; | ||
import io.quarkus.arc.processor.ContextRegistrar; | ||
|
||
public final class ContextRegistrarBuildItem extends MultiBuildItem { | ||
|
||
private final ContextRegistrar contextRegistrar; | ||
|
||
public ContextRegistrarBuildItem(ContextRegistrar contextRegistrar) { | ||
this.contextRegistrar = contextRegistrar; | ||
} | ||
|
||
public ContextRegistrar getContextRegistrar() { | ||
return contextRegistrar; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...s/undertow/deployment/src/main/java/io/quarkus/undertow/deployment/ListenerBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2019 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.quarkus.undertow.deployment; | ||
|
||
import org.jboss.builder.item.MultiBuildItem; | ||
|
||
public final class ListenerBuildItem extends MultiBuildItem { | ||
|
||
private final String listenerClass; | ||
|
||
public ListenerBuildItem(String listenerClass) { | ||
this.listenerClass = listenerClass; | ||
} | ||
|
||
public String getListenerClass() { | ||
return listenerClass; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...nsions/undertow/deployment/src/test/java/io/quarkus/undertow/test/sessioncontext/Foo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkus.undertow.test.sessioncontext; | ||
|
||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.SessionScoped; | ||
|
||
@SessionScoped | ||
class Foo { | ||
|
||
AtomicLong counter; | ||
|
||
@PostConstruct | ||
void init() { | ||
counter = new AtomicLong(); | ||
} | ||
|
||
long incrementAndGet() { | ||
return counter.incrementAndGet(); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...loyment/src/test/java/io/quarkus/undertow/test/sessioncontext/SessionContextTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2018 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.quarkus.undertow.test.sessioncontext; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static io.restassured.RestAssured.when; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.response.Response; | ||
|
||
public class SessionContextTestCase { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(TestServlet.class, Foo.class)); | ||
|
||
@Test | ||
public void testServlet() { | ||
Response response = when().get("/foo"); | ||
String sessionId = response.sessionId(); | ||
response.then().statusCode(200).body(is("count=1")); | ||
given().sessionId(sessionId).when().get("/foo").then().statusCode(200).body(is("count=2")); | ||
// Destroy session | ||
when().get("/foo?destroy=true").then().statusCode(200); | ||
response = when().get("/foo"); | ||
assertNotEquals(sessionId, response.sessionId()); | ||
response.then().statusCode(200).body(is("count=1")); | ||
} | ||
|
||
} |
Oops, something went wrong.