Browse Source

Merge branch '2.2.x'

pull/1688/head
Spencer Gibb 5 years ago
parent
commit
5f4317da42
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 4
      spring-cloud-gateway-mvc/src/main/java/org/springframework/cloud/gateway/mvc/ProxyExchange.java
  2. 50
      spring-cloud-gateway-mvc/src/test/java/org/springframework/cloud/gateway/mvc/ProductionConfigurationTests.java

4
spring-cloud-gateway-mvc/src/main/java/org/springframework/cloud/gateway/mvc/ProxyExchange.java

@ -322,8 +322,8 @@ public class ProxyExchange<T> { @@ -322,8 +322,8 @@ public class ProxyExchange<T> {
}
public ResponseEntity<T> delete() {
RequestEntity<Void> requestEntity = headers(
(BodyBuilder) RequestEntity.delete(uri)).build();
RequestEntity<Object> requestEntity = headers(
(BodyBuilder) RequestEntity.delete(uri)).body(body());
return exchange(requestEntity);
}

50
spring-cloud-gateway-mvc/src/test/java/org/springframework/cloud/gateway/mvc/ProductionConfigurationTests.java

@ -37,13 +37,16 @@ import org.springframework.cloud.gateway.mvc.ProductionConfigurationTests.TestAp @@ -37,13 +37,16 @@ import org.springframework.cloud.gateway.mvc.ProductionConfigurationTests.TestAp
import org.springframework.cloud.gateway.mvc.ProductionConfigurationTests.TestApplication.Bar;
import org.springframework.cloud.gateway.mvc.ProductionConfigurationTests.TestApplication.Foo;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@ -245,6 +248,27 @@ public class ProductionConfigurationTests { @@ -245,6 +248,27 @@ public class ProductionConfigurationTests {
assertThat(foo.getName()).isEqualTo("hello");
}
@Test
public void deleteWithoutBody() throws Exception {
ResponseEntity<Void> deleteResponse = rest.exchange("/proxy/{id}/no-body",
HttpMethod.DELETE, null, Void.TYPE,
Collections.singletonMap("id", "123"));
assertThat(deleteResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@Test
public void deleteWithBody() throws Exception {
Foo foo = new Foo("to-be-deleted");
ParameterizedTypeReference<Map<String, Foo>> returnType = new ParameterizedTypeReference<Map<String, Foo>>() {
};
ResponseEntity<Map<String, Foo>> deleteResponse = rest.exchange("/proxy/{id}",
HttpMethod.DELETE, new HttpEntity<Foo>(foo), returnType,
Collections.singletonMap("id", "123"));
assertThat(deleteResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(deleteResponse.getBody().get("deleted"))
.isEqualToComparingFieldByField(foo);
}
@Test
@SuppressWarnings({ "Duplicates", "unchecked" })
public void headers() throws Exception {
@ -386,6 +410,21 @@ public class ProductionConfigurationTests { @@ -386,6 +410,21 @@ public class ProductionConfigurationTests {
return proxy.uri(home.toString() + "/foos").post();
}
@DeleteMapping("/proxy/{id}/no-body")
public ResponseEntity<?> deleteWithoutBody(@PathVariable Integer id,
ProxyExchange<?> proxy) throws Exception {
return proxy.uri(home.toString() + "/foos/" + id + "/no-body").delete();
}
@DeleteMapping("/proxy/{id}")
public ResponseEntity<?> deleteWithBody(@PathVariable Integer id,
@RequestBody Foo foo, ProxyExchange<?> proxy) throws Exception {
return proxy.uri(home.toString() + "/foos/" + id).body(foo)
.delete(response -> ResponseEntity
.status(response.getStatusCode())
.headers(response.getHeaders()).body(response.getBody()));
}
@GetMapping("/forward/**")
public void forward(ProxyExchange<?> proxy) throws Exception {
String path = proxy.path("/forward");
@ -459,6 +498,17 @@ public class ProductionConfigurationTests { @@ -459,6 +498,17 @@ public class ProductionConfigurationTests {
return new Foo(id == 1 ? "foo" : custom != null ? custom : "bye");
}
@DeleteMapping("/foos/{id}/no-body")
public ResponseEntity<?> deleteFoo(@PathVariable Integer id) {
return ResponseEntity.ok().build();
}
@DeleteMapping("/foos/{id}")
public ResponseEntity<?> deleteFoo(@PathVariable Integer id,
@RequestBody Foo foo) {
return ResponseEntity.ok().body(Collections.singletonMap("deleted", foo));
}
@PostMapping("/bars")
public List<Bar> bars(@RequestBody List<Foo> foos,
@RequestHeader HttpHeaders headers) {

Loading…
Cancel
Save