Browse Source

Merge remote-tracking branch 'origin/3.1.x'

pull/782/head
Olga Maciaszek-Sharma 2 years ago
parent
commit
3b02c044cb
  1. 6
      spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignCircuitBreakerInvocationHandler.java
  2. 14
      spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/AbstractFormWriter.java
  3. 64
      spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/AbstractFormWriterTests.java

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

@ -37,8 +37,8 @@ import org.springframework.web.context.request.RequestContextHolder; @@ -37,8 +37,8 @@ import org.springframework.web.context.request.RequestContextHolder;
import static feign.Util.checkNotNull;
/**
* @author Grzejszczak
* @author Sharma
* @author Marcin Grzejszczak
* @author Olga Maciaszek-Sharma
* @author Niang
* @author Bohutskyi
* @author kim
@ -163,7 +163,7 @@ class FeignCircuitBreakerInvocationHandler implements InvocationHandler { @@ -163,7 +163,7 @@ class FeignCircuitBreakerInvocationHandler implements InvocationHandler {
* @return cached methods map for fallback invoking
*/
static Map<Method, Method> toFallbackMethod(Map<Method, InvocationHandlerFactory.MethodHandler> dispatch) {
Map<Method, Method> result = new LinkedHashMap<Method, Method>();
Map<Method, Method> result = new LinkedHashMap<>();
for (Method method : dispatch.keySet()) {
method.setAccessible(true);
result.put(method, method);

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

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.cloud.openfeign.support;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Iterator;
import java.util.function.Predicate;
@ -32,6 +33,7 @@ import static feign.form.ContentProcessor.CRLF; @@ -32,6 +33,7 @@ import static feign.form.ContentProcessor.CRLF;
/**
* @author Darren Foong
* @author Wu Daifu
*/
public abstract class AbstractFormWriter extends AbstractWriter {
@ -61,10 +63,16 @@ public abstract class AbstractFormWriter extends AbstractWriter { @@ -61,10 +63,16 @@ public abstract class AbstractFormWriter extends AbstractWriter {
protected abstract String writeAsString(Object object) throws IOException;
private boolean isTypeOrCollection(Object object, Predicate<Object> isType) {
if (object == null) {
return false;
}
if (object.getClass().isArray()) {
Object[] array = (Object[]) object;
return array.length > 1 && isType.test(array[0]);
int len = Array.getLength(object);
if (len > 0) {
Object one = Array.get(object, 0);
return len > 1 && one != null && isType.test(one);
}
return false;
}
else if (object instanceof Iterable) {
Iterable<?> iterable = (Iterable<?>) object;

64
spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/AbstractFormWriterTests.java

@ -0,0 +1,64 @@ @@ -0,0 +1,64 @@
/*
* Copyright 2013-2022 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.openfeign.support;
import java.io.IOException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
/**
* @author Wu Daifu
*/
class AbstractFormWriterTests {
@Test
void shouldCorrectlyResolveIfApplicableForCollection() {
MockFormWriter formWriter = new MockFormWriter();
Object object = new Object();
Assertions.assertFalse(formWriter.isApplicable(object));
object = new Object[] { new Object(), new Object() };
Assertions.assertFalse(formWriter.isApplicable(object));
object = new UserPojo();
Assertions.assertTrue(formWriter.isApplicable(object));
object = new UserPojo[] { new UserPojo(), new UserPojo() };
Assertions.assertTrue(formWriter.isApplicable(object));
object = new byte[] { '1', '2' };
Assertions.assertFalse(formWriter.isApplicable(object));
}
class MockFormWriter extends AbstractFormWriter {
@Override
protected MediaType getContentType() {
return null;
}
@Override
protected String writeAsString(Object object) throws IOException {
return null;
}
}
class UserPojo {
}
}
Loading…
Cancel
Save