Search in sources :

Example 1 with RunWithRunContext

use of org.eclipse.scout.rt.platform.context.RunWithRunContext in project scout.rt by eclipse.

the class PortProducer method proxyHandler.

/**
 * Proxies the given {@link Handler} to run on behalf of a {@link RunContext}, if the handler is annotated with
 * {@link RunWithRunContext}.
 */
protected Handler<? extends MessageContext> proxyHandler(final Handler<? extends MessageContext> handler) {
    final RunWithRunContext handleWithRunContext = handler.getClass().getAnnotation(RunWithRunContext.class);
    if (handleWithRunContext == null) {
        return handler;
    }
    final RunContextProducer runContextProducer = BEANS.get(handleWithRunContext.value());
    return (Handler<?>) Proxy.newProxyInstance(handler.getClass().getClassLoader(), handler.getClass().getInterfaces(), new InvocationHandler() {

        @Override
        public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
            if (PROXIED_HANDLER_METHODS.contains(method)) {
                return runContextProducer.produce(Subject.getSubject(AccessController.getContext())).call(new Callable<Object>() {

                    @Override
                    public Object call() throws Exception {
                        return method.invoke(handler, args);
                    }
                }, DefaultExceptionTranslator.class);
            } else {
                return method.invoke(handler, args);
            }
        }
    });
}
Also used : RunWithRunContext(org.eclipse.scout.rt.platform.context.RunWithRunContext) Handler(javax.xml.ws.handler.Handler) InvocationHandler(java.lang.reflect.InvocationHandler) RunContextProducer(org.eclipse.scout.rt.platform.context.RunContextProducer) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) WebServiceException(javax.xml.ws.WebServiceException)

Example 2 with RunWithRunContext

use of org.eclipse.scout.rt.platform.context.RunWithRunContext in project scout.rt by eclipse.

the class ServicePool method proxyHandler.

/**
 * Proxies the given {@link Handler} to run on behalf of a {@link RunContext}, if the handler is annotated with
 * {@link RunWithRunContext}.
 */
protected Handler<? extends MessageContext> proxyHandler(final Handler<? extends MessageContext> handler) {
    final RunWithRunContext handleWithRunContext = handler.getClass().getAnnotation(RunWithRunContext.class);
    if (handleWithRunContext == null) {
        return handler;
    }
    final RunContextProducer runContextProducer = BEANS.get(handleWithRunContext.value());
    return (Handler<?>) Proxy.newProxyInstance(handler.getClass().getClassLoader(), handler.getClass().getInterfaces(), new InvocationHandler() {

        @Override
        public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
            if (PROXIED_HANDLER_METHODS.contains(method)) {
                return runContextProducer.produce(Subject.getSubject(AccessController.getContext())).call(new Callable<Object>() {

                    @Override
                    public Object call() throws Exception {
                        return method.invoke(handler, args);
                    }
                }, DefaultExceptionTranslator.class);
            } else {
                return method.invoke(handler, args);
            }
        }
    });
}
Also used : RunWithRunContext(org.eclipse.scout.rt.platform.context.RunWithRunContext) Handler(javax.xml.ws.handler.Handler) InvocationHandler(java.lang.reflect.InvocationHandler) RunContextProducer(org.eclipse.scout.rt.platform.context.RunContextProducer) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) WebServiceException(javax.xml.ws.WebServiceException)

Aggregations

InvocationHandler (java.lang.reflect.InvocationHandler)2 Method (java.lang.reflect.Method)2 WebServiceException (javax.xml.ws.WebServiceException)2 Handler (javax.xml.ws.handler.Handler)2 RunContextProducer (org.eclipse.scout.rt.platform.context.RunContextProducer)2 RunWithRunContext (org.eclipse.scout.rt.platform.context.RunWithRunContext)2