Skip to content

Commit 2877e86

Browse files
committed
style(springboot openfeign): add headers, clean import, refresh style
Signed-off-by: lony2003 <[email protected]>
1 parent 46a9f65 commit 2877e86

File tree

24 files changed

+305
-128
lines changed

24 files changed

+305
-128
lines changed

dapr-spring/dapr-openfeign-client/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<parent>

dapr-spring/dapr-openfeign-client/src/main/java/io/dapr/feign/DaprInvokeFeignClient.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,6 @@ public class DaprInvokeFeignClient implements Client {
8989

9090
private final DaprClient daprClient;
9191

92-
private static Map<String, HttpExtension> generateHttpExtensionMap() {
93-
Map<String, HttpExtension> tempHttpExtensionMap = new HashMap<>();
94-
95-
tempHttpExtensionMap.put("none",
96-
HttpExtension.NONE);
97-
tempHttpExtensionMap.put("put",
98-
HttpExtension.PUT);
99-
tempHttpExtensionMap.put("post",
100-
HttpExtension.POST);
101-
tempHttpExtensionMap.put("delete",
102-
HttpExtension.DELETE);
103-
tempHttpExtensionMap.put("head",
104-
HttpExtension.HEAD);
105-
tempHttpExtensionMap.put("connect",
106-
HttpExtension.CONNECT);
107-
tempHttpExtensionMap.put("options",
108-
HttpExtension.OPTIONS);
109-
tempHttpExtensionMap.put("trace",
110-
HttpExtension.TRACE);
111-
tempHttpExtensionMap.put("get",
112-
HttpExtension.GET);
113-
114-
return tempHttpExtensionMap;
115-
}
116-
11792
/**
11893
* Default Client creation with no arguments.
11994
*
@@ -155,6 +130,31 @@ public DaprInvokeFeignClient(DaprClient daprClient, int timeout, int retry) {
155130
this.retry = retry;
156131
}
157132

133+
private static Map<String, HttpExtension> generateHttpExtensionMap() {
134+
Map<String, HttpExtension> tempHttpExtensionMap = new HashMap<>();
135+
136+
tempHttpExtensionMap.put("none",
137+
HttpExtension.NONE);
138+
tempHttpExtensionMap.put("put",
139+
HttpExtension.PUT);
140+
tempHttpExtensionMap.put("post",
141+
HttpExtension.POST);
142+
tempHttpExtensionMap.put("delete",
143+
HttpExtension.DELETE);
144+
tempHttpExtensionMap.put("head",
145+
HttpExtension.HEAD);
146+
tempHttpExtensionMap.put("connect",
147+
HttpExtension.CONNECT);
148+
tempHttpExtensionMap.put("options",
149+
HttpExtension.OPTIONS);
150+
tempHttpExtensionMap.put("trace",
151+
HttpExtension.TRACE);
152+
tempHttpExtensionMap.put("get",
153+
HttpExtension.GET);
154+
155+
return tempHttpExtensionMap;
156+
}
157+
158158
@Override
159159
public Response execute(Request request, Request.Options options) throws IOException {
160160
URI uri;

dapr-spring/dapr-openfeign-client/src/test/java/io/dapr/feign/DaprFeignClientBindingTest.java

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,54 +14,53 @@
1414
package io.dapr.feign;
1515

1616

17-
import static org.junit.jupiter.api.Assertions.assertEquals;
18-
1917
import feign.Body;
20-
import org.junit.jupiter.api.Test;
21-
import org.junit.jupiter.api.extension.ExtendWith;
22-
import org.mockito.Mock;
23-
import org.mockito.Mockito;
24-
import org.mockito.junit.jupiter.MockitoExtension;
25-
2618
import feign.Feign;
2719
import feign.Headers;
2820
import feign.RequestLine;
2921
import feign.Response;
3022
import io.dapr.client.DaprClient;
3123
import io.dapr.client.domain.InvokeBindingRequest;
3224
import io.dapr.utils.TypeRef;
25+
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.api.extension.ExtendWith;
27+
import org.mockito.Mock;
28+
import org.mockito.Mockito;
29+
import org.mockito.junit.jupiter.MockitoExtension;
3330
import reactor.core.publisher.Mono;
3431

32+
import static org.junit.jupiter.api.Assertions.assertEquals;
33+
3534
@ExtendWith(MockitoExtension.class)
3635
public class DaprFeignClientBindingTest {
3736

38-
@Mock
39-
DaprClient daprClient;
37+
@Mock
38+
DaprClient daprClient;
4039

41-
@Test
42-
void DaprFeignClient_testMockBindingInvoke() {
43-
DaprFeignClientTestInterface repository =
44-
newBuilder().target(DaprFeignClientTestInterface.class, "http://binding.myBinding");
40+
@Test
41+
void DaprFeignClient_testMockBindingInvoke() {
42+
DaprFeignClientTestInterface repository =
43+
newBuilder().target(DaprFeignClientTestInterface.class, "http://binding.myBinding");
4544

46-
assertEquals(200, repository.getWithContentType().status());
47-
assertEquals(0, repository.post().body().length());
48-
}
45+
assertEquals(200, repository.getWithContentType().status());
46+
assertEquals(0, repository.post().body().length());
47+
}
4948

50-
public Feign.Builder newBuilder() {
51-
Mockito.when(daprClient.invokeBinding(Mockito.any(InvokeBindingRequest.class), Mockito.eq(TypeRef.BYTE_ARRAY)))
52-
.thenReturn(Mono.just(new byte[0]));
49+
public Feign.Builder newBuilder() {
50+
Mockito.when(daprClient.invokeBinding(Mockito.any(InvokeBindingRequest.class), Mockito.eq(TypeRef.BYTE_ARRAY)))
51+
.thenReturn(Mono.just(new byte[0]));
5352

54-
return Feign.builder().client(new DaprInvokeFeignClient(daprClient));
55-
}
53+
return Feign.builder().client(new DaprInvokeFeignClient(daprClient));
54+
}
5655

57-
public interface DaprFeignClientTestInterface {
56+
public interface DaprFeignClientTestInterface {
5857

59-
@RequestLine("GET /create")
60-
@Headers({"Accept: text/plain", "Content-Type: text/plain"})
61-
Response getWithContentType();
58+
@RequestLine("GET /create")
59+
@Headers({"Accept: text/plain", "Content-Type: text/plain"})
60+
Response getWithContentType();
6261

63-
@RequestLine("POST /get")
64-
@Body("test")
65-
Response post();
66-
}
62+
@RequestLine("POST /get")
63+
@Body("test")
64+
Response post();
65+
}
6766
}

dapr-spring/dapr-openfeign-client/src/test/java/io/dapr/feign/DaprFeignClientMethodTest.java

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,56 +14,55 @@
1414
package io.dapr.feign;
1515

1616

17-
import static org.junit.jupiter.api.Assertions.assertEquals;
18-
19-
import java.nio.charset.StandardCharsets;
20-
2117
import feign.Body;
22-
import org.junit.jupiter.api.Test;
23-
import org.junit.jupiter.api.extension.ExtendWith;
24-
import org.mockito.Mock;
25-
import org.mockito.Mockito;
26-
import org.mockito.junit.jupiter.MockitoExtension;
27-
2818
import feign.Feign;
2919
import feign.Headers;
3020
import feign.RequestLine;
3121
import feign.Response;
3222
import io.dapr.client.DaprClient;
3323
import io.dapr.client.domain.InvokeMethodRequest;
3424
import io.dapr.utils.TypeRef;
25+
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.api.extension.ExtendWith;
27+
import org.mockito.Mock;
28+
import org.mockito.Mockito;
29+
import org.mockito.junit.jupiter.MockitoExtension;
3530
import reactor.core.publisher.Mono;
3631

32+
import java.nio.charset.StandardCharsets;
33+
34+
import static org.junit.jupiter.api.Assertions.assertEquals;
35+
3736
@ExtendWith(MockitoExtension.class)
3837
public class DaprFeignClientMethodTest {
3938

40-
@Mock
41-
DaprClient daprClient;
39+
@Mock
40+
DaprClient daprClient;
4241

43-
@Test
44-
void DaprFeignClient_testMockMethodInvoke() {
45-
DaprFeignClientTestInterface repository =
46-
newBuilder().target(DaprFeignClientTestInterface.class, "http://method.myApp/");
42+
@Test
43+
void DaprFeignClient_testMockMethodInvoke() {
44+
DaprFeignClientTestInterface repository =
45+
newBuilder().target(DaprFeignClientTestInterface.class, "http://method.myApp/");
4746

48-
assertEquals(12, repository.getWithContentType().body().length());
49-
assertEquals(200, repository.post().status());
50-
}
47+
assertEquals(12, repository.getWithContentType().body().length());
48+
assertEquals(200, repository.post().status());
49+
}
5150

52-
public Feign.Builder newBuilder() {
53-
Mockito.when(daprClient.invokeMethod(Mockito.any(InvokeMethodRequest.class), Mockito.eq(TypeRef.BYTE_ARRAY)))
54-
.thenReturn(Mono.just("hello world!".getBytes(StandardCharsets.UTF_8)));
51+
public Feign.Builder newBuilder() {
52+
Mockito.when(daprClient.invokeMethod(Mockito.any(InvokeMethodRequest.class), Mockito.eq(TypeRef.BYTE_ARRAY)))
53+
.thenReturn(Mono.just("hello world!".getBytes(StandardCharsets.UTF_8)));
5554

56-
return Feign.builder().client(new DaprInvokeFeignClient(daprClient));
57-
}
55+
return Feign.builder().client(new DaprInvokeFeignClient(daprClient));
56+
}
5857

59-
public interface DaprFeignClientTestInterface {
58+
public interface DaprFeignClientTestInterface {
6059

61-
@RequestLine("GET /getAll")
62-
@Headers({"Accept: text/plain", "Content-Type: text/plain"})
63-
Response getWithContentType();
60+
@RequestLine("GET /getAll")
61+
@Headers({"Accept: text/plain", "Content-Type: text/plain"})
62+
Response getWithContentType();
6463

65-
@RequestLine("POST /abc/")
66-
@Body("test")
67-
Response post();
68-
}
64+
@RequestLine("POST /abc/")
65+
@Body("test")
66+
Response post();
67+
}
6968
}

dapr-spring/dapr-spring-openfeign/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<parent>

dapr-spring/dapr-spring-openfeign/src/main/java/io/dapr/spring/openfeign/autoconfigure/DaprFeignClientProperties.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
115
package io.dapr.spring.openfeign.autoconfigure;
216

317
import org.springframework.boot.context.properties.ConfigurationProperties;

dapr-spring/dapr-spring-openfeign/src/main/java/io/dapr/spring/openfeign/targeter/DaprClientTargeterBeanPostProcessor.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
115
package io.dapr.spring.openfeign.targeter;
216

317
import io.dapr.feign.DaprInvokeFeignClient;

dapr-spring/dapr-spring-openfeign/src/test/java/io/dapr/spring/openfeign/DaprOpenFeignClientTestApplication.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
115
package io.dapr.spring.openfeign;
216

317
import org.springframework.boot.SpringApplication;

dapr-spring/dapr-spring-openfeign/src/test/java/io/dapr/spring/openfeign/DaprOpenFeignClientTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
115
package io.dapr.spring.openfeign;
216

317
import io.dapr.client.DaprClient;

dapr-spring/dapr-spring-openfeign/src/test/java/io/dapr/spring/openfeign/client/DaprInvokeBindingClient.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
115
package io.dapr.spring.openfeign.client;
216

317
import io.dapr.spring.openfeign.annotation.UseDaprClient;

dapr-spring/dapr-spring-openfeign/src/test/java/io/dapr/spring/openfeign/client/DaprInvokeMethodClient.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
115
package io.dapr.spring.openfeign.client;
216

317
import io.dapr.spring.openfeign.annotation.UseDaprClient;

dapr-spring/dapr-spring-openfeign/src/test/java/io/dapr/spring/openfeign/client/DemoFeignClient.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
115
package io.dapr.spring.openfeign.client;
216

317
import org.springframework.cloud.openfeign.FeignClient;

0 commit comments

Comments
 (0)