spring core proxy : log trace v2 - concrete proxy
This commit is contained in:
@@ -2,6 +2,7 @@ package com.example.proxy;
|
||||
|
||||
import com.example.proxy.config.AppV1Config;
|
||||
import com.example.proxy.config.AppV2Config;
|
||||
import com.example.proxy.config.v1_proxy.ConcreteProxyConfig;
|
||||
import com.example.proxy.config.v1_proxy.InterfaceProxyConfig;
|
||||
import com.example.proxy.trace.logtrace.LogTrace;
|
||||
import com.example.proxy.trace.logtrace.ThreadLocalLogTrace;
|
||||
@@ -11,7 +12,8 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
//@Import({AppV1Config.class, AppV2Config.class})
|
||||
@Import(InterfaceProxyConfig.class)
|
||||
//@Import(InterfaceProxyConfig.class)
|
||||
@Import(ConcreteProxyConfig.class)
|
||||
@SpringBootApplication(scanBasePackages = "com.example.proxy.app")
|
||||
public class ProxyApplication {
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.example.proxy.config.v1_proxy;
|
||||
|
||||
import com.example.proxy.app.v2.OrderControllerV2;
|
||||
import com.example.proxy.app.v2.OrderRepositoryV2;
|
||||
import com.example.proxy.app.v2.OrderServiceV2;
|
||||
import com.example.proxy.config.v1_proxy.concrete_proxy.OrderControllerConcreteProxy;
|
||||
import com.example.proxy.config.v1_proxy.concrete_proxy.OrderRepositoryConcreteProxy;
|
||||
import com.example.proxy.config.v1_proxy.concrete_proxy.OrderServiceConcreteProxy;
|
||||
import com.example.proxy.trace.logtrace.LogTrace;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class ConcreteProxyConfig {
|
||||
|
||||
@Bean
|
||||
public OrderControllerV2 orderControllerV2(LogTrace logTrace) {
|
||||
OrderControllerV2 controllerImpl = new OrderControllerV2(orderServiceV2(logTrace));
|
||||
return new OrderControllerConcreteProxy(controllerImpl, logTrace);
|
||||
}
|
||||
@Bean
|
||||
public OrderServiceV2 orderServiceV2(LogTrace logTrace) {
|
||||
OrderServiceV2 serviceImpl = new OrderServiceV2(orderRepositoryV2(logTrace));
|
||||
return new OrderServiceConcreteProxy(serviceImpl, logTrace);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public OrderRepositoryV2 orderRepositoryV2(LogTrace logTrace) {
|
||||
OrderRepositoryV2 repositoryImpl = new OrderRepositoryV2();
|
||||
return new OrderRepositoryConcreteProxy(repositoryImpl, logTrace);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.example.proxy.config.v1_proxy.concrete_proxy;
|
||||
|
||||
import com.example.proxy.app.v2.OrderControllerV2;
|
||||
import com.example.proxy.trace.TraceStatus;
|
||||
import com.example.proxy.trace.logtrace.LogTrace;
|
||||
|
||||
public class OrderControllerConcreteProxy extends OrderControllerV2 {
|
||||
|
||||
private final OrderControllerV2 target;
|
||||
private final LogTrace logTrace;
|
||||
|
||||
public OrderControllerConcreteProxy(OrderControllerV2 target, LogTrace logTrace) {
|
||||
super(null);
|
||||
this.target = target;
|
||||
this.logTrace = logTrace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String request(String itemId) {
|
||||
TraceStatus status = null;
|
||||
try {
|
||||
status = logTrace.begin("OrderController.request()");
|
||||
String result = target.request(itemId);
|
||||
logTrace.end(status);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
logTrace.exception(status, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noLog() {
|
||||
return target.noLog();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.example.proxy.config.v1_proxy.concrete_proxy;
|
||||
|
||||
import com.example.proxy.app.v2.OrderRepositoryV2;
|
||||
import com.example.proxy.trace.TraceStatus;
|
||||
import com.example.proxy.trace.logtrace.LogTrace;
|
||||
|
||||
public class OrderRepositoryConcreteProxy extends OrderRepositoryV2 {
|
||||
|
||||
private final OrderRepositoryV2 target;
|
||||
private final LogTrace logTrace;
|
||||
|
||||
public OrderRepositoryConcreteProxy(OrderRepositoryV2 target, LogTrace logTrace) {
|
||||
this.target = target;
|
||||
this.logTrace = logTrace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(String itemId) {
|
||||
TraceStatus status = null;
|
||||
try {
|
||||
status = logTrace.begin("OrderRepository.request()");
|
||||
target.save(itemId);
|
||||
logTrace.end(status);
|
||||
} catch (Exception e) {
|
||||
logTrace.exception(status, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.example.proxy.config.v1_proxy.concrete_proxy;
|
||||
|
||||
import com.example.proxy.app.v2.OrderServiceV2;
|
||||
import com.example.proxy.trace.TraceStatus;
|
||||
import com.example.proxy.trace.logtrace.LogTrace;
|
||||
|
||||
public class OrderServiceConcreteProxy extends OrderServiceV2 {
|
||||
|
||||
private final OrderServiceV2 target;
|
||||
private final LogTrace logTrace;
|
||||
|
||||
public OrderServiceConcreteProxy(OrderServiceV2 target, LogTrace logTrace) {
|
||||
super(null);
|
||||
this.target = target;
|
||||
this.logTrace = logTrace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void orderItem(String itemId) {
|
||||
TraceStatus status = null;
|
||||
try {
|
||||
status = logTrace.begin("OrderService.orderItem()");
|
||||
target.orderItem(itemId);
|
||||
logTrace.end(status);
|
||||
} catch (Exception e) {
|
||||
logTrace.exception(status, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user