List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs
Object[] getArgs();
From source file:org.cruk.genologics.api.cache.GenologicsAPICacheTest.java
License:Open Source License
@Test public void testLoadOrRetrieveWithOverride() throws Throwable { checkCredentialsSet();//from w w w . j a v a 2s . co m cacheAspect.setStatefulBehaviour(CacheStatefulBehaviour.LATEST); cacheAspect.getCache(Artifact.class).removeAll(); String base = api.getServerApiAddress(); Signature jpSig = createSignatureMock(); Artifact a1 = new Artifact(); a1.setUri(new URI(base + "/artifacts/2-1771911?state=1294907")); a1.setLimsid("2-1771911"); a1.setQCFlag(QCFlag.FAILED); Object[] a1args = { a1.getUri(), a1.getClass() }; ProceedingJoinPoint pjp1 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp1.getArgs()).andReturn(a1args).times(3); EasyMock.expect(pjp1.getSignature()).andReturn(jpSig).times(0, 1); EasyMock.expect(pjp1.proceed()).andReturn(a1).once(); EasyMock.replay(pjp1, jpSig); Object returned = cacheAspect.retrieve(pjp1); EasyMock.verify(pjp1, jpSig); assertSame("Did not return a1", a1, returned); // With an earlier state, it would normally return the same object. Object[] a2args = { base + "/artifacts/2-1771911?state=1101002", a1.getClass() }; jpSig = createSignatureMock(); ProceedingJoinPoint pjp2 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp2.getArgs()).andReturn(a2args).times(3); EasyMock.replay(pjp2, jpSig); returned = cacheAspect.retrieve(pjp2); EasyMock.verify(pjp2, jpSig); assertSame("Did not return a1", a1, returned); // With an override, we should get an equivalent object back but with a different state. Artifact a3 = new Artifact(); a3.setUri(new URI(base + "/artifacts/2-1771911?state=1101002")); a3.setLimsid("2-1771911"); a3.setQCFlag(QCFlag.PASSED); Object[] a3aargs = { CacheStatefulBehaviour.EXACT }; Object[] a3bargs = { base + "/artifacts/2-1771911?state=1101002", a1.getClass() }; jpSig = createSignatureMock(); ProceedingJoinPoint pjp3a = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp3a.getArgs()).andReturn(a3aargs).once(); EasyMock.expect(pjp3a.proceed()).andReturn(null).once(); ProceedingJoinPoint pjp3b = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp3b.getArgs()).andReturn(a3bargs).times(3); EasyMock.expect(pjp3b.getSignature()).andReturn(jpSig).times(0, 1); EasyMock.expect(pjp3b.proceed()).andReturn(a3).once(); JoinPoint pjp3c = EasyMock.createStrictMock(JoinPoint.class); EasyMock.expect(pjp3c.getSignature()).andReturn(jpSig).once(); EasyMock.replay(pjp3a, pjp3b, pjp3c, jpSig); cacheAspect.overrideBehaviour(pjp3a); returned = cacheAspect.retrieve(pjp3b); cacheAspect.resetBehaviour(pjp3c); EasyMock.verify(pjp3a, pjp3b, pjp3c, jpSig); assertSame("Did not return a3", a3, returned); }
From source file:org.cruk.genologics.api.cache.RestCallTrackingAspect.java
License:Open Source License
public Object getForObject(ProceedingJoinPoint pjp) throws Throwable { if (!enabled) { return pjp.proceed(); }/* w ww . ja v a2s .co m*/ Object uri = pjp.getArgs()[0]; final String key = uri.toString(); Object returned = pjp.proceed(); boolean isBatch = returned.getClass().getAnnotation(GenologicsBatchRetrieveResult.class) != null; boolean links = Links.class.isAssignableFrom(returned.getClass()); listCache(); if (!isBatch && !links && !isSearch(key) && !ArrayUtils.contains(allowedUris, key)) { listCache(); Assert.fail("Not allowed to fetch " + key + ". Should already be in the cache."); } return returned; }
From source file:org.cruk.genologics.api.cache.RestCallTrackingAspect.java
License:Open Source License
public ResponseEntity<?> getForEntity(ProceedingJoinPoint pjp) throws Throwable { if (!enabled) { return (ResponseEntity<?>) pjp.proceed(); }/*from w ww .j a v a 2s .c o m*/ Object uri = pjp.getArgs()[0]; final String key = uri.toString(); ResponseEntity<?> response = (ResponseEntity<?>) pjp.proceed(); Object returned = response.getBody(); boolean isBatch = returned.getClass().getAnnotation(GenologicsBatchRetrieveResult.class) != null; boolean links = Links.class.isAssignableFrom(returned.getClass()); if (!isBatch && !links && !isSearch(key) && !ArrayUtils.contains(allowedUris, key)) { listCache(); Assert.fail("Not allowed to fetch " + key + ". Should already be in the cache."); } return response; }
From source file:org.cruk.genologics.api.debugging.HttpClientTimingAspect.java
License:Open Source License
/** * Join point that, if the logging is set to DEBUG, will report on the * call made with the HttpClient and the time taken to get a response. * * @param pjp The AspectJ join point object. One of the arguments in * this object must be the HttpMethod being invoked. * * @return The result of proceeding with the join point. * * @throws Throwable if there is any failure. * * @see HttpClient#execute(HttpUriRequest) *//*from w ww. java2s . c o m*/ public Object timeCall(ProceedingJoinPoint pjp) throws Throwable { if (!logger.isDebugEnabled()) { return pjp.proceed(); } String uri = "<no url>"; String method = "<unknown>"; for (Object arg : pjp.getArgs()) { if (arg instanceof HttpUriRequest) { HttpUriRequest httpRequest = (HttpUriRequest) arg; uri = httpRequest.getURI().toString(); method = httpRequest.getMethod(); break; } } long startTime = System.currentTimeMillis(); try { return pjp.proceed(); } finally { long endTime = System.currentTimeMillis(); double timeTaken = (endTime - startTime) / 1000.0; logger.debug("HTTP {} call to {} took {} seconds.", method, uri, timeTaken); } }
From source file:org.cruk.genologics.api.debugging.RestClientSnoopingAspect.java
License:Open Source License
/** * Join point for the rest template's {@code get} operations. * Logs the URI being fetched and the reply received. * * @param pjp The AspectJ join point object. * * @return The reply object./* w ww.ja v a 2 s . c om*/ * * @throws Throwable if there is any failure from the operation. * This is also logged if logging is set to DEBUG. * * @see RestTemplate#getForEntity(java.net.URI, Class) * @see RestTemplate#getForObject(java.net.URI, Class) */ public Object checkGet(ProceedingJoinPoint pjp) throws Throwable { Object uri = pjp.getArgs()[0]; Class<?> type = (Class<?>) pjp.getArgs()[1]; if (logger.isDebugEnabled()) { logger.debug("Requesting a {} with {} from {}", ClassUtils.getShortClassName(type), pjp.getSignature().getName(), uri); } try { Object reply = pjp.proceed(); if (logger.isDebugEnabled()) { displayAfter(reply); } return reply; } catch (Throwable e) { fail(e); throw e; } }
From source file:org.cruk.genologics.api.debugging.RestClientSnoopingAspect.java
License:Open Source License
/** * Join point for the rest template's {@code put} and {@code post} operations. * Logs the XML being sent and the reply received. * * @param pjp The AspectJ join point object. * * @return The reply object.//from w w w. j a v a 2s .c o m * * @throws Throwable if there is any failure from the operation. * This is also logged if logging is set to DEBUG. * * @see RestTemplate#put(java.net.URI, Object) * @see RestTemplate#postForEntity(java.net.URI, Object, Class) * @see RestTemplate#postForObject(java.net.URI, Object, Class) */ public Object checkPutOrPost(ProceedingJoinPoint pjp) throws Throwable { Object uri = pjp.getArgs()[0]; Object request = pjp.getArgs()[1]; if (logger.isDebugEnabled()) { logger.debug("Calling {} to {}", pjp.getSignature().getName(), uri); displayBefore(request); } try { Object reply = pjp.proceed(); if (logger.isDebugEnabled()) { displayAfter(reply); } return reply; } catch (Throwable e) { fail(e); throw e; } }
From source file:org.cruk.genologics.api.debugging.RestClientSnoopingAspect.java
License:Open Source License
/** * Join point for the rest template's {@code exchange} operations. * Logs the XML being sent and the reply received. * * @param pjp The AspectJ join point object. * * @return The reply object.//from w w w. j av a 2 s . co m * * @throws Throwable if there is any failure from the operation. * This is also logged if logging is set to DEBUG. * * @see RestTemplate#exchange(java.net.URI, HttpMethod, HttpEntity, Class) */ public Object checkExchange(ProceedingJoinPoint pjp) throws Throwable { Object uri = pjp.getArgs()[0]; HttpMethod method = (HttpMethod) pjp.getArgs()[1]; HttpEntity<?> entity = (HttpEntity<?>) pjp.getArgs()[2]; Object request = entity.getBody(); if (logger.isDebugEnabled()) { logger.debug("Calling {} via {} to {}", pjp.getSignature().getName(), method, uri); displayBefore(request); } try { Object reply = pjp.proceed(); if (logger.isDebugEnabled()) { displayAfter(reply); } return reply; } catch (Throwable e) { fail(e); throw e; } }
From source file:org.cruk.genologics.api.debugging.RestClientSnoopingAspect.java
License:Open Source License
/** * Join point for the rest template's {@code exchange} operations. * Logs the URI being deleted./* ww w . jav a 2 s. c o m*/ * * @param pjp The AspectJ join point object. * * @return The reply object. * * @throws Throwable if there is any failure from the operation. * This is also logged if logging is set to DEBUG. * * @see RestTemplate#delete(java.net.URI) */ public Object checkDelete(ProceedingJoinPoint pjp) throws Throwable { Object uri = pjp.getArgs()[0]; if (logger.isDebugEnabled()) { logger.debug("Deleting with {} from {}", pjp.getSignature().getName(), uri); } try { return pjp.proceed(); } catch (Throwable e) { fail(e); throw e; } }
From source file:org.cybercat.automation.core.DataProviderAspect.java
License:Apache License
public Object applyData(ProceedingJoinPoint pjp) throws AutomationFrameworkException { String methodName = pjp.getSignature().getName(); Method[] methods = pjp.getTarget().getClass().getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(methodName)) { System.out.println("found"); try { Object[] arg = createData(methods[i], pjp.getArgs()); return pjp.proceed(arg); } catch (Throwable e) { throw new PageObjectException(e); }//from w w w .j av a 2s. co m } } return null; }
From source file:org.cybercat.automation.core.SoapServicesAspect.java
License:Apache License
public Object invoke(ProceedingJoinPoint pjp) throws Throwable { if (pjp.getTarget() instanceof SoapService) { SoapService service = (SoapService) pjp.getTarget(); ISessionManager session = service.getSoapSession(); //set Session session.putCookieSnapshot();// w ww . j a v a2 s. c o m Object result = pjp.proceed(this.before(this.getMethod(pjp), pjp.getArgs(), pjp.getTarget())); //get Session session.makeCookieSnapshot(); return result; } else { return pjp.proceed(); } }