java


Adding Response Header using AspectJ spring


I'm trying to add a response header to all the responses in my java application, to do that I'm using AspectJ.
In other words, what I want to do is, in the moment before the Response is being returned (and before building it) I want to add a header response so by adding the #PointCut and #AfterReturning I try to catch the response in order to add the header
The problem is I tried to debug but it dosen't reach the aspect, maybe the #PointCut executtion syntax isn't good ??
and is using #AfterReturning helps me ?
Thanks for the help, Jay
here's my code :
Responses to the client are returned in that way:
public Response getCustomer(...) {
...
return Response.ok(costumers).build();
}
Aspect class:
#Aspect
public class MyAspect {
#AfterReturning(
pointcut="execution(public Response *.*(..)",
returning="response")
public void updateStatisticsResponseHeader(JoinPoint joinPoint, Object response) {
long longEndTime = System.currentTimeMillis();
Response resp1 = (Response) response;
Object startTime = resp1.getMetadata().get("start-time");
long longStartTime = (long)startTime;
long totalTime = longEndTime - longStartTime;
Response.ResponseBuilder responseBuilder = Response.fromResponse(resp1);
responseBuilder.header("total-time",String.valueOf(totalTime));
responseBuilder.build();
}
}
beans.xml:
<bean id="MyAspect" class="com.project.aspect.MyAspect"/>

Related Links

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. >
How to tell if a players inventory is full - Minecraft
How can I join 2 XML in 1 XSL
Display And Use Information From A DownloadTask In Android Studio
Spring security how do admin perform every action which comes after (/admin/**) just using 1 intercept url
Reader for MIME media type text/html; charset=UTF-8 was not found
Spring Cloud Config in web application
How to create generic DAO that delivers crud operation without the need to extend it by custom DAO that doesn't deliver others methods
Reflection Config Loading
Spark 2.0.0 Arrays.asList not working - incompatible types
Unable to execute Mysql query using DButils and Datasource
Using jmh to benchmark code without creating separate maven project
Get the number of inputs and outputs of MapReduce in Java
MS SQL script generating different DDL on different machine
spring-boot-devtools reload of multi-module maven project changes
HashMap dont stay stable in android

Categories

HOME
log4j
ionic-framework
asp.net-core
c#-4.0
smarty
session
microservices
fsm
ckeditor
uber-api
add
iggrid
session-variables
etl
zend-framework3
spring-tool-suite
iolanguage
facebook-page
pugjs
lldb
clickonce
accessor
core-text
bootstrap-tour
hammerspoon
trading
p-value
facebook-access-token
linkerd
opentype
objectanimator
google-cloud-endpoints-v2
pdb
mozilla
rotational-matrices
retina-display
android-browser
service-discovery
jna
texmaker
node-sass
google-datalayer
termination
python-c-api
dandelion
recursive-datastructures
elgg
feeds
mako
account-kit
quartz-composer
eventkit
setuptools
rotativa
database-optimization
impresspages
gridview-sorting
multiple-regression
connect-by
simplewebrtc
lua-5.1
sdf
itextpdf
vhd
marching-cubes
spidermonkey
iis-arr
wyam
varargs
unity3d-gui
oberon
android-nested-fragment
id3v2
internet-connection
document-classification
poller
android-2.2-froyo
intentservice
file-locking
gridcontrol
chronoforms
random-seed
ember-app-kit
flashvars
tinn-r
labwindows
ocx
appconkit
enter
netbeans-6.9
assembly-loading
work-stealing
nsdatecomponents
stage
infobox
invite
javax.script
gamequery
castle-monorail
rescale
mdac
rtml

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App