Package org.apache.tuscany.spi.wire

Examples of org.apache.tuscany.spi.wire.Interceptor


            }
        });
        replay(scheduler);
        WorkContext context = createMock(WorkContext.class);
        Message msg = new MessageImpl();
        Interceptor next = EasyMock.createMock(Interceptor.class);
        EasyMock.expect(next.invoke(EasyMock.eq(msg))).andReturn(msg);
        EasyMock.replay(next);
        Interceptor interceptor = new NonBlockingBridgingInterceptor(scheduler, context, next);
        interceptor.invoke(msg);
        verify(next);
    }
View Full Code Here


        for (InboundInvocationChain chain : chains.values()) {
            if (chain.getTargetInvoker() != null && !chain.getTargetInvoker().isOptimizable()) {
                return false;
            }
            if (chain.getHeadInterceptor() != null) {
                Interceptor current = chain.getHeadInterceptor();
                while (current != null) {
                    if (!current.isOptimizable()) {
                        return false;
                    }
                    current = current.getNext();
                }
            }
        }
        return true;
    }
View Full Code Here

        interceptorChainTail = interceptor;
    }

    public void addInterceptor(int index, Interceptor interceptor) {
        int i = 0;
        Interceptor next = interceptorChainHead;
        Interceptor prev = null;
        while (next != null && i < index) {
            prev = next;
            next = next.getNext();
            i++;
        }
        if (i == index) {
            if (prev != null) {
                prev.setNext(interceptor);
            } else {
                interceptorChainHead = interceptor;
            }
            interceptor.setNext(next);
            if (next == null) {
View Full Code Here

                    new DataBindingInteceptor(source, sourceOperation, target, targetOperation);
                interceptor.setMediator(mediator);
                if (isReference) {
                    // FIXME: We need a better way to position the interceptors
                    target.getInvocationChains().get(targetOperation).addInterceptor(0, interceptor);
                    Interceptor tail = entry.getValue().getTailInterceptor();
                    if (tail != null) {
                        // HACK to relink the bridging interceptor
                        tail.setNext(interceptor);
                    }
                } else {
                    entry.getValue().addInterceptor(0, interceptor);
                }
View Full Code Here

     */
    void connect(OutboundInvocationChain sourceChain,
                 InboundInvocationChain targetChain,
                 TargetInvoker invoker,
                 boolean nonBlocking) {
        Interceptor head = targetChain.getHeadInterceptor();
        if (head == null) {
            BuilderConfigException e = new BuilderConfigException("No interceptor for operation");
            e.setIdentifier(targetChain.getOperation().getName());
            throw e;
        }
View Full Code Here

    }

    public boolean isOptimizable() {
        for (OutboundInvocationChain chain : chains.values()) {
            if (chain.getHeadInterceptor() != null) {
                Interceptor current = chain.getHeadInterceptor();
                while (current != null && current != chain.getTargetInterceptor()) {
                    if (!current.isOptimizable()) {
                        return false;
                    }
                    current = current.getNext();
                }
            }
        }

        for (InboundInvocationChain chain : callbackTargetChains.values()) {
            if (chain.getTargetInvoker() != null && !chain.getTargetInvoker().isOptimizable()) {
                return false;
            }
            if (chain.getHeadInterceptor() != null) {
                Interceptor current = chain.getHeadInterceptor();
                while (current != null) {
                    if (!current.isOptimizable()) {
                        return false;
                    }
                    current = current.getNext();
                }
            }
        }

        return true;
View Full Code Here

    }

    public Object invokeTarget(org.apache.tuscany.spi.model.Operation<?> op, Object[] args)
        throws InvocationTargetException {
        InvocationChain chain = inboundWire.getInvocationChains().get(op);
        Interceptor headInterceptor = chain.getHeadInterceptor();
        if (headInterceptor == null) {
            try {
                // short-circuit the dispatch and invoke the target directly
                if (chain.getTargetInvoker() == null) {
                    throw new AssertionError("No target invoker [" + chain.getOperation().getName() + "]");
                }
                return chain.getTargetInvoker().invokeTarget(args);
            } catch (InvocationTargetException e) {
                // the cause was thrown by the target so throw it
                throw e;
            }
        } else {
            Object messageId = workContext.getCurrentMessageId();
            workContext.setCurrentMessageId(null);
            Object correlationId = workContext.getCurrentCorrelationId();
            workContext.setCurrentCorrelationId(null);

            Message msg = new MessageImpl();
            msg.setTargetInvoker(chain.getTargetInvoker());
            msg.setFromAddress(getFromAddress());
            if (messageId == null) {
                messageId = new MessageId();
            }
            msg.setMessageId(messageId);
            msg.setCorrelationId(correlationId);
            msg.setBody(args);
            Message resp;
            // dispatch the wire down the chain and get the response
            // TODO http://issues.apache.org/jira/browse/TUSCANY-777
            ClassLoader oldtccl = Thread.currentThread().getContextClassLoader();
            try {
                Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
                resp = headInterceptor.invoke(msg);
            } finally {
                Thread.currentThread().setContextClassLoader(oldtccl);
            }
            Object body = resp.getBody();
            if (resp.isFault()) {
View Full Code Here

*/
public class SynchronousBridgingInterceptorTestCase extends TestCase {

    public void testInvoke() throws Exception {
        Message msg = new MessageImpl();
        Interceptor next = EasyMock.createMock(Interceptor.class);
        EasyMock.expect(next.invoke(EasyMock.eq(msg))).andReturn(msg);
        EasyMock.replay(next);
        Interceptor interceptor = new SynchronousBridgingInterceptor(next);
        interceptor.invoke(msg);
        verify(next);
    }
View Full Code Here

        msg.setBody(EasyMock.anyObject());
        expectLastCall().anyTimes();
        expect(msg.getBody()).andReturn(source).once().andReturn(target[0]).once().andReturn(source[0]);
        expect(msg.isFault()).andReturn(false).once();
        replay(msg);
        Interceptor next = createMock(Interceptor.class);
        expect(next.invoke(msg)).andReturn(msg);
        replay(next);
        interceptor.setNext(next);
        interceptor.invoke(msg);
        String result = (String)msg.getBody();
        Assert.assertEquals(source[0], result);
View Full Code Here

*/
public class InvocationChainImplTestCase extends TestCase {

    public void testInsertAtPos() throws Exception {
        MockChain chain = new MockChain(new Operation<Type>("foo", null, null, null));
        Interceptor inter3 = new MockInterceptor();
        Interceptor inter2 = new MockInterceptor();
        Interceptor inter1 = new MockInterceptor();
        chain.addInterceptor(inter3);
        chain.addInterceptor(0, inter1);
        chain.addInterceptor(1, inter2);
        Interceptor head = chain.getHeadInterceptor();
        assertEquals(inter1, head);
        assertEquals(inter2, head.getNext());
        assertEquals(inter3, head.getNext().getNext());
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.spi.wire.Interceptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.