Compare commits

...
9 changed files with 74 additions and 25 deletions
+1
View File
@@ -245,6 +245,7 @@ $ touch .springformat
==== Intellij IDEA
In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin.
The following files can be found in the https://github.com/spring-cloud/spring-cloud-build/tree/master/spring-cloud-build-tools[Spring Cloud Build] project.
.spring-cloud-build-tools/
----
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign</artifactId>
<version>2.1.2.RELEASE</version>
<version>2.1.3.RELEASE</version>
</parent>
<artifactId>spring-cloud-openfeign-docs</artifactId>
<packaging>pom</packaging>
+1
View File
@@ -0,0 +1 @@
spring-cloud-openfeign.adoc
+4 -4
View File
@@ -4,14 +4,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-openfeign</artifactId>
<version>2.1.2.RELEASE</version>
<version>2.1.3.RELEASE</version>
<packaging>pom</packaging>
<name>Spring Cloud OpenFeign</name>
<description>Spring Cloud OpenFeign</description>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-build</artifactId>
<version>2.1.5.RELEASE</version>
<version>2.1.7.RELEASE</version>
<relativePath/>
</parent>
<scm>
@@ -26,8 +26,8 @@
<properties>
<main.basedir>${basedir}</main.basedir>
<jackson.version>2.7.3</jackson.version>
<spring-cloud-commons.version>2.1.2.RELEASE</spring-cloud-commons.version>
<spring-cloud-netflix.version>2.1.2.RELEASE</spring-cloud-netflix.version>
<spring-cloud-commons.version>2.1.3.RELEASE</spring-cloud-commons.version>
<spring-cloud-netflix.version>2.1.3.RELEASE</spring-cloud-netflix.version>
<!-- Plugin versions -->
<maven-compiler-plugin.version>3.6.1</maven-compiler-plugin.version>
+2 -6
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign</artifactId>
<version>2.1.2.RELEASE</version>
<version>2.1.3.RELEASE</version>
<relativePath>..</relativePath> <!-- lookup parent from repository -->
</parent>
<artifactId>spring-cloud-openfeign-core</artifactId>
@@ -158,14 +158,10 @@
<artifactId>rxjava</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-apache-client4</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.1.0</version>
<optional>true</optional>
</dependency>
<dependency>
@@ -37,6 +37,21 @@ public class PageableSpringEncoder implements Encoder {
private final Encoder delegate;
/**
* Page index parameter name.
*/
private String pageParameter = "page";
/**
* Page size parameter name.
*/
private String sizeParameter = "size";
/**
* Sort parameter name.
*/
private String sortParameter = "sort";
/**
* Creates a new PageableSpringEncoder with the given delegate for fallback. If no
* delegate is provided and this encoder cant handle the request, an EncodeException
@@ -54,8 +69,12 @@ public class PageableSpringEncoder implements Encoder {
if (supports(object)) {
if (object instanceof Pageable) {
Pageable pageable = (Pageable) object;
template.query("page", pageable.getPageNumber() + "");
template.query("size", pageable.getPageSize() + "");
if (pageable.isPaged()) {
template.query(pageParameter, pageable.getPageNumber() + "");
template.query(sizeParameter, pageable.getPageSize() + "");
}
if (pageable.getSort() != null) {
applySort(template, pageable.getSort());
}
@@ -82,11 +101,17 @@ public class PageableSpringEncoder implements Encoder {
Collection<String> existingSorts = template.queries().get("sort");
List<String> sortQueries = existingSorts != null ? new ArrayList<>(existingSorts)
: new ArrayList<>();
if (!sortParameter.equals("sort")) {
existingSorts = template.queries().get(sortParameter);
if (existingSorts != null) {
sortQueries.addAll(existingSorts);
}
}
for (Sort.Order order : sort) {
sortQueries.add(order.getProperty() + "," + order.getDirection());
}
if (!sortQueries.isEmpty()) {
template.query("sort", sortQueries);
template.query(sortParameter, sortQueries);
}
}
@@ -63,13 +63,18 @@ public class PageableEncoderTests {
encoder.encode(createPageAndSortRequest(), null, request);
// Request queries shall contain three entries
assertThat(request.queries().size()).isEqualTo(3);
assertThat(request.queries()).hasSize(3);
// Request page shall contain page
assertThat(request.queries().get("page")).contains(String.valueOf(PAGE));
// Request size shall contain size
assertThat(request.queries().get("size")).contains(String.valueOf(SIZE));
// Request sort size shall contain sort entries
assertThat(request.queries().get("sort").size()).isEqualTo(2);
assertThat(request.queries().get("size")).contains(String.valueOf(SIZE)); // Request
// sort
// size
// shall
// contain
// sort
// entries
assertThat(request.queries().get("sort")).hasSize(2);
}
private Pageable createPageAndSortRequest() {
@@ -86,9 +91,14 @@ public class PageableEncoderTests {
// Request page shall contain page
assertThat(request.queries().get("page")).contains(String.valueOf(PAGE));
// Request size shall contain size
assertThat(request.queries().get("size")).contains(String.valueOf(SIZE));
// Request sort size shall contain sort entries
assertThat(request.queries().containsKey("sort")).isEqualTo(false);
assertThat(request.queries().get("size")).contains(String.valueOf(SIZE)); // Request
// sort
// size
// shall
// contain
// sort
// entries
assertThat(request.queries()).doesNotContainKey("sort");
}
private Pageable createPageAndRequest() {
@@ -105,11 +115,22 @@ public class PageableEncoderTests {
// Request queries shall contain three entries
assertThat(request.queries().size()).isEqualTo(1);
// Request sort size shall contain sort entries
assertThat(request.queries().get("sort").size()).isEqualTo(2);
assertThat(request.queries().get("sort")).hasSize(2);
}
private Sort createSort() {
return Sort.by(SORT_1, SORT_2).ascending();
}
@Test
public void testUnpagedRequest() {
Encoder encoder = this.context.getInstance("foo", Encoder.class);
assertThat(encoder).isNotNull();
RequestTemplate request = new RequestTemplate();
encoder.encode(Pageable.unpaged(), null, request);
// Request queries shall contain three entries
assertThat(request.queries()).isEmpty();
}
}
+7 -2
View File
@@ -6,11 +6,11 @@
<parent>
<artifactId>spring-cloud-dependencies-parent</artifactId>
<groupId>org.springframework.cloud</groupId>
<version>2.1.5.RELEASE</version>
<version>2.1.7.RELEASE</version>
<relativePath/>
</parent>
<artifactId>spring-cloud-openfeign-dependencies</artifactId>
<version>2.1.2.RELEASE</version>
<version>2.1.3.RELEASE</version>
<packaging>pom</packaging>
<name>spring-cloud-openfeign-dependencies</name>
<description>Spring Cloud OpenFeign Dependencies</description>
@@ -100,6 +100,11 @@
<artifactId>feign-sax</artifactId>
<version>${feign.version}</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-mock</artifactId>
<version>${feign.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<profiles>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign</artifactId>
<version>2.1.2.RELEASE</version>
<version>2.1.3.RELEASE</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-cloud-starter-openfeign</artifactId>