Reactive Spring does not support ServerHttpRequest as parameter in REST endpoint tests?
The question is very similar to this one. Except the fact that I use:
org.springframework.http.server.ServerHttpRequest
not HttpServletRequest.- The exception is got in test code. Real calls works.
Code:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SecurityTests.SecurityTestsApplication.class)
@TestPropertySource(properties = {""})
@AutoConfigureWebTestClient
public class SecurityTests {
@Test
public void myTest() {
//send request to myUrl and got 500
}
}
@RestController
@RequestMapping("/myPath")
public class MyController {
@PostMapping
public Mono<Void> myMethod(ServerHttpRequest request) {
return Mono.empty()
}
}
Exception is:
java.lang.IllegalStateException: Failed to resolve argument 1 of type 'org.springframework.http.server.ServerHttpRequest' on public reactor.core.publisher.Mono<java.lang.Void> MyController$MockitoMock$606550817.myMethod(org.springframework.http.server.ServerHttpRequest)
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.getArgumentError(InvocableHandlerMethod.java:228) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArg(InvocableHandlerMethod.java:223) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$null$1(InvocableHandlerMethod.java:179) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at java.util.Optional.orElseGet(Optional.java:267) ~[na:1.8.0_131]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$resolveArguments$2(InvocableHandlerMethod.java:177) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_131]
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_131]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_131]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_131]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_131]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_131]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_131]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArguments(InvocableHandlerMethod.java:183) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
...
Caused by: java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.http.server.ServerHttpRequest
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.createAttribute(ModelAttributeMethodArgumentResolver.java:213) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.prepareAttributeMono(ModelAttributeMethodArgumentResolver.java:163) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.resolveArgument(ModelAttributeMethodArgumentResolver.java:117) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArg(InvocableHandlerMethod.java:214) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 227 common frames omitted
Caused by: java.lang.NoSuchMethodException: org.springframework.http.server.ServerHttpRequest.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_131]
at java.lang.Class.getDeclaredConstructor(Class.java:2178) ~[na:1.8.0_131]
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.createAttribute(ModelAttributeMethodArgumentResolver.java:210) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 230 common frames omitted
java spring spring-webflux project-reactor
add a comment |
The question is very similar to this one. Except the fact that I use:
org.springframework.http.server.ServerHttpRequest
not HttpServletRequest.- The exception is got in test code. Real calls works.
Code:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SecurityTests.SecurityTestsApplication.class)
@TestPropertySource(properties = {""})
@AutoConfigureWebTestClient
public class SecurityTests {
@Test
public void myTest() {
//send request to myUrl and got 500
}
}
@RestController
@RequestMapping("/myPath")
public class MyController {
@PostMapping
public Mono<Void> myMethod(ServerHttpRequest request) {
return Mono.empty()
}
}
Exception is:
java.lang.IllegalStateException: Failed to resolve argument 1 of type 'org.springframework.http.server.ServerHttpRequest' on public reactor.core.publisher.Mono<java.lang.Void> MyController$MockitoMock$606550817.myMethod(org.springframework.http.server.ServerHttpRequest)
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.getArgumentError(InvocableHandlerMethod.java:228) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArg(InvocableHandlerMethod.java:223) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$null$1(InvocableHandlerMethod.java:179) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at java.util.Optional.orElseGet(Optional.java:267) ~[na:1.8.0_131]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$resolveArguments$2(InvocableHandlerMethod.java:177) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_131]
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_131]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_131]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_131]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_131]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_131]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_131]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArguments(InvocableHandlerMethod.java:183) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
...
Caused by: java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.http.server.ServerHttpRequest
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.createAttribute(ModelAttributeMethodArgumentResolver.java:213) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.prepareAttributeMono(ModelAttributeMethodArgumentResolver.java:163) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.resolveArgument(ModelAttributeMethodArgumentResolver.java:117) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArg(InvocableHandlerMethod.java:214) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 227 common frames omitted
Caused by: java.lang.NoSuchMethodException: org.springframework.http.server.ServerHttpRequest.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_131]
at java.lang.Class.getDeclaredConstructor(Class.java:2178) ~[na:1.8.0_131]
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.createAttribute(ModelAttributeMethodArgumentResolver.java:210) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 230 common frames omitted
java spring spring-webflux project-reactor
add a comment |
The question is very similar to this one. Except the fact that I use:
org.springframework.http.server.ServerHttpRequest
not HttpServletRequest.- The exception is got in test code. Real calls works.
Code:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SecurityTests.SecurityTestsApplication.class)
@TestPropertySource(properties = {""})
@AutoConfigureWebTestClient
public class SecurityTests {
@Test
public void myTest() {
//send request to myUrl and got 500
}
}
@RestController
@RequestMapping("/myPath")
public class MyController {
@PostMapping
public Mono<Void> myMethod(ServerHttpRequest request) {
return Mono.empty()
}
}
Exception is:
java.lang.IllegalStateException: Failed to resolve argument 1 of type 'org.springframework.http.server.ServerHttpRequest' on public reactor.core.publisher.Mono<java.lang.Void> MyController$MockitoMock$606550817.myMethod(org.springframework.http.server.ServerHttpRequest)
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.getArgumentError(InvocableHandlerMethod.java:228) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArg(InvocableHandlerMethod.java:223) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$null$1(InvocableHandlerMethod.java:179) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at java.util.Optional.orElseGet(Optional.java:267) ~[na:1.8.0_131]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$resolveArguments$2(InvocableHandlerMethod.java:177) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_131]
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_131]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_131]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_131]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_131]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_131]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_131]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArguments(InvocableHandlerMethod.java:183) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
...
Caused by: java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.http.server.ServerHttpRequest
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.createAttribute(ModelAttributeMethodArgumentResolver.java:213) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.prepareAttributeMono(ModelAttributeMethodArgumentResolver.java:163) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.resolveArgument(ModelAttributeMethodArgumentResolver.java:117) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArg(InvocableHandlerMethod.java:214) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 227 common frames omitted
Caused by: java.lang.NoSuchMethodException: org.springframework.http.server.ServerHttpRequest.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_131]
at java.lang.Class.getDeclaredConstructor(Class.java:2178) ~[na:1.8.0_131]
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.createAttribute(ModelAttributeMethodArgumentResolver.java:210) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 230 common frames omitted
java spring spring-webflux project-reactor
The question is very similar to this one. Except the fact that I use:
org.springframework.http.server.ServerHttpRequest
not HttpServletRequest.- The exception is got in test code. Real calls works.
Code:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SecurityTests.SecurityTestsApplication.class)
@TestPropertySource(properties = {""})
@AutoConfigureWebTestClient
public class SecurityTests {
@Test
public void myTest() {
//send request to myUrl and got 500
}
}
@RestController
@RequestMapping("/myPath")
public class MyController {
@PostMapping
public Mono<Void> myMethod(ServerHttpRequest request) {
return Mono.empty()
}
}
Exception is:
java.lang.IllegalStateException: Failed to resolve argument 1 of type 'org.springframework.http.server.ServerHttpRequest' on public reactor.core.publisher.Mono<java.lang.Void> MyController$MockitoMock$606550817.myMethod(org.springframework.http.server.ServerHttpRequest)
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.getArgumentError(InvocableHandlerMethod.java:228) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArg(InvocableHandlerMethod.java:223) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$null$1(InvocableHandlerMethod.java:179) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at java.util.Optional.orElseGet(Optional.java:267) ~[na:1.8.0_131]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$resolveArguments$2(InvocableHandlerMethod.java:177) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_131]
at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_131]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_131]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_131]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_131]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_131]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_131]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArguments(InvocableHandlerMethod.java:183) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
...
Caused by: java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.http.server.ServerHttpRequest
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.createAttribute(ModelAttributeMethodArgumentResolver.java:213) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.prepareAttributeMono(ModelAttributeMethodArgumentResolver.java:163) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.resolveArgument(ModelAttributeMethodArgumentResolver.java:117) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.resolveArg(InvocableHandlerMethod.java:214) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 227 common frames omitted
Caused by: java.lang.NoSuchMethodException: org.springframework.http.server.ServerHttpRequest.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_131]
at java.lang.Class.getDeclaredConstructor(Class.java:2178) ~[na:1.8.0_131]
at org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.createAttribute(ModelAttributeMethodArgumentResolver.java:210) ~[spring-webflux-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 230 common frames omitted
java spring spring-webflux project-reactor
java spring spring-webflux project-reactor
asked Nov 20 '18 at 18:12
CherryCherry
9,3582496174
9,3582496174
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You've imported the wrong class:
org.springframework.http.server.ServerHttpRequest
is for Spring MVC
org.springframework.http.server.reactive.ServerHttpRequest
is for Spring WebFlux
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399058%2freactive-spring-does-not-support-serverhttprequest-as-parameter-in-rest-endpoint%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You've imported the wrong class:
org.springframework.http.server.ServerHttpRequest
is for Spring MVC
org.springframework.http.server.reactive.ServerHttpRequest
is for Spring WebFlux
add a comment |
You've imported the wrong class:
org.springframework.http.server.ServerHttpRequest
is for Spring MVC
org.springframework.http.server.reactive.ServerHttpRequest
is for Spring WebFlux
add a comment |
You've imported the wrong class:
org.springframework.http.server.ServerHttpRequest
is for Spring MVC
org.springframework.http.server.reactive.ServerHttpRequest
is for Spring WebFlux
You've imported the wrong class:
org.springframework.http.server.ServerHttpRequest
is for Spring MVC
org.springframework.http.server.reactive.ServerHttpRequest
is for Spring WebFlux
answered Nov 20 '18 at 20:36
Brian ClozelBrian Clozel
31.6k676102
31.6k676102
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399058%2freactive-spring-does-not-support-serverhttprequest-as-parameter-in-rest-endpoint%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown