This is an automated email from the ASF dual-hosted git repository.

shenlin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/rocketmq-eventbridge.git


The following commit(s) were added to refs/heads/main by this push:
     new 691842d  add access log (#36)
691842d is described below

commit 691842d4d754e4997a199a04b514f7e0eb7cd0a3
Author: zhaohai <[email protected]>
AuthorDate: Wed Oct 19 15:12:03 2022 +0800

    add access log (#36)
    
    add access log
---
 .../adapter/api/handler/WebLogAspect.java          |  32 +++--
 .../adapter/rpc/impl/SecretManagerAPIImpl.java     |   7 +-
 .../eventbridge/config/EventBridgeConstants.java   |   1 +
 .../exception/EventBridgeException.java            |   5 +
 .../common/exception/EventBridgeErrorCode.java     |   6 +-
 .../apidestination/ApiDestinationService.java      |  79 +++++-------
 .../domain/model/connection/ConnectionService.java | 135 ++++++++-------------
 .../eventbridge/domain/rpc/SecretManagerAPI.java   |   7 +-
 ...iceTest.java => ApiDestinationServiceTest.java} |   8 +-
 .../rocketmq/eventbridge/filter/LogFilter.java     |  77 ++++++++++++
 .../eventbridge/handler/ExceptionHandler.java      |  12 +-
 start/src/main/resources/logback-spring.xml        |  17 +++
 12 files changed, 221 insertions(+), 165 deletions(-)

diff --git 
a/adapter/api/src/main/java/org/apache/rocketmq/eventbridge/adapter/api/handler/WebLogAspect.java
 
b/adapter/api/src/main/java/org/apache/rocketmq/eventbridge/adapter/api/handler/WebLogAspect.java
index 8be0a44..09e7b49 100644
--- 
a/adapter/api/src/main/java/org/apache/rocketmq/eventbridge/adapter/api/handler/WebLogAspect.java
+++ 
b/adapter/api/src/main/java/org/apache/rocketmq/eventbridge/adapter/api/handler/WebLogAspect.java
@@ -18,18 +18,23 @@
 package org.apache.rocketmq.eventbridge.adapter.api.handler;
 
 import com.google.gson.Gson;
-import lombok.extern.slf4j.Slf4j;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Pointcut;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
+import reactor.core.publisher.Mono;
+
+import java.util.Objects;
 
-@Slf4j
 @Aspect
 @Component
 public class WebLogAspect {
 
+    private static final Logger log = LoggerFactory.getLogger("accessLog");
+
     
@Pointcut("@annotation(org.apache.rocketmq.eventbridge.adapter.api.annotations.WebLog)")
     public void webLog() {
 
@@ -37,16 +42,21 @@ public class WebLogAspect {
 
     @Around("webLog()")
     public Object doControllerAround(ProceedingJoinPoint proceedingJoinPoint) 
throws Throwable {
-        long startTime = System.currentTimeMillis();
-        log.info("========================================== Start 
==========================================");
-        log.info("Class Method   : {}.{}", proceedingJoinPoint.getSignature().
-            getDeclaringTypeName(), 
proceedingJoinPoint.getSignature().getName());
-        log.info("Request Args   : {}", new 
Gson().toJson(proceedingJoinPoint.getArgs()));
         Object result = proceedingJoinPoint.proceed();
-        log.info("Response Args : {}", new Gson().toJson(result));
-        log.info("Time-Consuming : {} ms", System.currentTimeMillis() - 
startTime);
-        log.info("=========================================== End 
===========================================");
-        log.info("");
+        if (result instanceof Mono) {
+            Mono monoResult = (Mono) result;
+            return monoResult.doOnSuccess(o -> {
+                String response = "";
+                if (Objects.nonNull(o)) {
+                    response = o.toString();
+                }
+                log.info("Class Method   : {}.{} | Request Args   : {} | 
Response Args : {}",
+                        
proceedingJoinPoint.getSignature().getDeclaringTypeName(),
+                        proceedingJoinPoint.getSignature().getName(),
+                        new Gson().toJson(proceedingJoinPoint.getArgs()),
+                        response);
+            });
+        }
         return result;
     }
 
diff --git 
a/adapter/rpc/src/main/java/org/apache/rocketmq/eventbridge/adapter/rpc/impl/SecretManagerAPIImpl.java
 
b/adapter/rpc/src/main/java/org/apache/rocketmq/eventbridge/adapter/rpc/impl/SecretManagerAPIImpl.java
index 2b2db1b..dcf4343 100644
--- 
a/adapter/rpc/src/main/java/org/apache/rocketmq/eventbridge/adapter/rpc/impl/SecretManagerAPIImpl.java
+++ 
b/adapter/rpc/src/main/java/org/apache/rocketmq/eventbridge/adapter/rpc/impl/SecretManagerAPIImpl.java
@@ -24,12 +24,12 @@ import org.springframework.stereotype.Component;
 public class SecretManagerAPIImpl implements SecretManagerAPI {
 
     @Override
-    public String createSecretName(String accountId, String connectionName, 
String secretData) throws Exception {
+    public String createSecretName(String accountId, String connectionName, 
String secretData) {
         return null;
     }
 
     @Override
-    public void deleteSecretName(String secretName) throws Exception {
+    public void deleteSecretName(String secretName) {
 
     }
 
@@ -49,8 +49,7 @@ public class SecretManagerAPIImpl implements SecretManagerAPI 
{
     }
 
     @Override
-    public String updateSecretValue(String oldSecretName, String accountId, 
String connectionName, String key,
-        String value) throws Exception {
+    public String updateSecretValue(String oldSecretName, String accountId, 
String connectionName, String key, String value) {
         return null;
     }
 }
diff --git 
a/common/src/main/java/org/apache/rocketmq/eventbridge/config/EventBridgeConstants.java
 
b/common/src/main/java/org/apache/rocketmq/eventbridge/config/EventBridgeConstants.java
index 7cdb5cb..67b9a30 100644
--- 
a/common/src/main/java/org/apache/rocketmq/eventbridge/config/EventBridgeConstants.java
+++ 
b/common/src/main/java/org/apache/rocketmq/eventbridge/config/EventBridgeConstants.java
@@ -20,4 +20,5 @@ package org.apache.rocketmq.eventbridge.config;
 public class EventBridgeConstants {
     public static final String EVENT_BUS_NAME_KEY = "eventBusName";
     public static final String ACCOUNT_ID_KEY = "accountId";
+    public static final String REQUEST_TRACE_ID = "requestId";
 }
diff --git 
a/common/src/main/java/org/apache/rocketmq/eventbridge/exception/EventBridgeException.java
 
b/common/src/main/java/org/apache/rocketmq/eventbridge/exception/EventBridgeException.java
index a459581..b6ea18b 100644
--- 
a/common/src/main/java/org/apache/rocketmq/eventbridge/exception/EventBridgeException.java
+++ 
b/common/src/main/java/org/apache/rocketmq/eventbridge/exception/EventBridgeException.java
@@ -31,6 +31,11 @@ public class EventBridgeException extends RuntimeException {
         this.code = DefaultErrorCode.InternalError.getCode();
     }
 
+    public EventBridgeException(String code, String msg) {
+        super(msg);
+        this.code = code;
+    }
+
     public EventBridgeException(String msg, Throwable throwable) {
         super(MessageFormat.format(DefaultErrorCode.InternalError.getMsg(), 
msg), throwable);
         this.code = DefaultErrorCode.InternalError.getCode();
diff --git 
a/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/common/exception/EventBridgeErrorCode.java
 
b/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/common/exception/EventBridgeErrorCode.java
index 1dbafc6..73759c1 100644
--- 
a/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/common/exception/EventBridgeErrorCode.java
+++ 
b/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/common/exception/EventBridgeErrorCode.java
@@ -105,7 +105,11 @@ public enum EventBridgeErrorCode implements BaseErrorCode {
     ApiDestinationAlreadyExist(409, "ApiDestinationAlreadyExist", "The 
api-destination [{0}]  already existed!"),
     ApiDestinationParametersInvalid(409, "ApiDestinationParametersInvalid", 
"The api-destination parameters [{0}] is invalid! Please see the documentation 
for details."),
     ApiDestinationNotExist(409, "ApiDestinationNotExist", "The api-destination 
[{0}] not existed!"),
-    ;
+
+    // SecretManagerAPI
+    SecretManagerAPICreateSecretNameFailed(409, 
"SecretManagerAPICreateSecretNameFailed", "Create secret manager api secret 
name [{0}] failed"),
+    SecretManagerAPIDeleteSecretFailed(409, 
"SecretManagerAPIDeleteSecretFailed", "Delete secret manager api secret [{0}] 
failed"),
+    SecretManagerAPIGetSecretValueFailed(409, 
"SecretManagerAPIGetSecretValueFailed", "Get secret manager api secret value 
[{0}] failed");
 
     private final int httpCode;
     private final String code;
diff --git 
a/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/model/apidestination/ApiDestinationService.java
 
b/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/model/apidestination/ApiDestinationService.java
index fb7ddb1..8f989a1 100644
--- 
a/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/model/apidestination/ApiDestinationService.java
+++ 
b/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/model/apidestination/ApiDestinationService.java
@@ -17,7 +17,6 @@
 
 package org.apache.rocketmq.eventbridge.domain.model.apidestination;
 
-import java.util.List;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.rocketmq.eventbridge.domain.common.EventBridgeConstants;
 import 
org.apache.rocketmq.eventbridge.domain.common.exception.EventBridgeErrorCode;
@@ -29,6 +28,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.List;
+
 import static 
org.apache.rocketmq.eventbridge.domain.common.exception.EventBridgeErrorCode.ApiDestinationCountExceedLimit;
 
 @Slf4j
@@ -43,46 +44,31 @@ public class ApiDestinationService extends 
AbstractResourceService {
 
     @Transactional(rollbackFor = Exception.class, propagation = 
Propagation.REQUIRED)
     public String createApiDestination(ApiDestinationDTO 
eventApiDestinationDTO) {
-        try {
-            if (checkApiDestination(eventApiDestinationDTO.getAccountId(), 
eventApiDestinationDTO.getName()) != null) {
-                throw new 
EventBridgeException(EventBridgeErrorCode.ApiDestinationAlreadyExist, 
eventApiDestinationDTO.getName());
-            }
-            
super.checkQuota(this.getApiDestinationCount(eventApiDestinationDTO.getAccountId()),
 EventBridgeConstants.API_DESTINATION_COUNT_LIMIT,
+        if (checkApiDestination(eventApiDestinationDTO.getAccountId(), 
eventApiDestinationDTO.getName()) != null) {
+            throw new 
EventBridgeException(EventBridgeErrorCode.ApiDestinationAlreadyExist, 
eventApiDestinationDTO.getName());
+        }
+        
super.checkQuota(this.getApiDestinationCount(eventApiDestinationDTO.getAccountId()),
 EventBridgeConstants.API_DESTINATION_COUNT_LIMIT,
                 ApiDestinationCountExceedLimit);
-            final Boolean apiDestination = 
apiDestinationRepository.createApiDestination(eventApiDestinationDTO);
-            if (apiDestination) {
-                return eventApiDestinationDTO.getName();
-            }
-            return null;
-        } catch (Exception e) {
-            log.error("ApiDestinationService | createApiDestination | error", 
e);
-            throw new EventBridgeException(e);
+        final Boolean apiDestination = 
apiDestinationRepository.createApiDestination(eventApiDestinationDTO);
+        if (apiDestination) {
+            return eventApiDestinationDTO.getName();
         }
+        return null;
     }
 
     @Transactional(rollbackFor = Exception.class, propagation = 
Propagation.REQUIRED)
     public Boolean updateApiDestination(ApiDestinationDTO apiDestinationDTO) {
-        try {
-            if (checkApiDestination(apiDestinationDTO.getAccountId(), 
apiDestinationDTO.getName()) == null) {
-                throw new 
EventBridgeException(EventBridgeErrorCode.ApiDestinationNotExist, 
apiDestinationDTO.getName());
-            }
-            return 
apiDestinationRepository.updateApiDestination(apiDestinationDTO);
-        } catch (Exception e) {
-            log.error("ApiDestinationService | updateApiDestination | error", 
e);
-            throw new EventBridgeException(e);
+        if (checkApiDestination(apiDestinationDTO.getAccountId(), 
apiDestinationDTO.getName()) == null) {
+            throw new 
EventBridgeException(EventBridgeErrorCode.ApiDestinationNotExist, 
apiDestinationDTO.getName());
         }
+        return 
apiDestinationRepository.updateApiDestination(apiDestinationDTO);
     }
 
     public ApiDestinationDTO getApiDestination(String accountId, String 
apiDestinationName) {
-        try {
-            if (checkApiDestination(accountId, apiDestinationName) == null) {
-                throw new 
EventBridgeException(EventBridgeErrorCode.ApiDestinationNotExist, 
apiDestinationName);
-            }
-            return apiDestinationRepository.getApiDestination(accountId, 
apiDestinationName);
-        } catch (Exception e) {
-            log.error("ApiDestinationService | getApiDestination | error", e);
-            throw new EventBridgeException(e);
+        if (checkApiDestination(accountId, apiDestinationName) == null) {
+            throw new 
EventBridgeException(EventBridgeErrorCode.ApiDestinationNotExist, 
apiDestinationName);
         }
+        return apiDestinationRepository.getApiDestination(accountId, 
apiDestinationName);
     }
 
     public ApiDestinationDTO checkApiDestination(String accountId, String 
apiDestinationName) {
@@ -91,31 +77,20 @@ public class ApiDestinationService extends 
AbstractResourceService {
 
     @Transactional(rollbackFor = Exception.class, propagation = 
Propagation.REQUIRED)
     public Boolean deleteApiDestination(String accountId, String 
apiDestinationName) {
-        try {
-            if (checkApiDestination(accountId, apiDestinationName) == null) {
-                throw new 
EventBridgeException(EventBridgeErrorCode.ApiDestinationNotExist, 
apiDestinationName);
-            }
-            return apiDestinationRepository.deleteApiDestination(accountId, 
apiDestinationName);
-        } catch (Exception e) {
-            log.error("ApiDestinationService | deleteApiDestination | error", 
e);
-            throw new EventBridgeException(e);
+        if (checkApiDestination(accountId, apiDestinationName) == null) {
+            throw new 
EventBridgeException(EventBridgeErrorCode.ApiDestinationNotExist, 
apiDestinationName);
         }
+        return apiDestinationRepository.deleteApiDestination(accountId, 
apiDestinationName);
     }
 
-    public PaginationResult<List<ApiDestinationDTO>> 
listApiDestinations(String accountId, String apiDestinationName,
-        String nextToken,
-        int maxResults) {
-        try {
-            final List<ApiDestinationDTO> apiDestinationDTOS = 
apiDestinationRepository.listApiDestinations(accountId, apiDestinationName, 
nextToken, maxResults);
-            PaginationResult<List<ApiDestinationDTO>> result = new 
PaginationResult();
-            result.setData(apiDestinationDTOS);
-            result.setTotal(this.getApiDestinationCount(accountId));
-            result.setNextToken(String.valueOf(Integer.parseInt(nextToken) + 
maxResults));
-            return result;
-        } catch (Exception e) {
-            log.error("ApiDestinationService | listApiDestinations | error", 
e);
-            throw new EventBridgeException(e);
-        }
+    public PaginationResult<List<ApiDestinationDTO>> 
listApiDestinations(String accountId, String apiDestinationName, String 
nextToken,
+                                                                         int 
maxResults) {
+        final List<ApiDestinationDTO> apiDestinationDTOS = 
apiDestinationRepository.listApiDestinations(accountId, apiDestinationName, 
nextToken, maxResults);
+        PaginationResult<List<ApiDestinationDTO>> result = new 
PaginationResult();
+        result.setData(apiDestinationDTOS);
+        result.setTotal(this.getApiDestinationCount(accountId));
+        result.setNextToken(String.valueOf(Integer.parseInt(nextToken) + 
maxResults));
+        return result;
     }
 
     private int getApiDestinationCount(String accountId) {
diff --git 
a/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/model/connection/ConnectionService.java
 
b/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/model/connection/ConnectionService.java
index 5d6a056..52d92e2 100644
--- 
a/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/model/connection/ConnectionService.java
+++ 
b/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/model/connection/ConnectionService.java
@@ -64,107 +64,80 @@ public class ConnectionService extends 
AbstractResourceService {
 
     @Transactional(rollbackFor = Exception.class, propagation = 
Propagation.REQUIRED)
     public String createConnection(ConnectionDTO connectionDTO) {
-        try {
-            if 
(!CollectionUtils.isEmpty(checkConnection(connectionDTO.getAccountId(), 
connectionDTO.getConnectionName()))) {
-                throw new 
EventBridgeException(EventBridgeErrorCode.ConnectionAlreadyExist, 
connectionDTO.getConnectionName());
-            }
-            
super.checkQuota(this.getConnectionCount(connectionDTO.getAccountId()), 
EventBridgeConstants.CONNECTION_COUNT_LIMIT, ConnectionCountExceedLimit);
-            
checkNetworkType(connectionDTO.getNetworkParameters().getNetworkType());
-            if (connectionDTO.getAuthParameters() != null) {
-                
connectionDTO.setAuthParameters(setSecretData(connectionDTO.getAuthParameters(),
 connectionDTO.getAccountId(), connectionDTO.getConnectionName()));
-            }
-            if (connectionRepository.createConnection(connectionDTO)) {
-                if 
(NetworkTypeEnum.PRIVATE_NETWORK.getNetworkType().equals(connectionDTO.getNetworkParameters().getNetworkType()))
 {
-                    networkServiceAPI.createPrivateNetwork();
-                }
-                return connectionDTO.getConnectionName();
+        if 
(!CollectionUtils.isEmpty(checkConnection(connectionDTO.getAccountId(), 
connectionDTO.getConnectionName()))) {
+            throw new 
EventBridgeException(EventBridgeErrorCode.ConnectionAlreadyExist, 
connectionDTO.getConnectionName());
+        }
+        
super.checkQuota(this.getConnectionCount(connectionDTO.getAccountId()), 
EventBridgeConstants.CONNECTION_COUNT_LIMIT, ConnectionCountExceedLimit);
+        
checkNetworkType(connectionDTO.getNetworkParameters().getNetworkType());
+        if (connectionDTO.getAuthParameters() != null) {
+            
connectionDTO.setAuthParameters(setSecretData(connectionDTO.getAuthParameters(),
 connectionDTO.getAccountId(), connectionDTO.getConnectionName()));
+        }
+        if (connectionRepository.createConnection(connectionDTO)) {
+            if 
(NetworkTypeEnum.PRIVATE_NETWORK.getNetworkType().equals(connectionDTO.getNetworkParameters().getNetworkType()))
 {
+                networkServiceAPI.createPrivateNetwork();
             }
-        } catch (Exception e) {
-            log.error("ConnectionService | createConnection | error", e);
-            throw new EventBridgeException(e);
+            return connectionDTO.getConnectionName();
         }
         return null;
     }
 
     @Transactional(rollbackFor = Exception.class, propagation = 
Propagation.REQUIRED)
     public void deleteConnection(String accountId, String connectionName) {
-        try {
-            if (CollectionUtils.isEmpty(checkConnection(accountId, 
connectionName))) {
-                throw new 
EventBridgeException(EventBridgeErrorCode.ConnectionNotExist, connectionName);
-            }
-            if 
(!CollectionUtils.isEmpty(apiDestinationRepository.queryApiDestinationByConnectionName(accountId,
 connectionName))) {
-                throw new 
EventBridgeException(EventBridgeErrorCode.ConnectionBoundApiDestination, 
connectionName);
-            }
-            List<ConnectionDTO> connection = getConnection(accountId, 
connectionName);
-            ConnectionDTO connectionDTO = connection.get(0);
-            if 
(NetworkTypeEnum.PRIVATE_NETWORK.getNetworkType().equals(connectionDTO.getNetworkParameters().getNetworkType()))
 {
-                networkServiceAPI.deletePrivateNetwork();
-            }
-            connectionRepository.deleteConnection(accountId, connectionName);
-            if 
(secretManagerAPI.querySecretName(secretManagerAPI.getSecretName(accountId, 
connectionName))) {
-                
secretManagerAPI.deleteSecretName(secretManagerAPI.getSecretName(accountId, 
connectionName));
-            }
-        } catch (Exception e) {
-            log.error("ConnectionService | deleteConnection | error", e);
-            throw new EventBridgeException(e);
+        if (CollectionUtils.isEmpty(checkConnection(accountId, 
connectionName))) {
+            throw new 
EventBridgeException(EventBridgeErrorCode.ConnectionNotExist, connectionName);
+        }
+        if 
(!CollectionUtils.isEmpty(apiDestinationRepository.queryApiDestinationByConnectionName(accountId,
 connectionName))) {
+            throw new 
EventBridgeException(EventBridgeErrorCode.ConnectionBoundApiDestination, 
connectionName);
+        }
+        List<ConnectionDTO> connection = getConnection(accountId, 
connectionName);
+        ConnectionDTO connectionDTO = connection.get(0);
+        if 
(NetworkTypeEnum.PRIVATE_NETWORK.getNetworkType().equals(connectionDTO.getNetworkParameters().getNetworkType()))
 {
+            networkServiceAPI.deletePrivateNetwork();
+        }
+        connectionRepository.deleteConnection(accountId, connectionName);
+        if 
(secretManagerAPI.querySecretName(secretManagerAPI.getSecretName(accountId, 
connectionName))) {
+            
secretManagerAPI.deleteSecretName(secretManagerAPI.getSecretName(accountId, 
connectionName));
         }
     }
 
     @Transactional(rollbackFor = Exception.class, propagation = 
Propagation.REQUIRED)
     public void updateConnection(ConnectionDTO connectionDTO, String 
accountId) {
-        try {
-            if (CollectionUtils.isEmpty(checkConnection(accountId, 
connectionDTO.getConnectionName()))) {
-                throw new 
EventBridgeException(EventBridgeErrorCode.ConnectionNotExist, 
connectionDTO.getConnectionName());
-            }
-            
checkNetworkType(connectionDTO.getNetworkParameters().getNetworkType());
-            if (connectionDTO.getAuthParameters() != null) {
-                
connectionDTO.setAuthParameters(updateSecretData(connectionDTO.getAuthParameters(),
 accountId, connectionDTO.getConnectionName(), 
connectionDTO.getConnectionName()));
-            }
-            connectionRepository.updateConnection(connectionDTO);
-        } catch (Exception e) {
-            log.error("ConnectionService | updateConnection | error", e);
-            throw new EventBridgeException(e);
+        if (CollectionUtils.isEmpty(checkConnection(accountId, 
connectionDTO.getConnectionName()))) {
+            throw new 
EventBridgeException(EventBridgeErrorCode.ConnectionNotExist, 
connectionDTO.getConnectionName());
         }
+        
checkNetworkType(connectionDTO.getNetworkParameters().getNetworkType());
+        if (connectionDTO.getAuthParameters() != null) {
+            
connectionDTO.setAuthParameters(updateSecretData(connectionDTO.getAuthParameters(),
 accountId, connectionDTO.getConnectionName(), 
connectionDTO.getConnectionName()));
+        }
+        connectionRepository.updateConnection(connectionDTO);
     }
 
     public List<ConnectionDTO> getConnection(String accountId, String 
connectionName) {
-        try {
-            final List<ConnectionDTO> connectionDTO = 
connectionRepository.getConnection(accountId, connectionName);
-            if (connectionDTO == null) {
-                throw new 
EventBridgeException(EventBridgeErrorCode.ConnectionNotExist, connectionName);
-            }
-            return connectionDTO;
-        } catch (Exception e) {
-            log.error("ConnectionService | getConnection | error", e);
-            throw new EventBridgeException(e);
+        final List<ConnectionDTO> connectionDTO = 
connectionRepository.getConnection(accountId, connectionName);
+        if (connectionDTO == null) {
+            throw new 
EventBridgeException(EventBridgeErrorCode.ConnectionNotExist, connectionName);
         }
+        return connectionDTO;
     }
 
     public List<ConnectionDTO> checkConnection(String accountId, String 
connectionName) {
         return connectionRepository.getConnection(accountId, connectionName);
     }
 
-    public PaginationResult<List<ConnectionDTO>> listConnections(String 
accountId, String connectionName,
-        String nextToken, int maxResults) {
-        try {
-            List<ConnectionDTO> connectionDTOS = 
connectionRepository.listConnections(accountId, connectionName, nextToken, 
maxResults);
-            PaginationResult<List<ConnectionDTO>> result = new 
PaginationResult();
-            result.setData(connectionDTOS);
-            result.setTotal(this.getConnectionCount(accountId));
-            result.setNextToken(String.valueOf(Integer.parseInt(nextToken) + 
maxResults));
-            return result;
-        } catch (Exception e) {
-            log.error("ConnectionService | listConnections | error", e);
-            throw new EventBridgeException(e);
-        }
+    public PaginationResult<List<ConnectionDTO>> listConnections(String 
accountId, String connectionName, String nextToken, int maxResults) {
+        List<ConnectionDTO> connectionDTOS = 
connectionRepository.listConnections(accountId, connectionName, nextToken, 
maxResults);
+        PaginationResult<List<ConnectionDTO>> result = new PaginationResult();
+        result.setData(connectionDTOS);
+        result.setTotal(this.getConnectionCount(accountId));
+        result.setNextToken(String.valueOf(Integer.parseInt(nextToken) + 
maxResults));
+        return result;
     }
 
     public int getConnectionCount(String accountId) {
         return connectionRepository.getConnectionCount(accountId);
     }
 
-    private AuthParameters setSecretData(AuthParameters authParameters, String 
accountId,
-        String connectionName) throws Exception {
+    private AuthParameters setSecretData(AuthParameters authParameters, String 
accountId, String connectionName) {
         final BasicAuthParameters basicAuthParameters = 
authParameters.getBasicAuthParameters();
         final ApiKeyAuthParameters apiKeyAuthParameters = 
authParameters.getApiKeyAuthParameters();
         final OAuthParameters oauthParameters = 
authParameters.getOauthParameters();
@@ -178,23 +151,22 @@ public class ConnectionService extends 
AbstractResourceService {
             apiKeyAuthParameters.setApiKeyValue(secretName);
             return authParameters;
         }
-        final OAuthHttpParameters oauthHttpParameters = 
oauthParameters.getOauthHttpParameters();
-        if (oauthHttpParameters == null) {
-            throw new 
EventBridgeException(EventBridgeErrorCode.OauthHttpParametersEmpty);
+        if (oauthParameters != null) {
+            final OAuthHttpParameters oauthHttpParameters = 
oauthParameters.getOauthHttpParameters();
+            if (oauthHttpParameters != null) {
+                saveClientByKms(accountId, connectionName, oauthParameters);
+            }
         }
-        saveClientByKms(accountId, connectionName, oauthParameters);
         return authParameters;
     }
 
-    private void saveClientByKms(String accountId, String connectionName,
-        OAuthParameters oauthParameters) throws Exception {
+    private void saveClientByKms(String accountId, String connectionName, 
OAuthParameters oauthParameters) {
         OAuthParameters.ClientParameters clientParameters = 
oauthParameters.getClientParameters();
         
clientParameters.setClientSecret(secretManagerAPI.createSecretName(accountId, 
connectionName, new Gson().toJson(clientParameters)));
         oauthParameters.setClientParameters(clientParameters);
     }
 
-    private AuthParameters updateSecretData(AuthParameters authParameters, 
String accountId, String connectionName,
-        String name) throws Exception {
+    private AuthParameters updateSecretData(AuthParameters authParameters, 
String accountId, String connectionName, String name) {
         ConnectionDTO connection = 
connectionRepository.getConnectionByName(name);
         if (authParameters == null) {
             return null;
@@ -232,8 +204,7 @@ public class ConnectionService extends 
AbstractResourceService {
         return authParameters;
     }
 
-    private void updateClientByKms(String accountId, String connectionName, 
OAuthParameters oauthParameters,
-        ConnectionDTO connection) throws Exception {
+    private void updateClientByKms(String accountId, String connectionName, 
OAuthParameters oauthParameters, ConnectionDTO connection) {
         OAuthParameters.ClientParameters clientParameters = 
oauthParameters.getClientParameters();
         String clientSecretSecretValue = null;
         if (connection.getAuthParameters() != null && 
connection.getAuthParameters().getOauthParameters() != null) {
diff --git 
a/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/rpc/SecretManagerAPI.java
 
b/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/rpc/SecretManagerAPI.java
index 1935b60..cb2a8a8 100644
--- 
a/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/rpc/SecretManagerAPI.java
+++ 
b/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/rpc/SecretManagerAPI.java
@@ -19,9 +19,9 @@ package org.apache.rocketmq.eventbridge.domain.rpc;
 
 public interface SecretManagerAPI {
 
-    String createSecretName(String accountId, String connectionName, String 
secretData) throws Exception;
+    String createSecretName(String accountId, String connectionName, String 
secretData);
 
-    void deleteSecretName(String secretName) throws Exception;
+    void deleteSecretName(String secretName);
 
     String getSecretName(String accountId, String connectionName);
 
@@ -29,6 +29,5 @@ public interface SecretManagerAPI {
 
     Object getSecretValue(String secretName);
 
-    String updateSecretValue(String oldSecretName, String accountId, String 
connectionName, String key,
-        String value) throws Exception;
+    String updateSecretValue(String oldSecretName, String accountId, String 
connectionName, String key, String value);
 }
diff --git 
a/domain/src/test/java/org/apache/rocketmq/eventbridge/domain/service/ApiDestinationDTOServiceTest.java
 
b/domain/src/test/java/org/apache/rocketmq/eventbridge/domain/service/ApiDestinationServiceTest.java
similarity index 93%
rename from 
domain/src/test/java/org/apache/rocketmq/eventbridge/domain/service/ApiDestinationDTOServiceTest.java
rename to 
domain/src/test/java/org/apache/rocketmq/eventbridge/domain/service/ApiDestinationServiceTest.java
index 3d6dafc..ce9cc21 100644
--- 
a/domain/src/test/java/org/apache/rocketmq/eventbridge/domain/service/ApiDestinationDTOServiceTest.java
+++ 
b/domain/src/test/java/org/apache/rocketmq/eventbridge/domain/service/ApiDestinationServiceTest.java
@@ -24,8 +24,6 @@ import 
org.apache.rocketmq.eventbridge.domain.model.PaginationResult;
 import 
org.apache.rocketmq.eventbridge.domain.model.apidestination.ApiDestinationDTO;
 import 
org.apache.rocketmq.eventbridge.domain.model.apidestination.ApiDestinationService;
 import 
org.apache.rocketmq.eventbridge.domain.repository.ApiDestinationRepository;
-import org.apache.rocketmq.eventbridge.domain.rpc.NetworkServiceAPI;
-import org.apache.rocketmq.eventbridge.domain.rpc.SecretManagerAPI;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -39,16 +37,12 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
 
 @RunWith(MockitoJUnitRunner.class)
-public class ApiDestinationDTOServiceTest {
+public class ApiDestinationServiceTest {
 
     @InjectMocks
     private ApiDestinationService apiDestinationService;
     @Mock
     private ApiDestinationRepository apiDestinationRepository;
-    @Mock
-    private SecretManagerAPI secretManagerAPI;
-    @Mock
-    private NetworkServiceAPI networkServiceAPI;
 
     @Before
     public void testBefore() {
diff --git 
a/start/src/main/java/org/apache/rocketmq/eventbridge/filter/LogFilter.java 
b/start/src/main/java/org/apache/rocketmq/eventbridge/filter/LogFilter.java
new file mode 100644
index 0000000..dd9fd1f
--- /dev/null
+++ b/start/src/main/java/org/apache/rocketmq/eventbridge/filter/LogFilter.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.rocketmq.eventbridge.filter;
+
+import com.google.gson.Gson;
+import org.apache.rocketmq.eventbridge.config.EventBridgeConstants;
+import org.apache.rocketmq.eventbridge.exception.EventBridgeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.annotation.Order;
+import org.springframework.core.io.buffer.DataBuffer;
+import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.server.ServerWebExchange;
+import org.springframework.web.server.WebFilter;
+import org.springframework.web.server.WebFilterChain;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.channels.Channels;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+@Component
+@Order(value = 1)
+public class LogFilter implements WebFilter {
+    private static final Logger log = LoggerFactory.getLogger("accessLog");
+
+    @Override
+    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) 
{
+        ServerHttpRequestDecorator accessPermissionDecorator = new 
ServerHttpRequestDecorator(exchange.getRequest()) {
+            @Override
+            public Flux<DataBuffer> getBody() {
+                return super.getBody().doOnNext(dataBuffer -> {
+                    try {
+                        ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+                        
Channels.newChannel(byteArrayOutputStream).write(dataBuffer.asByteBuffer().asReadOnlyBuffer());
+                        String requestBody = new 
String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8);
+                        List<String> requestTraceIds = 
exchange.getRequest().getHeaders().get(EventBridgeConstants.REQUEST_TRACE_ID);
+                        String requestId = "";
+                        if (!CollectionUtils.isEmpty(requestTraceIds)) {
+                            requestId = requestTraceIds.get(0);
+                        }
+                        log.info("requestTraceId : {} | url : {} | 
requestParam : {} | requestMethod : {} | requestBody : {}",
+                                requestId,
+                                exchange.getRequest().getURI(),
+                                exchange.getRequest().getQueryParams(),
+                                exchange.getRequest().getMethodValue(),
+                                new Gson().toJson(requestBody));
+                    } catch (IOException e) {
+                        log.error("LoginFilter | filter => e ", e);
+                        throw new EventBridgeException(e);
+                    }
+                });
+            }
+        };
+        return 
chain.filter(exchange.mutate().request(accessPermissionDecorator).build());
+    }
+}
diff --git 
a/start/src/main/java/org/apache/rocketmq/eventbridge/handler/ExceptionHandler.java
 
b/start/src/main/java/org/apache/rocketmq/eventbridge/handler/ExceptionHandler.java
index 0ee024a..30fb5b4 100644
--- 
a/start/src/main/java/org/apache/rocketmq/eventbridge/handler/ExceptionHandler.java
+++ 
b/start/src/main/java/org/apache/rocketmq/eventbridge/handler/ExceptionHandler.java
@@ -20,11 +20,11 @@ package org.apache.rocketmq.eventbridge.handler;
 import com.google.common.net.MediaType;
 import com.google.gson.Gson;
 import io.netty.handler.codec.http.HttpHeaderNames;
-import java.nio.charset.StandardCharsets;
-import lombok.extern.slf4j.Slf4j;
 import org.apache.rocketmq.eventbridge.adapter.api.dto.BaseResponse;
 import 
org.apache.rocketmq.eventbridge.domain.common.exception.EventBridgeErrorCode;
 import org.apache.rocketmq.eventbridge.exception.EventBridgeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
 import org.springframework.core.annotation.Order;
 import org.springframework.core.io.buffer.DataBuffer;
@@ -36,17 +36,21 @@ import org.springframework.web.server.ServerWebExchange;
 import reactor.core.publisher.Mono;
 import reactor.ipc.netty.ByteBufMono;
 
+import java.nio.charset.StandardCharsets;
+
 @Component
 @Order(-1)
-@Slf4j
 public class ExceptionHandler implements ErrorWebExceptionHandler {
+
+    private static final Logger log = LoggerFactory.getLogger("accessLog");
+
     @Override
     public Mono<Void> handle(ServerWebExchange exchange, Throwable throwable) {
         ServerHttpResponse serverHttpResponse = exchange.getResponse();
         BaseResponse baseResponse = new BaseResponse();
         HttpStatus httpStatus = null;
         if (throwable instanceof EventBridgeException) {
-            EventBridgeException eventBridgeException = (EventBridgeException) 
throwable;
+            EventBridgeException eventBridgeException = 
(EventBridgeException)throwable;
             baseResponse.setCode(eventBridgeException.getCode());
             baseResponse.setMessage(eventBridgeException.getMessage());
             httpStatus = 
HttpStatus.resolve(eventBridgeException.getHttpCode());
diff --git a/start/src/main/resources/logback-spring.xml 
b/start/src/main/resources/logback-spring.xml
index 9dd7ae7..c86f339 100644
--- a/start/src/main/resources/logback-spring.xml
+++ b/start/src/main/resources/logback-spring.xml
@@ -39,6 +39,23 @@
         </encoder>
     </appender>
 
+    <appender name="ACCESS" 
class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <file>${log.path}/${app.name}/access.log</file>
+        <rollingPolicy 
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            
<fileNamePattern>${log.path}/${app.name}/access.%d{yyyy-MM-dd}.log</fileNamePattern>
+            <maxHistory>30</maxHistory>
+            <totalSizeCap>3GB</totalSizeCap>
+        </rollingPolicy>
+        <encoder>
+            <pattern>%d{yyyy-MM-dd 
HH:mm:ss.SSS}@@%X{traceId:-}@@%X{parentId:-}@@%X{spanId:-}@@[%thread]@@%level@@%logger{36}[%line]@@%msg%n</pattern>
+        </encoder>
+    </appender>
+
+    <logger name="accessLog" level="${log.level}" additivity="false">
+        <appender-ref ref="ACCESS"/>
+        <appender-ref ref="STDOUT"/>
+    </logger>
+
     <root level="${log.level}">
         <appender-ref ref="STDOUT"/>
         <appender-ref ref="PROJECT"/>


Reply via email to