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

Finding the range of ints in a scanner
why i can interchange field values inside a class using class reference but can't interchange the references themselves
Is it okay to inherit classes in java even if it is not meant for that job
BlackBerry - get error code 411
how to create draggable toggle button in Android
Permutation of a 2 dimensional arraylist
Cast a String object to XMLNode object
how to resolve eclipse error Source not found
Can Mirth send JavaBeans on JMS?
How are Java interfaces used? [closed]
Using a external jar. No suitable driver found for jdbc:sqlserver
Java synchronizing a method in a class
Hibernate : refresh on detached object - weird behavior
Java program Not running in Eclipse [duplicate]
Make Graphics from JPanel visible outside JPanel
stdint.h for Java? [duplicate]

Categories

HOME
arduino-uno
vim
hive
openstack
fluentd
drivers
path-finding
onedrive
rsyslog
sharepoint-designer
multiple-records
pheatmap
nano-server
windows-phone-7
orchardcms
django-simple-history
after-effects
flux
google-cloud-speech
lldb
tibco-mdm
blazemeter
crystal-reports-2010
qhull
applozic
ping
skia
preg-match
binary-data
ecto
fog
vsts-build-task
android-kernel
c11
android-fingerprint-api
mime
import-from-excel
websphere-mq-fte
powercli
tropo
diagnostics
lift-json
np-complete
r-forge
iso8601
gnome-shell-extensions
instant
underscore.js-templating
django-debug-toolbar
master-slave
hover-over
pickadate
yaws
cloudbees
phpcas
reactive-banana
intel-fortran
ionic
microbenchmark
system32
angular-local-storage
web-controls
facebook-graph-api-v2.4
device-manager
preferences
bitcoinj
zend-route
hyprlinkr
mysqltuner
jmapviewer
google-cloud-save
netdna-api
gnu-prolog
qt-jambi
hirefire
coercion
cinema-4d
servicehost
gdlib
sortable-tables
getresponsestream
firefox-5
web-architecture
microsoft-virtualization
django-notification
wsdl.exe
ntvdm.exe

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