Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access to the returning Object instance of an advised method
    text
    copied!<p>I'm using spring AOP to advice my services methods and especially ones returning an object, I want to have access to that object during advice processing.</p> <p>My configuration is working fine, no problems with that.</p> <p>Here's the signature of the adviced method, method returns a new instance based on data within method argument, so argument is unusable</p> <pre><code>@Traceable(ETraceableMessages.SAUVER_APPORTEUR) public ElementNiveauUn save(ElementNiveauUn apporteur) throws ATPBusinessException { String identifiant = instanceService.sauverInstance(null, apporteur); List&lt;String&gt; extensions = new ArrayList&lt;String&gt;(); extensions.add(ELEMENTSCONTENUS); extensions.add(TYPEELEMENT); extensions.add(VERSIONING); extensions.add(PARAMETRAGES); extensions.add(PARAMETRAGES + "." + PARAMETRES); return (ElementNiveauUn ) instanceService.lireInstanceParId(identifiant, extensions.toArray(new String[]{})); } </code></pre> <p>Here's what I'm wondering to do</p> <pre><code>@Around(value = "execution(elementNiveauUn fr.generali.nova.atp.service.metier.impl.*.*(..)) &amp;&amp; @annotation(traceable) &amp;&amp; args(element)", argNames = "element,traceable") public void serviceLayerTraceAdviceBasedElementInstanceAfter2(final ProceedingJoinPoint pjp, final ElementNiveauUn element, final Traceable traceable) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { // current user String currentUserId = findCurrentUserId(); // wether user is found or not boolean isUserFound = StringUtils.isBlank(currentUserId); // retrieve the oid of the returning type MethodSignature signature = (MethodSignature ) pjp.getSignature(); Class&lt;ElementNiveauUn&gt; returnType = signature.getReturnType(); Method[] methods = returnType.getMethods(); Method method = returnType.getMethod("getOid", (Class&lt; ? &gt;[] ) null); String oid = (String ) method.invoke(null, (Object[] ) null); // log to database simpleTraceService.trace(element.getOid(), element.getVersioning().toString(), traceable.value(), isUserFound ? UTILISATEUR_NON_TROUVE : currentUserId); } </code></pre> <p>My problem is that this line of code</p> <pre><code>Class&lt;ElementNiveauUn&gt; returnType = signature.getReturnType(); </code></pre> <p>permits me to have access to the returning type not to the instance</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload