Search in sources :

Example 1 with CXFInvocationHandler

use of org.apache.cxf.jca.cxf.CXFInvocationHandler in project cxf by apache.

the class InvocationHandlerFactory method createHandlers.

public CXFInvocationHandler createHandlers(Object target, Subject subject) throws ResourceAdapterInternalException {
    CXFInvocationHandler first = null;
    CXFInvocationHandler last = null;
    // Create data member
    CXFInvocationHandlerData data = new CXFInvocationHandlerDataImpl();
    data.setBus(bus);
    data.setManagedConnection(managedConnection);
    data.setSubject(subject);
    data.setTarget(target);
    for (int i = 0; i < handlerChainTypes.length; i++) {
        CXFInvocationHandler newHandler;
        try {
            Constructor<?> newHandlerConstructor = handlerChainTypes[i].getDeclaredConstructor(new Class[] { CXFInvocationHandlerData.class });
            newHandler = (CXFInvocationHandler) newHandlerConstructor.newInstance(new Object[] { data });
        } catch (Exception ex) {
            ResourceAdapterInternalException raie = new ResourceAdapterInternalException("error creating InvocationHandler: " + handlerChainTypes[i], ex);
            LOG.warning(raie.getMessage());
            throw raie;
        }
        if (last != null) {
            last.setNext(newHandler);
            last = newHandler;
        } else {
            first = newHandler;
            last = newHandler;
        }
    }
    return first;
}
Also used : CXFInvocationHandler(org.apache.cxf.jca.cxf.CXFInvocationHandler) CXFInvocationHandlerData(org.apache.cxf.jca.cxf.CXFInvocationHandlerData) ResourceAdapterInternalException(org.apache.cxf.jca.core.resourceadapter.ResourceAdapterInternalException) ResourceAdapterInternalException(org.apache.cxf.jca.core.resourceadapter.ResourceAdapterInternalException) IOException(java.io.IOException)

Example 2 with CXFInvocationHandler

use of org.apache.cxf.jca.cxf.CXFInvocationHandler in project cxf by apache.

the class AbstractInvocationHandlerTest method testBusAttribute.

@Test
public void testBusAttribute() {
    CXFInvocationHandler handler = getHandler();
    handler.getData().setBus(mockBus);
    assertSame("bus must be retrievable after set", mockBus, handler.getData().getBus());
}
Also used : CXFInvocationHandler(org.apache.cxf.jca.cxf.CXFInvocationHandler) Test(org.junit.Test)

Example 3 with CXFInvocationHandler

use of org.apache.cxf.jca.cxf.CXFInvocationHandler in project cxf by apache.

the class AbstractInvocationHandlerTest method testManagedConnectionAttribute.

@Test
public void testManagedConnectionAttribute() {
    CXFInvocationHandler handler = getHandler();
    handler.getData().setManagedConnection(mockManagedConnection);
    assertSame("bus must be retrievable after set", mockManagedConnection, handler.getData().getManagedConnection());
}
Also used : CXFInvocationHandler(org.apache.cxf.jca.cxf.CXFInvocationHandler) Test(org.junit.Test)

Example 4 with CXFInvocationHandler

use of org.apache.cxf.jca.cxf.CXFInvocationHandler in project cxf by apache.

the class InvocationHandlerFactoryTest method testCreateHandlerChain.

@Test
public void testCreateHandlerChain() throws ResourceAdapterInternalException {
    CXFInvocationHandler first = handler;
    CXFInvocationHandler last = null;
    assertNotNull("handler must not be null", handler);
    int count = 0;
    Set<Class<?>> allHandlerTypes = new HashSet<>();
    while (handler != null) {
        assertSame("managed connection must be set", mci, handler.getData().getManagedConnection());
        assertSame("bus must be set", mockBus, handler.getData().getBus());
        assertSame("subject must be set", testSubject, handler.getData().getSubject());
        assertSame("target must be set", target, handler.getData().getTarget());
        allHandlerTypes.add(handler.getClass());
        last = handler;
        handler = handler.getNext();
        count++;
    }
    assertNotNull(last);
    assertEquals("must create correct number of handlers", count, 4);
    assertTrue("first handler must a ProxyInvocationHandler", first instanceof ProxyInvocationHandler);
    assertTrue("last handler must be an InvokingInvocationHandler", last instanceof InvokingInvocationHandler);
    Class<?>[] types = { ProxyInvocationHandler.class, ObjectMethodInvocationHandler.class, InvokingInvocationHandler.class, SecurityTestHandler.class };
    for (int i = 0; i < types.length; i++) {
        assertTrue("handler chain must contain type: " + types[i], allHandlerTypes.contains(types[i]));
    }
}
Also used : CXFInvocationHandler(org.apache.cxf.jca.cxf.CXFInvocationHandler) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with CXFInvocationHandler

use of org.apache.cxf.jca.cxf.CXFInvocationHandler in project cxf by apache.

the class AbstractInvocationHandlerTest method testTargetAttribute.

@Test
public void testTargetAttribute() {
    CXFInvocationHandler handler = getHandler();
    handler.getData().setTarget(target);
    assertSame("target must be retrievable after set", target, handler.getData().getTarget());
}
Also used : CXFInvocationHandler(org.apache.cxf.jca.cxf.CXFInvocationHandler) Test(org.junit.Test)

Aggregations

CXFInvocationHandler (org.apache.cxf.jca.cxf.CXFInvocationHandler)7 Test (org.junit.Test)5 CXFInvocationHandlerData (org.apache.cxf.jca.cxf.CXFInvocationHandlerData)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ResourceAdapterInternalException (org.apache.cxf.jca.core.resourceadapter.ResourceAdapterInternalException)1 Before (org.junit.Before)1