Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates Netty*Filter classes to use DefaultDataBuffer.
This avoids class cast exceptions when using MockServerHttpResponse. Fixes gh-1491 It may also work for Tomcat, Jetty and Undertow. See gh-145
- Loading branch information
1 parent
fb465e2
commit 85193a0
Showing
3 changed files
with
107 additions
and
10 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
67 changes: 67 additions & 0 deletions
67
...-core/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterTests.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,67 @@ | ||
/* | ||
* Copyright 2013-2020 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* https://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 org.springframework.cloud.gateway.filter; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringBootConfiguration; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.cloud.gateway.route.RouteLocator; | ||
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; | ||
import org.springframework.cloud.gateway.test.PermitAllSecurityConfiguration; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class NettyRoutingFilterTests { | ||
|
||
@Autowired | ||
private ApplicationContext context; | ||
|
||
@Test | ||
public void mockServerWorks() { | ||
WebTestClient client = WebTestClient.bindToApplicationContext(this.context) | ||
.build(); | ||
client.get().uri("/mockexample").exchange().expectStatus() | ||
.value(Matchers.lessThan(500)); | ||
} | ||
|
||
@SpringBootConfiguration | ||
@EnableAutoConfiguration | ||
@Import(PermitAllSecurityConfiguration.class) | ||
public static class TestConfig { | ||
|
||
@Bean | ||
public RouteLocator routes(RouteLocatorBuilder builder) { | ||
return builder.routes() | ||
.route(p -> p.path("/mockexample") | ||
.filters(f -> f.prefixPath("/httpbin")) | ||
.uri("http://example.com")) | ||
.build(); | ||
} | ||
|
||
} | ||
|
||
} |