77import tech .dbgsoftware .easyrest .actors .Signal ;
88import tech .dbgsoftware .easyrest .actors .remote .model .RemoteInvokeObject ;
99import tech .dbgsoftware .easyrest .actors .response .ResponseProcessActor ;
10+ import tech .dbgsoftware .easyrest .aop .customer .CustomInjection ;
1011import tech .dbgsoftware .easyrest .ioc .utils .BeanOperationUtils ;
1112import tech .dbgsoftware .easyrest .model .HttpEntity ;
1213import tech .dbgsoftware .easyrest .model .ResponseEntity ;
@@ -23,22 +24,22 @@ public Receive createReceive() {
2324 Method method = httpEntity .getMethod ();
2425 Class <?> controller = httpEntity .getController ();
2526 if (method .getReturnType ().getName ().equalsIgnoreCase (Void .class .getSimpleName ())) {
26- invokeMethod (method , controller , httpEntity .getArgs (), null );
27+ invokeMethod (method , controller , httpEntity .getArgs (), null , httpEntity );
2728 httpEntity .setResponseEntity (ResponseEntity .buildOkResponse ());
2829 } else if (method .getReturnType ().equals (ResponseEntity .class )) {
29- httpEntity .setResponseEntity ((ResponseEntity ) invokeMethod (method , controller , httpEntity .getArgs (), null ));
30+ httpEntity .setResponseEntity ((ResponseEntity ) invokeMethod (method , controller , httpEntity .getArgs (), null , httpEntity ));
3031 } else {
31- httpEntity .setResponseEntity (ResponseEntity .buildBaseResponse (invokeMethod (method , controller , httpEntity .getArgs (), null )));
32+ httpEntity .setResponseEntity (ResponseEntity .buildBaseResponse (invokeMethod (method , controller , httpEntity .getArgs (), null , httpEntity )));
3233 }
3334 ActorFactory .createActor (ResponseProcessActor .class ).tell (httpEntity , ActorRef .noSender ());
3435 } catch (Exception e ) {
3536 LogUtils .error (e .getMessage (), e );
36- httpEntity .addError (e );
37+ httpEntity .addError (e . getCause () );
3738 ActorFactory .createActor (ExceptionHandleActor .class ).tell (httpEntity , ActorRef .noSender ());
3839 }
3940 })).match (RemoteInvokeObject .class , (remoteInvokeObject -> {
4041 try {
41- Object result = invokeMethod (remoteInvokeObject .getMethod (), remoteInvokeObject .getImplClass (), remoteInvokeObject .getArgs (), remoteInvokeObject .getInvokeBeanName ());
42+ Object result = invokeMethod (remoteInvokeObject .getMethod (), remoteInvokeObject .getImplClass (), remoteInvokeObject .getArgs (), remoteInvokeObject .getInvokeBeanName (), null );
4243 if (remoteInvokeObject .getMethod ().getReturnType ().getName ().equalsIgnoreCase (Void .class .getSimpleName ())) {
4344 remoteInvokeObject .setResult (ResponseEntity .buildOkResponse ());
4445 } else {
@@ -52,20 +53,30 @@ public Receive createReceive() {
5253 })).build ();
5354 }
5455
55- private Object invokeMethod (Method method , Class <?> controller , Object [] args , String invokeBeanName ) throws Exception {
56+ private Object invokeMethod (Method method , Class <?> controller , Object [] args , String invokeBeanName , HttpEntity httpEntity ) throws Exception {
5657 if (args .length > 0 ) {
5758 if (invokeBeanName == null || invokeBeanName .equalsIgnoreCase ("null" )) {
59+ invokePerCheck (BeanOperationUtils .getBean (controller ), httpEntity );
5860 return method .invoke (BeanOperationUtils .getBean (controller ), args );
5961 } else {
62+ invokePerCheck (BeanOperationUtils .getBean (invokeBeanName , controller ), httpEntity );
6063 return method .invoke (BeanOperationUtils .getBean (invokeBeanName , controller ), args );
6164 }
6265 } else {
6366 if (invokeBeanName == null || invokeBeanName .equalsIgnoreCase ("null" )) {
67+ invokePerCheck (BeanOperationUtils .getBean (controller ), httpEntity );
6468 return method .invoke (BeanOperationUtils .getBean (controller ));
6569 } else {
70+ invokePerCheck (BeanOperationUtils .getBean (invokeBeanName , controller ), httpEntity );
6671 return method .invoke (BeanOperationUtils .getBean (invokeBeanName , controller ));
6772 }
6873 }
6974 }
7075
76+ private void invokePerCheck (Object classz , HttpEntity httpEntity ) throws Exception {
77+ if (httpEntity != null && classz instanceof CustomInjection ) {
78+ CustomInjection .class .getMethods ()[0 ].invoke (classz , httpEntity );
79+ }
80+ }
81+
7182}
0 commit comments