added WebScriptContext request scope support
This commit is contained in:
parent
6e7b5311f1
commit
74635514fe
@ -0,0 +1,50 @@
|
|||||||
|
package com.inteligr8.alfresco.annotations.aspect;
|
||||||
|
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.extensions.webscripts.WebScript;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||||
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
|
import com.inteligr8.alfresco.annotations.context.WebScriptContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This aspect captures the WebScript execution context.
|
||||||
|
*/
|
||||||
|
@Aspect
|
||||||
|
public class WebScriptAspect {
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
private ThreadLocal<WebScriptContext> context = new ThreadLocal<>();
|
||||||
|
|
||||||
|
@Pointcut("execution(public void org.springframework.extensions.webscripts.WebScript.execute(..))")
|
||||||
|
public void isWebScriptExecute() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Around("isWebScriptExecute()")
|
||||||
|
public Object execute(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
this.logger.trace("execute({})", joinPoint);
|
||||||
|
|
||||||
|
WebScript ws = (WebScript) joinPoint.getTarget();
|
||||||
|
WebScriptRequest req = (WebScriptRequest) joinPoint.getArgs()[0];
|
||||||
|
WebScriptResponse res = (WebScriptResponse) joinPoint.getArgs()[1];
|
||||||
|
this.context.set(new WebScriptContext(ws, req, res));
|
||||||
|
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Scope(WebApplicationContext.SCOPE_REQUEST)
|
||||||
|
public WebScriptContext getContext() {
|
||||||
|
return this.context.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.inteligr8.alfresco.annotations.context;
|
||||||
|
|
||||||
|
import org.springframework.extensions.webscripts.WebScript;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||||
|
|
||||||
|
public class WebScriptContext {
|
||||||
|
|
||||||
|
private final WebScript webscript;
|
||||||
|
private final WebScriptRequest request;
|
||||||
|
private final WebScriptResponse response;
|
||||||
|
|
||||||
|
public WebScriptContext(WebScript webscript, WebScriptRequest request, WebScriptResponse response) {
|
||||||
|
this.webscript = webscript;
|
||||||
|
this.request = request;
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebScript getWebscript() {
|
||||||
|
return webscript;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebScriptRequest getRequest() {
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebScriptResponse getResponse() {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -13,5 +13,7 @@
|
|||||||
<aspect name="com.inteligr8.alfresco.annotations.aspect.NodeTypeAspect" />
|
<aspect name="com.inteligr8.alfresco.annotations.aspect.NodeTypeAspect" />
|
||||||
<aspect name="com.inteligr8.alfresco.annotations.aspect.NodeAspectAspect" />
|
<aspect name="com.inteligr8.alfresco.annotations.aspect.NodeAspectAspect" />
|
||||||
<aspect name="com.inteligr8.alfresco.annotations.aspect.ChildIsPrimaryAspect" />
|
<aspect name="com.inteligr8.alfresco.annotations.aspect.ChildIsPrimaryAspect" />
|
||||||
|
|
||||||
|
<aspect name="com.inteligr8.alfresco.annotations.aspect.WebScriptAspect" />
|
||||||
</aspects>
|
</aspects>
|
||||||
</aspectj>
|
</aspectj>
|
Loading…
x
Reference in New Issue
Block a user