Skip to content

Commit a142fa9

Browse files
committed
Fix Checkstyle errors
1 parent a9b1b5e commit a142fa9

File tree

7 files changed

+135
-63
lines changed

7 files changed

+135
-63
lines changed

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsConfiguration.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ public Decoder feignDecoder() {
8989
@ConditionalOnMissingClass("org.springframework.data.domain.Pageable")
9090
public Encoder feignEncoder() {
9191
if (this.pojoSerializationWriter != null) {
92-
return new SpringEncoder(this.pojoSerializationWriter, this.messageConverters);
93-
} else {
92+
return new SpringEncoder(this.pojoSerializationWriter,
93+
this.messageConverters);
94+
}
95+
else {
9496
return new SpringEncoder(this.messageConverters);
9597
}
9698
}
@@ -102,11 +104,12 @@ public Encoder feignEncoderPageable() {
102104
PageableSpringEncoder encoder;
103105

104106
if (this.pojoSerializationWriter != null) {
107+
encoder = new PageableSpringEncoder(new SpringEncoder(
108+
this.pojoSerializationWriter, this.messageConverters));
109+
}
110+
else {
105111
encoder = new PageableSpringEncoder(
106-
new SpringEncoder(this.pojoSerializationWriter, this.messageConverters));
107-
} else {
108-
encoder = new PageableSpringEncoder(
109-
new SpringEncoder(this.messageConverters));
112+
new SpringEncoder(this.messageConverters));
110113
}
111114

112115
if (springDataWebProperties != null) {

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PojoJsonSerializationWriter.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.cloud.openfeign.support;
218

19+
import java.io.IOException;
20+
321
import com.fasterxml.jackson.databind.ObjectMapper;
22+
423
import org.springframework.beans.factory.annotation.Autowired;
524
import org.springframework.http.MediaType;
625
import org.springframework.stereotype.Component;
726

8-
import java.io.IOException;
9-
1027
@Component
1128
public class PojoJsonSerializationWriter extends PojoSerializationWriter {
29+
1230
@Autowired
1331
private ObjectMapper objectMapper;
1432

@@ -21,4 +39,5 @@ protected MediaType getContentType() {
2139
protected String serialize(Object object) throws IOException {
2240
return objectMapper.writeValueAsString(object);
2341
}
42+
2443
}

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PojoSerializationWriter.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,55 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.cloud.openfeign.support;
218

19+
import java.io.IOException;
20+
import java.util.Iterator;
21+
322
import feign.codec.EncodeException;
423
import feign.form.multipart.AbstractWriter;
524
import feign.form.multipart.Output;
25+
626
import org.springframework.http.MediaType;
727
import org.springframework.web.multipart.MultipartFile;
828

9-
import java.io.IOException;
10-
import java.util.Iterator;
11-
1229
import static feign.form.ContentProcessor.CRLF;
1330
import static feign.form.util.PojoUtil.isUserPojo;
1431

1532
public abstract class PojoSerializationWriter extends AbstractWriter {
33+
1634
@Override
1735
public boolean isApplicable(Object object) {
1836
return !(object instanceof MultipartFile) && !(object instanceof MultipartFile[])
19-
&& (isUserPojoCollection(object) || isUserPojo(object));
37+
&& (isUserPojoCollection(object) || isUserPojo(object));
2038
}
2139

2240
@Override
23-
public void write (Output output, String key, Object object) throws EncodeException {
41+
public void write(Output output, String key, Object object) throws EncodeException {
2442
try {
2543
String string = new StringBuilder()
26-
.append("Content-Disposition: form-data; name=\"").append(key).append('"')
27-
.append(CRLF)
28-
.append("Content-Type: ").append(getContentType())
29-
.append("; charset=").append(output.getCharset().name())
30-
.append(CRLF)
31-
.append(CRLF)
32-
.append(serialize(object))
33-
.toString();
44+
.append("Content-Disposition: form-data; name=\"").append(key)
45+
.append('"').append(CRLF).append("Content-Type: ")
46+
.append(getContentType()).append("; charset=")
47+
.append(output.getCharset().name()).append(CRLF).append(CRLF)
48+
.append(serialize(object)).toString();
3449

3550
output.write(string);
36-
} catch (IOException e) {
51+
}
52+
catch (IOException e) {
3753
throw new EncodeException(e.getMessage());
3854
}
3955
}
@@ -61,8 +77,10 @@ private boolean isUserPojoCollection(Object object) {
6177
Object next = iterator.next();
6278

6379
return !(next instanceof MultipartFile) && isUserPojo(next);
64-
} else {
80+
}
81+
else {
6582
return false;
6683
}
6784
}
85+
6886
}

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringEncoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public SpringEncoder(ObjectFactory<HttpMessageConverters> messageConverters) {
6868
this.messageConverters = messageConverters;
6969
}
7070

71-
public SpringEncoder(PojoSerializationWriter writer, ObjectFactory<HttpMessageConverters> messageConverters) {
71+
public SpringEncoder(PojoSerializationWriter writer,
72+
ObjectFactory<HttpMessageConverters> messageConverters) {
7273
this.springFormEncoder = new SpringPojoFormEncoder(writer);
7374
this.messageConverters = messageConverters;
7475
}

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringMvcContract.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@
2020
import java.lang.reflect.Method;
2121
import java.lang.reflect.Parameter;
2222
import java.lang.reflect.Type;
23-
import java.util.*;
23+
import java.util.ArrayList;
24+
import java.util.Arrays;
25+
import java.util.Collection;
26+
import java.util.Collections;
27+
import java.util.HashMap;
28+
import java.util.LinkedHashMap;
29+
import java.util.List;
30+
import java.util.Map;
31+
import java.util.Objects;
2432

2533
import feign.Contract;
2634
import feign.Feign;
@@ -271,11 +279,13 @@ protected boolean processAnnotationsOnParameter(MethodMetadata data,
271279
Annotation[] annotations, int paramIndex) {
272280
boolean isMultipartFormData = false;
273281

274-
Collection<String> contentTypes = data.template().headers().get(HttpEncoding.CONTENT_TYPE);
282+
Collection<String> contentTypes = data.template().headers()
283+
.get(HttpEncoding.CONTENT_TYPE);
275284

276285
if (contentTypes != null && !contentTypes.isEmpty()) {
277286
String type = contentTypes.iterator().next();
278-
isMultipartFormData = Objects.equals(MediaType.valueOf(type), MediaType.MULTIPART_FORM_DATA);
287+
isMultipartFormData = Objects.equals(MediaType.valueOf(type),
288+
MediaType.MULTIPART_FORM_DATA);
279289
}
280290

281291
boolean isHttpAnnotation = false;
@@ -297,7 +307,8 @@ protected boolean processAnnotationsOnParameter(MethodMetadata data,
297307
}
298308
}
299309

300-
if (!isMultipartFormData && isHttpAnnotation && data.indexToExpander().get(paramIndex) == null) {
310+
if (!isMultipartFormData && isHttpAnnotation
311+
&& data.indexToExpander().get(paramIndex) == null) {
301312
TypeDescriptor typeDescriptor = createTypeDescriptor(method, paramIndex);
302313
if (this.conversionService.canConvert(typeDescriptor,
303314
STRING_TYPE_DESCRIPTOR)) {
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.cloud.openfeign.support;
218

319
import feign.form.MultipartFormContentProcessor;
@@ -6,10 +22,13 @@
622
import static feign.form.ContentType.MULTIPART;
723

824
public class SpringPojoFormEncoder extends SpringFormEncoder {
25+
926
public SpringPojoFormEncoder(PojoSerializationWriter pojoSerializationWriter) {
1027
super();
1128

12-
MultipartFormContentProcessor processor = (MultipartFormContentProcessor) getContentProcessor(MULTIPART);
29+
MultipartFormContentProcessor processor = (MultipartFormContentProcessor) getContentProcessor(
30+
MULTIPART);
1331
processor.addFirstWriter(pojoSerializationWriter);
1432
}
33+
1534
}

0 commit comments

Comments
 (0)