Skip to content

Commit

Permalink
fix spotless issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lony2003 committed May 28, 2024
1 parent ec16392 commit 5f066f4
Show file tree
Hide file tree
Showing 19 changed files with 353 additions and 200 deletions.
143 changes: 57 additions & 86 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,4 @@ dependencies {
api project(':dapr-secretstore-spring-boot-starter')

testImplementation project(':tests')
}
}
2 changes: 1 addition & 1 deletion dapr-client-spring-boot-starter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ dependencies {
api('org.springframework.boot:spring-boot-starter')

api project(":dapr-dependencies-spring-boot")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Mono;

import java.util.concurrent.TimeoutException;

/**
* The autoconfiguration used by Spring-Boot that contains all beans to create and inject dapr clients into beans.
* <p>
* Dapr Java SDK currently has two types of Client: DaprClient and DaprPreviewClient, and both of them contains some important methods,
* so we will create them all.
* Dapr Java SDK currently has two types of Client: DaprClient and DaprPreviewClient, and both of them contains some
* important methods, so we will create them all.
*/
@Slf4j
@Configuration(proxyBeanMethods = false)
Expand All @@ -56,7 +55,8 @@ DaprClient daprClient(DaprClientConfig daprClientConfig) {
SetupDaprPropertyUtil.setupDaprSystemProperty(daprClientConfig);

DaprClient daprClient = new DaprClientBuilder().build();
// waitForDaprClient(daprClient, daprClientConfig.getSidecarConnectWaitMillis(), daprClientConfig.getSidecarConnectAlwaysRetry());
// waitForDaprClient(daprClient, daprClientConfig.getSidecarConnectWaitMillis(),
// daprClientConfig.getSidecarConnectAlwaysRetry());

return daprClient;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ public static void setupDaprSystemProperty(DaprClientConfig daprClientConfig) {
System.setProperty("dapr.http.port", daprClientConfig.getHttpPort().toString());
System.setProperty("dapr.grpc.port", daprClientConfig.getGrpcPort().toString());

//grpc endpoint could be null
// grpc endpoint could be null
if (daprClientConfig.getGrpcEndpoint() != null) {
System.setProperty("dapr.grpc.endpoint", daprClientConfig.getGrpcEndpoint());
}

//http endpoint could be null
// http endpoint could be null
if (daprClientConfig.getGrpcEndpoint() != null) {
System.setProperty("dapr.http.endpoint", daprClientConfig.getGrpcEndpoint());
}

System.setProperty("dapr.api.max.retries", daprClientConfig.getMaxRetries().toString());
System.setProperty("dapr.api.timeout.milliseconds", String.valueOf(daprClientConfig.getTimeout().toMillis()));

//api token could be null
// api token could be null
if (daprClientConfig.getApiToken() != null) {
System.setProperty("dapr.api.token", daprClientConfig.getApiToken());
}
Expand Down
2 changes: 1 addition & 1 deletion dapr-dependencies-spring-boot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ version = projectVersion
dependencies {
api("io.dapr:dapr-sdk:${daprVersion}")
api("io.dapr:dapr-sdk-springboot3:${daprVersion}")
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2016-2024 Team Fangkehou
*
* 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
*
* http://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 icu.fangkehou.dapr.feign.annotation;

import java.lang.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
/*
* Copyright (c) 2016-2024 Team Fangkehou
*
* 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
*
* http://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 icu.fangkehou.dapr.feign.autoconfigure;

import icu.fangkehou.dapr.feign.DaprInvokeFeignClient;
import io.dapr.client.DaprClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(FeignAutoConfiguration.class)
public class DaprFeignClientAutoConfiguration {

// @Bean()
// public DaprInvokeFeignClient daprInvokeFeignClient(DaprClient daprClient) {
// return new DaprInvokeFeignClient(daprClient);
// }
// @Bean()
// public DaprInvokeFeignClient daprInvokeFeignClient(DaprClient daprClient) {
// return new DaprInvokeFeignClient(daprClient);
// }
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
/*
* Copyright (c) 2016-2024 Team Fangkehou
*
* 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
*
* http://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 icu.fangkehou.dapr.feign.targeter;

import java.lang.reflect.Field;

import org.springframework.cloud.openfeign.FeignClientFactory;
import org.springframework.cloud.openfeign.FeignClientFactoryBean;
import org.springframework.cloud.openfeign.Targeter;

import feign.Client;
import feign.Feign;
import feign.Target;
import icu.fangkehou.dapr.feign.DaprInvokeFeignClient;
import icu.fangkehou.dapr.feign.annotation.UseDaprClient;
import org.springframework.cloud.openfeign.FeignClientFactory;
import org.springframework.cloud.openfeign.FeignClientFactoryBean;
import org.springframework.cloud.openfeign.Targeter;

import java.lang.reflect.Field;

public class DaprClientTargeter implements Targeter {

Expand All @@ -20,7 +37,8 @@ public DaprClientTargeter(DaprInvokeFeignClient daprInvokeFeignClient) {
}

@Override
public <T> T target(FeignClientFactoryBean factory, Feign.Builder feign, FeignClientFactory context, Target.HardCodedTarget<T> target) {
public <T> T target(FeignClientFactoryBean factory, Feign.Builder feign, FeignClientFactory context,
Target.HardCodedTarget<T> target) {
Class<Feign.Builder> builderClass = Feign.Builder.class;

Client defaultClient = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
/*
* Copyright (c) 2016-2024 Team Fangkehou
*
* 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
*
* http://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;

import feign.Feign;
import feign.Target;
import icu.fangkehou.dapr.feign.DaprInvokeFeignClient;
import icu.fangkehou.dapr.feign.targeter.DaprClientTargeter;
import io.dapr.client.DaprClient;
import lombok.extern.slf4j.Slf4j;
import java.lang.reflect.Method;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand All @@ -15,17 +27,22 @@
import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory;
import org.springframework.context.annotation.*;

import java.lang.reflect.Method;
import feign.Feign;
import feign.Target;
import icu.fangkehou.dapr.feign.DaprInvokeFeignClient;
import icu.fangkehou.dapr.feign.targeter.DaprClientTargeter;
import io.dapr.client.DaprClient;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration(proxyBeanMethods = false)
public class DaprFeignClientOpenFeignAutoConfiguration {
//
// @Bean
// FeignClientsRegistrarProxyForDaprFeignClient feignClientsRegistrarProxyForDaprFeignClient() {
// return new FeignClientsRegistrarProxyForDaprFeignClient();
// }
//
// @Bean
// FeignClientsRegistrarProxyForDaprFeignClient feignClientsRegistrarProxyForDaprFeignClient() {
// return new FeignClientsRegistrarProxyForDaprFeignClient();
// }

@Configuration(proxyBeanMethods = false)
@Conditional(FeignCircuitBreakerDisabledConditions.class)
protected static class DefaultFeignTargeterConfiguration {
Expand Down Expand Up @@ -70,8 +87,8 @@ public CircuitBreakerNameResolver alphanumericCircuitBreakerNameResolver() {
@ConditionalOnMissingBean
@ConditionalOnBean(CircuitBreakerFactory.class)
public Targeter circuitBreakerFeignTargeter(CircuitBreakerFactory circuitBreakerFactory,
@Value("${spring.cloud.openfeign.circuitbreaker.group.enabled:false}") boolean circuitBreakerGroupEnabled,
CircuitBreakerNameResolver circuitBreakerNameResolver) {
@Value("${spring.cloud.openfeign.circuitbreaker.group.enabled:false}") boolean circuitBreakerGroupEnabled,
CircuitBreakerNameResolver circuitBreakerNameResolver) {
return new FeignCircuitBreakerTargeter(circuitBreakerFactory, circuitBreakerGroupEnabled,
circuitBreakerNameResolver);
}
Expand Down
2 changes: 1 addition & 1 deletion feign-dapr-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ dependencies {
testImplementation 'io.github.openfeign:feign-core'

testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
/*
* Copyright (c) 2016-2024 Team Fangkehou
*
* 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
*
* http://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 icu.fangkehou.dapr.feign;

import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.TimeUnit;

import feign.Client;
import feign.Request;
import feign.Response;
Expand All @@ -12,50 +38,43 @@
import io.dapr.utils.TypeRef;
import reactor.core.publisher.Mono;

import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;

import java.nio.charset.Charset;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.TimeUnit;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* This module directs Feign's requests to
* <a href="https://dapr.io/">Dapr</a>, which is a microservice framework.
* Ex.
* This module directs Feign's requests to <a href="https://dapr.io/">Dapr</a>, which is a microservice framework. Ex.
* <p>
* Currently, Dapr supports two ways to invoke operations, which is <b>invokeBinding (Output Binding)</b> and <b>invokeMethod</b>,
* so this Client supports two schemas: <b>http://binding.xxx</b> or <b>http://method.xxx</b><br>
* Currently, Dapr supports two ways to invoke operations, which is <b>invokeBinding (Output Binding)</b> and
* <b>invokeMethod</b>, so this Client supports two schemas: <b>http://binding.xxx</b> or <b>http://method.xxx</b><br>
* You don't have to mind why there is a http schema at start, it's just a trick to hack Spring Boot Openfeign.
* <p>
* For invokeMethod, there are two types of information in the url, which is very similar to an HTTP URL,
* except that the host in the HTTP URL is converted to appId, and the path (excluding "/") is converted to methodName.<br>
* For example, if you have a method which appid is "myApp", and methodName is "getAll", then the url of this request
* is "http://method.myApp/getAll".<br>
* For invokeMethod, there are two types of information in the url, which is very similar to an HTTP URL, except that
* the host in the HTTP URL is converted to appId, and the path (excluding "/") is converted to methodName.<br>
* For example, if you have a method which appid is "myApp", and methodName is "getAll", then the url of this request is
* "http://method.myApp/getAll".<br>
* You can also set HTTP Headers if you like, the Client will handle them.<br>
* <b>Currently only HTTP invokes are supported, but I think we will support grpc invokes in the future, may be the url will be "http://method_grpc.myApp/getAll" or something.</b>
* <b>Currently only HTTP invokes are supported, but I think we will support grpc invokes in the future, may be the url
* will be "http://method_grpc.myApp/getAll" or something.</b>
* <p>
* For invokeBinding, there are also two types of information in the url, the host is the bindingName, and the path is the operation.<br>
* <b>Note: different bindings support different operations, so you have to check <a href="https://docs.dapr.io/zh-hans/reference/components-reference/supported-bindings/">the documentation of Dapr</a> for that.</b><br>
* For example, if you have a binding which bindingName is "myBinding", and the operation supported is "create",
* and then the url of this request is "http://binding.myBinding/create"<br>
* For invokeBinding, there are also two types of information in the url, the host is the bindingName, and the path is
* the operation.<br>
* <b>Note: different bindings support different operations, so you have to check
* <a href="https://docs.dapr.io/zh-hans/reference/components-reference/supported-bindings/">the documentation of
* Dapr</a> for that.</b><br>
* For example, if you have a binding which bindingName is "myBinding", and the operation supported is "create", and
* then the url of this request is "http://binding.myBinding/create"<br>
* You can put some metadata into the Header of your Feign Request, the Client will handle them.
* <p>
* As for response, the result code is always 200 OK, and if client have met any error, it will throw an IOException for that.
* As for response, the result code is always 200 OK, and if client have met any error, it will throw an IOException for
* that.
*
* <pre>
* MyAppData response = Feign.builder().client(new DaprFeignClient()).target(MyAppData.class, "http://binding.myBinding/create");
* MyAppData response = Feign.builder().client(new DaprFeignClient()).target(MyAppData.class,
* "http://binding.myBinding/create");
*/
public class DaprInvokeFeignClient implements Client {

private final DaprClient daprClient;

public DaprInvokeFeignClient() {
daprClient = new DaprClientBuilder().build();
daprClient = new DaprClientBuilder().build();
}

public DaprInvokeFeignClient(DaprClient daprClient) {
Expand Down Expand Up @@ -235,7 +254,8 @@ private Response.Body toResponseBody(Mono<byte[]> response, Request.Options opti
byte[] result;

try {
result = response.block(Duration.of(options.connectTimeoutMillis()+ options.readTimeoutMillis(), TimeUnit.MILLISECONDS.toChronoUnit()));
result = response.block(Duration.of(options.connectTimeoutMillis() + options.readTimeoutMillis(),
TimeUnit.MILLISECONDS.toChronoUnit()));

if (result == null) {
result = new byte[0];
Expand Down Expand Up @@ -279,4 +299,4 @@ public void close() throws IOException {
};
}

}
}
Loading

0 comments on commit 5f066f4

Please sign in to comment.