diff --git a/corant-context/src/main/java/org/corant/context/ComponentManager.java b/corant-context/src/main/java/org/corant/context/ComponentManager.java index f606212df..6f6a74002 100644 --- a/corant-context/src/main/java/org/corant/context/ComponentManager.java +++ b/corant-context/src/main/java/org/corant/context/ComponentManager.java @@ -29,6 +29,11 @@ /** * corant-context + *
+ * A CDI component management class for hosting the creation and destruction of various bean + * instances using CDI-related scopes. These instances can be obtained by specifying a unique name + * key. These instances are also destroyed through the scope of CDI, and manual destruction is also + * supported. * * @author bingo 下午5:29:56 * @@ -86,21 +91,53 @@ private void writeObject(ObjectOutputStream stream) throws IOException { } } + /** + * corant-context + *
+ * Request scoped component manager
+ *
+ * @author bingo 上午10:50:08
+ *
+ */
@RequestScoped
abstract class RsComponentManager
+ * Session scoped component manager
+ *
+ * @author bingo 上午10:50:29
+ *
+ */
@SessionScoped
abstract class SsComponentManager
+ * Thread scoped component manager
+ *
+ * @author bingo 上午10:50:50
+ *
+ */
@ThreadScoped
- abstract class thComponentManager
+ * Transaction scoped component manager
+ *
+ * @author bingo 上午10:51:21
+ *
+ */
@TransactionScoped
abstract class TsComponentManager
+ * A simple CDI base invocation handler implementation, supports method interceptor.
*
* @author bingo 下午2:12:51
*
@@ -54,13 +56,13 @@ public int hashCode() {
}
@Override
- public Object invoke(Object o, Method method, Object[] args) throws Throwable {
+ public Object invoke(Object target, Method method, Object[] args) throws Throwable {
List
+ * A simple contextual method handler, use for constructs a contextual CDI invocation from a method
+ * object.
+ *
* @author bingo 下午2:26:15
*
*/
@@ -47,34 +51,34 @@ public class ContextualMethodHandler implements Serializable {
protected transient Method method; // ?? use java.lang.invoke.MethodHandle
protected MethodSignature methodSignature;
- public ContextualMethodHandler(Class> beanClass, Method beanMethod, Annotation... qualifiers) {
+ public ContextualMethodHandler(Method method, Annotation... qualifiers) {
+ this(method.getDeclaringClass(), method, qualifiers);
+ }
+
+ protected ContextualMethodHandler(Class> beanClass, Method beanMethod,
+ Annotation... qualifiers) {
method = shouldNotNull(beanMethod);
methodSignature = MethodSignature.of(method);
clazz = defaultObject(beanClass, beanMethod::getDeclaringClass);
this.qualifiers = qualifiers;
}
- public ContextualMethodHandler(Method method) {
- this(null, method);
- }
-
public static Set
+ * An object representing an interceptor meta object and an interceptor instance, while providing an
+ * interceptor to call the entry method.
+ *
+ *
+ * Note: Only supports {@code InterceptionType.AROUND_INVOKE}
+ *
* @author bingo 上午10:41:54
*
*/
diff --git a/corant-context/src/main/java/org/corant/context/proxy/InvocationContextImpl.java b/corant-context/src/main/java/org/corant/context/proxy/InvocationContextImpl.java
index b02545c3f..fc7b1c05d 100644
--- a/corant-context/src/main/java/org/corant/context/proxy/InvocationContextImpl.java
+++ b/corant-context/src/main/java/org/corant/context/proxy/InvocationContextImpl.java
@@ -25,6 +25,9 @@
/**
* corant-context
*
+ *
+ * A simple interceptor call context implementation that works with {@link InterceptorInvocation}.
+ *
* @author bingo 上午11:10:02
*
*/
@@ -47,12 +50,14 @@ public class InvocationContextImpl implements InvocationContext {
private final MethodInvoker methodInvoker;
/**
- * @param targetClass
- * @param target
- * @param method
- * @param methodInvoker
- * @param args
- * @param chain
+ * Build a simple invocation context
+ *
+ * @param targetClass the invocation target class
+ * @param target the invocation target object
+ * @param method the invocation method
+ * @param methodInvoker the method implementation
+ * @param args the method parameters
+ * @param chain the interceptor chain
*/
public InvocationContextImpl(final Class> targetClass, final Object target, final Method method,
final MethodInvoker methodInvoker, final Object[] args,
@@ -61,18 +66,17 @@ public InvocationContextImpl(final Class> targetClass, final Object target, fi
}
/**
- * @param targetClass
- * @param target
- * @param method
- * @param args
- * @param chain
+ * Build a simple invocation context with interceptor chain position
+ *
+ * @param targetClass the invocation target class
+ * @param target the invocation target object
+ * @param method the invocation method
+ * @param methodInvoker the method implementation
+ * @param args the method parameters
+ * @param chain the interceptor chain
+ * @param position the current interceptor chain position
*/
- public InvocationContextImpl(final Class> targetClass, final Object target, final Method method,
- final Object[] args, final List
+ * A simple implementation interface, use for proxy invoking.
+ *
* @author bingo 上午10:38:27
*
*/
diff --git a/corant-context/src/main/java/org/corant/context/proxy/ProxyBuilder.java b/corant-context/src/main/java/org/corant/context/proxy/ProxyBuilder.java
index 76185d1c0..99549ae1e 100644
--- a/corant-context/src/main/java/org/corant/context/proxy/ProxyBuilder.java
+++ b/corant-context/src/main/java/org/corant/context/proxy/ProxyBuilder.java
@@ -32,12 +32,15 @@ public class ProxyBuilder {
/**
* Build normal Interface-based dynamic proxy instance.
*
- * @see MethodInvoker
*
- * @param
+ * A simple invocation handler implementation.
*
* @author bingo 下午3:20:16
*
@@ -79,18 +81,18 @@ public int hashCode() {
}
@Override
- public Object invoke(Object o, Method method, Object[] args) throws Throwable {
+ public Object invoke(Object target, Method method, Object[] args) throws Throwable {
MethodInvoker methodInvoker = invokers.get(method);
if (methodInvoker == null) {
// The default method and java.lang.Object methods use for hq in Collection
if (method.isDefault()) {
- return ProxyUtils.invokeDefaultMethod(o, method, args);
+ return ProxyUtils.invokeDefaultMethod(target, method, args);
} else if ("equals".equals(method.getName()) && method.getParameterTypes()[0] == Object.class
&& args != null && args.length == 1) {
if (args[0] == null) {
return false;
}
- if (o == args[0]) {
+ if (target == args[0]) {
return true;
}
return ProxyUtils.isProxyOfSameInterfaces(args[0], clazz)
@@ -103,7 +105,7 @@ public Object invoke(Object o, Method method, Object[] args) throws Throwable {
throw new CorantRuntimeException("Can not find method %s.", method);
}
}
- return methodInvoker.invoke(o, args);
+ return methodInvoker.invoke(target, args);
}
diff --git a/corant-context/src/main/java/org/corant/context/proxy/ProxyUtils.java b/corant-context/src/main/java/org/corant/context/proxy/ProxyUtils.java
index f69ff3c48..691d24ebc 100644
--- a/corant-context/src/main/java/org/corant/context/proxy/ProxyUtils.java
+++ b/corant-context/src/main/java/org/corant/context/proxy/ProxyUtils.java
@@ -47,6 +47,13 @@ public class ProxyUtils {
static final Map
+ * Note: Currently we do not support resolving static methods.
+ *
+ * FIXME for now I am not sure yet, the default method interceptor?
+ *
+ * @param beanManager bean manager to handle interceptors
+ * @param creationalContext the creational context use for interceptor instantiation
+ * @param beanType the target bean interface type with some interceptors
+ * @return a maps that key is the method of target bean interface and value is the interceptor
+ * invocations of the method, the interceptor invocation contains interceptor instance and
+ * the meta object of the interceptor.
+ *
+ * @see BeanManager#resolveInterceptors(InterceptionType, Annotation...)
+ * @see InterceptorInvocation
+ */
public static Map
+ * FIXME UNFINISHED YET!
*
- * @param o
- * @param method
- * @param args
- * @return invokeDefaultMethod
+ * @param target target object
+ * @param method target object default method
+ * @param args target object default method parameters
+ * @return invoke default method result
*/
- public static Object invokeDefaultMethod(Object o, Method method, Object[] args) {
+ public static Object invokeDefaultMethod(Object target, Method method, Object[] args) {
try {
return defaultMethodHandleCache.computeIfAbsent(method, m -> {
try {
@@ -121,7 +150,7 @@ public static Object invokeDefaultMethod(Object o, Method method, Object[] args)
} catch (Throwable e) {
throw new CorantRuntimeException(e);
}
- }).bindTo(o).invokeWithArguments(args);
+ }).bindTo(target).invokeWithArguments(args);
} catch (Throwable e) {
throw new CorantRuntimeException(e);
}
diff --git a/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/AbstractJMSConfig.java b/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/AbstractJMSConfig.java
index 1103ca84b..f68d5c56d 100644
--- a/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/AbstractJMSConfig.java
+++ b/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/AbstractJMSConfig.java
@@ -55,6 +55,9 @@ public abstract class AbstractJMSConfig implements JMSConfig, NamedObject, Decla
@ConfigKeyItem
protected boolean xa = true;
+ @ConfigKeyItem
+ protected boolean propagateSecurityContext = false;
+
@Override
public boolean equals(Object obj) {
if (this == obj) {
@@ -83,14 +86,16 @@ public String getClientId() {
}
/**
- *
- * @return the connectionFactoryId
+ * @return the connection factory id, the connection factory id means a broker server or cluster.
*/
@Override
public String getConnectionFactoryId() {
return connectionFactoryId;
}
+ /**
+ * Same as {@link #getConnectionFactoryId()}
+ */
@Override
public String getName() {
return connectionFactoryId;
@@ -116,6 +121,10 @@ public boolean isEnable() {
return enable;
}
+ public boolean isPropagateSecurityContext() {
+ return propagateSecurityContext;
+ }
+
@Override
public boolean isXa() {
return xa;
diff --git a/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/AbstractJMSExtension.java b/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/AbstractJMSExtension.java
index bdfbf0c8d..65ec8bfe9 100644
--- a/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/AbstractJMSExtension.java
+++ b/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/AbstractJMSExtension.java
@@ -38,6 +38,7 @@
import javax.jms.JMSConnectionFactory;
import javax.jms.Session;
import org.corant.context.proxy.ContextualMethodHandler;
+import org.corant.context.proxy.ProxyBuilder;
import org.corant.context.qualifier.Qualifiers.NamedQualifierObjectManager;
import org.corant.modules.jms.annotation.MessageContext;
import org.corant.modules.jms.annotation.MessageDestination;
@@ -109,7 +110,7 @@ protected void onProcessAnnotatedType(
}
}
logger.fine(() -> String.format("Scanning message driven on bean: %s.", beanClass.getName()));
- ContextualMethodHandler.fromDeclared(beanClass, m -> m.isAnnotationPresent(MessageDriven.class))
+ ProxyBuilder.buildDeclaredMethods(beanClass, m -> m.isAnnotationPresent(MessageDriven.class))
.forEach(cm -> {
Method method = cm.getMethod();
logger.fine(() -> String.format("Found message driven method %s.", method.getName()));
diff --git a/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/context/ExtendedJMSContext.java b/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/context/ExtendedJMSContext.java
index a627735c1..d65af4533 100644
--- a/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/context/ExtendedJMSContext.java
+++ b/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/context/ExtendedJMSContext.java
@@ -188,8 +188,10 @@ public ObjectMessage createObjectMessage(final Serializable object) {
@Override
public JMSProducer createProducer() {
JMSProducer producer = context().createProducer();
- find(SecurityContextPropagator.class).orElse(SimpleSecurityContextPropagator.INSTANCE)
- .propagate(producer);
+ if (key.getConfig().isPropagateSecurityContext()) {
+ find(SecurityContextPropagator.class).orElse(SimpleSecurityContextPropagator.INSTANCE)
+ .propagate(producer);
+ }
return producer;
}
diff --git a/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/context/JMSContextKey.java b/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/context/JMSContextKey.java
index 40e90f09b..9eec8ebf2 100644
--- a/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/context/JMSContextKey.java
+++ b/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/context/JMSContextKey.java
@@ -109,6 +109,10 @@ public boolean equals(Object o) {
}
+ public AbstractJMSConfig getConfig() {
+ return config;
+ }
+
public String getConnectionFactoryId() {
return connectionFactoryId;
}
diff --git a/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/receive/DefaultMessageHandler.java b/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/receive/DefaultMessageHandler.java
index b27ba8bc9..2e0b4f11b 100644
--- a/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/receive/DefaultMessageHandler.java
+++ b/corant-modules/corant-modules-jms/corant-modules-jms-shared/src/main/java/org/corant/modules/jms/shared/receive/DefaultMessageHandler.java
@@ -26,6 +26,7 @@
import org.corant.context.security.SecurityContexts;
import org.corant.modules.jms.JMSNames;
import org.corant.modules.jms.receive.ManagedMessageReceivingHandler;
+import org.corant.modules.jms.shared.AbstractJMSExtension;
import org.corant.modules.jms.shared.context.SecurityContextPropagator;
import org.corant.modules.jms.shared.context.SecurityContextPropagator.SimpleSecurityContextPropagator;
import org.corant.shared.exception.CorantRuntimeException;
@@ -43,12 +44,15 @@ public class DefaultMessageHandler implements ManagedMessageReceivingHandler {
final MessageReceivingMediator mediator;
final Class> messageClass;
final MessageReceivingExecutorConfig config;
+ final boolean propagateSecurityContext;
protected DefaultMessageHandler(MessageReceivingMetaData meta,
MessageReceivingMediator mediator) {
method = meta.getMethod();
config = MessageReceivingExecutorConfig.getExecutorConfig(meta.getConnectionFactoryId());
messageClass = method.getMethod().getParameterTypes()[0];
+ propagateSecurityContext = AbstractJMSExtension.getConfig(config.getConnectionFactoryId())
+ .isPropagateSecurityContext();
this.mediator = mediator;
}
@@ -81,6 +85,9 @@ protected Object resolvePayload(Message message) throws JMSException {
}
protected void resolveSecurityContext(Message message) {
+ if (!propagateSecurityContext) {
+ return;
+ }
try {
SecurityContext ctx = find(SecurityContextPropagator.class)
.orElse(SimpleSecurityContextPropagator.INSTANCE).extract(message);
diff --git a/corant-modules/corant-modules-quartz/corant-modules-quartz-embeddable/src/main/java/org/corant/modules/quartz/embeddable/CorantSchedulerExtension.java b/corant-modules/corant-modules-quartz/corant-modules-quartz-embeddable/src/main/java/org/corant/modules/quartz/embeddable/CorantSchedulerExtension.java
index 08d50cc48..b31c96d36 100644
--- a/corant-modules/corant-modules-quartz/corant-modules-quartz-embeddable/src/main/java/org/corant/modules/quartz/embeddable/CorantSchedulerExtension.java
+++ b/corant-modules/corant-modules-quartz/corant-modules-quartz-embeddable/src/main/java/org/corant/modules/quartz/embeddable/CorantSchedulerExtension.java
@@ -10,7 +10,7 @@
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.enterprise.inject.spi.WithAnnotations;
import org.corant.context.ContainerEvents.PreContainerStopEvent;
-import org.corant.context.proxy.ContextualMethodHandler;
+import org.corant.context.proxy.ProxyBuilder;
import org.corant.shared.normal.Priorities;
import org.corant.shared.util.Services;
@@ -40,7 +40,7 @@ protected void onProcessAnnotatedType(
return;
}
final Class> beanClass = pat.getAnnotatedType().getJavaClass();
- ContextualMethodHandler.fromDeclared(beanClass, m -> m.isAnnotationPresent(CorantTrigger.class))
+ ProxyBuilder.buildDeclaredMethods(beanClass, m -> m.isAnnotationPresent(CorantTrigger.class))
.stream().map(CorantDeclarativeJobMetaData::of).forEach(declarativeJobMetaDatas::add);
}
}
diff --git a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/FetchQueryHandler.java b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/FetchQueryHandler.java
index 2428ac417..1e9220ce3 100644
--- a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/FetchQueryHandler.java
+++ b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/FetchQueryHandler.java
@@ -20,8 +20,8 @@
* corant-modules-query-api
*
*
- * This interface is used to process fetch queries, provide the query parameters of the fetch query,
- * and provide processing of the fetch query result set.
+ * This interface is used to process fetch queries, provide query parameters and query result
+ * handling for fetch query.
*
* @author bingo 上午10:03:39
*
diff --git a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/QueryParameter.java b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/QueryParameter.java
index c105b4acc..295315319 100644
--- a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/QueryParameter.java
+++ b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/QueryParameter.java
@@ -47,19 +47,20 @@ public interface QueryParameter extends Serializable {
String CTX_QHH_DONT_CONVERT_RESULT = "__QHH_DONT_CONVERT_RESULT";
/**
- * Return the query context that may be contain current user context or security context.
+ * Returns the query context that may be contain current caller context, the context information
+ * may include the security context information of the caller, etc.
*
- * @return getContext
+ * @return the context maps
*/
default Map