0

I am using Spring. I have an several endpoints in my application. Basically, each endpoint return a different object. The application consists in several layers. It is important to us , no matter where an error occurs , to propagate the errors to the caller of the endpoints. Our approach It is to throw an exception where the error happens , and it should be caught up in the endpoint , and the endpoint should change the status codes of the response according to the information in the exception. We catch up the exception, because we don't want to throw soap faults to the caller

we have come to a point in the architecture, we don't want the endpoint to manage the exception. We think t should be done in some kind of interceptor or by AOP. The important It is that at that "outer exception handling component" I could get the exception fully and its attribute and based on that , no matter , what endpoint was called, get the return type object of the endpoint and return it by filling some appropriate fields based on the exception, possibly by some java reflection

My first approach was to use a SOAP interceptor, but I think it is limited according to what I need. I am doing research on AOP , any ideas?

Deibys
  • 619
  • 3
  • 9
  • 18

1 Answers1

0

In my opinion this is a perfect scenario for AOP. But where is the problem ? :) You can create an Aspect of type @Around on your service methods (not end point) and then call joinPoint.proceed() inside a try catch block. Catch the exception and return what you want :P By using AOP API you can check what should be the return type, the arguments .. basically everything you need :)

Marek Raki
  • 3,056
  • 3
  • 27
  • 50
  • Thanks a lot! Let me ask you something else...Is it possible to have two or @Around aspects that matches the same method? What is the execution order ? Can I get the type of object the method returns from the jointPoint ? – Deibys Apr 04 '14 at 18:15
  • yes, it is. You have @Order annotation for doing that. But I have never checked how it works. You have to check it on your own :) – Marek Raki Apr 04 '14 at 18:18
  • thxs! How about getting the type of object the method returns from the jointPoint ? – Deibys Apr 04 '14 at 18:22
  • MethodSignature signature = (MethodSignature) joinPoint.getSignature() signature .getReturnType; something like that. I don't have any way to check it now. – Marek Raki Apr 04 '14 at 18:25
  • Here you have a very similar case: http://stackoverflow.com/questions/21275819/how-to-get-a-methods-annotation-value-from-a-proceedingjoinpoint – Marek Raki Apr 04 '14 at 18:35