-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add secret property to set the servlet container to sync mode
- Loading branch information
Showing
6 changed files
with
267 additions
and
3 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
79 changes: 79 additions & 0 deletions
79
http-server-jetty/src/test/groovy/io/micronaut/servlet/jetty/JettyResponseEncoderSpec.groovy
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,79 @@ | ||
package io.micronaut.servlet.jetty | ||
|
||
import groovy.transform.Canonical | ||
import io.micronaut.context.annotation.Property | ||
import io.micronaut.context.annotation.Requires | ||
import io.micronaut.core.annotation.AnnotationMetadata | ||
import io.micronaut.core.annotation.Introspected | ||
import io.micronaut.core.annotation.NonNull | ||
import io.micronaut.http.MutableHttpResponse | ||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import io.micronaut.http.client.HttpClient | ||
import io.micronaut.http.client.annotation.Client | ||
import io.micronaut.servlet.http.ServletExchange | ||
import io.micronaut.servlet.http.ServletHttpResponse | ||
import io.micronaut.servlet.http.ServletResponseEncoder | ||
import io.micronaut.test.extensions.spock.annotation.MicronautTest | ||
import jakarta.inject.Inject | ||
import jakarta.inject.Singleton | ||
import org.reactivestreams.Publisher | ||
import reactor.core.publisher.Flux | ||
import spock.lang.Specification | ||
|
||
@MicronautTest | ||
@Property(name = "spec.name", value = SPEC_NAME) | ||
@Property(name = "micronaut.server.testing.async", value = "false") | ||
class JettyResponseEncoderSpec extends Specification { | ||
|
||
private static final String SPEC_NAME = "JettyResponseEncoderSpec" | ||
|
||
@Inject | ||
@Client("/") | ||
HttpClient client | ||
|
||
void "custom encoder applied once"() { | ||
when: | ||
def response = client.toBlocking().exchange("/test", String) | ||
|
||
then: | ||
response.body() == "SRE{bar}" | ||
} | ||
|
||
@Requires(property = "spec.name", value = SPEC_NAME) | ||
@Controller | ||
static class TestController { | ||
|
||
@Get("/test") | ||
SomeResponseType test() { | ||
new SomeResponseType(foo: "bar") | ||
} | ||
} | ||
|
||
@Canonical | ||
@Introspected | ||
static class SomeResponseType { | ||
String foo | ||
|
||
@Override | ||
String toString() { | ||
"NOPE!" | ||
} | ||
} | ||
|
||
@Requires(property = "spec.name", value = SPEC_NAME) | ||
@Singleton | ||
static class SomeResponseEncoder implements ServletResponseEncoder<SomeResponseType> { | ||
@Override | ||
Class<SomeResponseType> getResponseType() { | ||
return SomeResponseType.class | ||
} | ||
|
||
@Override | ||
Publisher<MutableHttpResponse<?>> encode(@NonNull ServletExchange<?, ?> exchange, AnnotationMetadata annotationMetadata, @NonNull SomeResponseType value) { | ||
ServletHttpResponse<?, ?> response = exchange.getResponse().contentType("text/plain") | ||
response.getOutputStream() << "SRE{$value.foo}" | ||
Flux.just(response) | ||
} | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
...erver-tomcat/src/test/groovy/io/micronaut/servlet/tomcat/TomcatResponseEncoderSpec.groovy
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,79 @@ | ||
package io.micronaut.servlet.tomcat | ||
|
||
import groovy.transform.Canonical | ||
import io.micronaut.context.annotation.Property | ||
import io.micronaut.context.annotation.Requires | ||
import io.micronaut.core.annotation.AnnotationMetadata | ||
import io.micronaut.core.annotation.Introspected | ||
import io.micronaut.core.annotation.NonNull | ||
import io.micronaut.http.MutableHttpResponse | ||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import io.micronaut.http.client.HttpClient | ||
import io.micronaut.http.client.annotation.Client | ||
import io.micronaut.servlet.http.ServletExchange | ||
import io.micronaut.servlet.http.ServletHttpResponse | ||
import io.micronaut.servlet.http.ServletResponseEncoder | ||
import io.micronaut.test.extensions.spock.annotation.MicronautTest | ||
import jakarta.inject.Inject | ||
import jakarta.inject.Singleton | ||
import org.reactivestreams.Publisher | ||
import reactor.core.publisher.Flux | ||
import spock.lang.Specification | ||
|
||
@MicronautTest | ||
@Property(name = "spec.name", value = SPEC_NAME) | ||
@Property(name = "micronaut.server.testing.async", value = "false") | ||
class TomcatResponseEncoderSpec extends Specification { | ||
|
||
private static final String SPEC_NAME = "JettyResponseEncoderSpec" | ||
|
||
@Inject | ||
@Client("/") | ||
HttpClient client | ||
|
||
void "custom encoder applied once"() { | ||
when: | ||
def response = client.toBlocking().exchange("/test", String) | ||
|
||
then: | ||
response.body() == "SRE{bar}" | ||
} | ||
|
||
@Requires(property = "spec.name", value = SPEC_NAME) | ||
@Controller | ||
static class TestController { | ||
|
||
@Get("/test") | ||
SomeResponseType test() { | ||
new SomeResponseType(foo: "bar") | ||
} | ||
} | ||
|
||
@Canonical | ||
@Introspected | ||
static class SomeResponseType { | ||
String foo | ||
|
||
@Override | ||
String toString() { | ||
"NOPE!" | ||
} | ||
} | ||
|
||
@Requires(property = "spec.name", value = SPEC_NAME) | ||
@Singleton | ||
static class SomeResponseEncoder implements ServletResponseEncoder<SomeResponseType> { | ||
@Override | ||
Class<SomeResponseType> getResponseType() { | ||
return SomeResponseType.class | ||
} | ||
|
||
@Override | ||
Publisher<MutableHttpResponse<?>> encode(@NonNull ServletExchange<?, ?> exchange, AnnotationMetadata annotationMetadata, @NonNull SomeResponseType value) { | ||
ServletHttpResponse<?, ?> response = exchange.getResponse().contentType("text/plain") | ||
response.getOutputStream() << "SRE{$value.foo}" | ||
Flux.just(response) | ||
} | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
...undertow/src/test/groovy/io/micronaut/servlet/undertow/UndertowResponseEncoderSpec.groovy
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,79 @@ | ||
package io.micronaut.servlet.undertow | ||
|
||
import groovy.transform.Canonical | ||
import io.micronaut.context.annotation.Property | ||
import io.micronaut.context.annotation.Requires | ||
import io.micronaut.core.annotation.AnnotationMetadata | ||
import io.micronaut.core.annotation.Introspected | ||
import io.micronaut.core.annotation.NonNull | ||
import io.micronaut.http.MutableHttpResponse | ||
import io.micronaut.http.annotation.Controller | ||
import io.micronaut.http.annotation.Get | ||
import io.micronaut.http.client.HttpClient | ||
import io.micronaut.http.client.annotation.Client | ||
import io.micronaut.servlet.http.ServletExchange | ||
import io.micronaut.servlet.http.ServletHttpResponse | ||
import io.micronaut.servlet.http.ServletResponseEncoder | ||
import io.micronaut.test.extensions.spock.annotation.MicronautTest | ||
import jakarta.inject.Inject | ||
import jakarta.inject.Singleton | ||
import org.reactivestreams.Publisher | ||
import reactor.core.publisher.Flux | ||
import spock.lang.Specification | ||
|
||
@MicronautTest | ||
@Property(name = "spec.name", value = SPEC_NAME) | ||
@Property(name = "micronaut.server.testing.async", value = "false") | ||
class UndertowResponseEncoderSpec extends Specification { | ||
|
||
private static final String SPEC_NAME = "JettyResponseEncoderSpec" | ||
|
||
@Inject | ||
@Client("/") | ||
HttpClient client | ||
|
||
void "custom encoder applied once"() { | ||
when: | ||
def response = client.toBlocking().exchange("/test", String) | ||
|
||
then: | ||
response.body() == "SRE{bar}" | ||
} | ||
|
||
@Requires(property = "spec.name", value = SPEC_NAME) | ||
@Controller | ||
static class TestController { | ||
|
||
@Get("/test") | ||
SomeResponseType test() { | ||
new SomeResponseType(foo: "bar") | ||
} | ||
} | ||
|
||
@Canonical | ||
@Introspected | ||
static class SomeResponseType { | ||
String foo | ||
|
||
@Override | ||
String toString() { | ||
"NOPE!" | ||
} | ||
} | ||
|
||
@Requires(property = "spec.name", value = SPEC_NAME) | ||
@Singleton | ||
static class SomeResponseEncoder implements ServletResponseEncoder<SomeResponseType> { | ||
@Override | ||
Class<SomeResponseType> getResponseType() { | ||
return SomeResponseType.class | ||
} | ||
|
||
@Override | ||
Publisher<MutableHttpResponse<?>> encode(@NonNull ServletExchange<?, ?> exchange, AnnotationMetadata annotationMetadata, @NonNull SomeResponseType value) { | ||
ServletHttpResponse<?, ?> response = exchange.getResponse().contentType("text/plain") | ||
response.getOutputStream() << "SRE{$value.foo}" | ||
Flux.just(response) | ||
} | ||
} | ||
} |