Search in sources :

Example 6 with AdaptrisConnection

use of com.adaptris.core.AdaptrisConnection in project interlok by adaptris.

the class AdapterManager method addSharedConnection.

@Override
public boolean addSharedConnection(String xmlString) throws CoreException, IllegalArgumentException {
    ensureState(ClosedState.getInstance());
    AdaptrisConnection comp = (AdaptrisConnection) DefaultMarshaller.getDefaultMarshaller().unmarshal(xmlString);
    boolean result = getWrappedComponent().getSharedComponents().addConnection(comp);
    if (result) {
        marshalAndSendNotification();
    }
    return result;
}
Also used : AdaptrisConnection(com.adaptris.core.AdaptrisConnection)

Example 7 with AdaptrisConnection

use of com.adaptris.core.AdaptrisConnection in project interlok by adaptris.

the class JdbcServiceList method applyServices.

@Override
protected void applyServices(AdaptrisMessage msg) throws ServiceException {
    try {
        AdaptrisConnection c = connection();
        if (c != null) {
            Connection conn = c.retrieveConnection(DatabaseConnection.class).connect();
            msg.getObjectHeaders().put(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY, conn);
        }
        super.applyServices(msg);
        // We may not have a valid connection here if we're using pooled connections.  If not, then no point in committing on a new connection.
        Connection conn = (Connection) msg.getObjectHeaders().get(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY);
        if (conn != null && !conn.isClosed())
            JdbcUtil.commit(conn);
    } catch (Exception e) {
        rollback(msg, e);
        throw ExceptionHelper.wrapServiceException(e);
    } finally {
        Connection conn = (Connection) msg.getObjectHeaders().get(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY);
        JdbcUtil.closeQuietly(conn);
    }
}
Also used : AdaptrisConnection(com.adaptris.core.AdaptrisConnection) DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) Connection(java.sql.Connection) AdaptrisConnection(com.adaptris.core.AdaptrisConnection) DatabaseConnection(com.adaptris.core.jdbc.DatabaseConnection) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException)

Example 8 with AdaptrisConnection

use of com.adaptris.core.AdaptrisConnection in project interlok by adaptris.

the class FilteredSharedComponentStart method exclude.

private Collection<AdaptrisConnection> exclude(Collection<AdaptrisConnection> conns) {
    if (getExcludes().size() == 0) {
        return conns;
    }
    initialisePatterns();
    List<AdaptrisConnection> toBeRemoved = new ArrayList<>();
    for (AdaptrisConnection element : conns) {
        for (Pattern pattern : excludePatterns) {
            if (pattern.matcher(element.getUniqueId()).find()) {
                toBeRemoved.add(element);
                break;
            }
        }
    }
    conns.removeAll(toBeRemoved);
    return conns;
}
Also used : Pattern(java.util.regex.Pattern) AdaptrisConnection(com.adaptris.core.AdaptrisConnection) ArrayList(java.util.ArrayList)

Example 9 with AdaptrisConnection

use of com.adaptris.core.AdaptrisConnection in project interlok by adaptris.

the class FilteredSharedComponentStart method init.

@Override
public void init(Collection<AdaptrisConnection> conns) throws CoreException {
    Collection<AdaptrisConnection> actual = filter(new ArrayList<AdaptrisConnection>(conns));
    logActivity(ConnectionAction.INIT, actual);
    for (AdaptrisConnection c : actual) {
        execute(ConnectionAction.INIT, c);
    }
}
Also used : AdaptrisConnection(com.adaptris.core.AdaptrisConnection)

Example 10 with AdaptrisConnection

use of com.adaptris.core.AdaptrisConnection in project interlok by adaptris.

the class JndiHelperTest method testBindCollection_WithContext.

@Test
public void testBindCollection_WithContext() throws Exception {
    NullConnection connection = new NullConnection();
    connection.setUniqueId(getName());
    ArrayList<AdaptrisConnection> connectionList = new ArrayList<AdaptrisConnection>();
    connectionList.add(connection);
    InitialContext initialContext = new InitialContext(env);
    try {
        JndiHelper.bind(initialContext, connectionList, true);
        NullConnection lookedup = (NullConnection) initialContext.lookup("adapter:comp/env/" + getName());
        assertNotNull(lookedup);
        assertTrue(lookedup instanceof NullConnection);
        assertEquals(getName(), lookedup.getUniqueId());
    } finally {
        JndiHelper.unbindQuietly(initialContext, connectionList, true);
    }
}
Also used : AdaptrisConnection(com.adaptris.core.AdaptrisConnection) ArrayList(java.util.ArrayList) NullConnection(com.adaptris.core.NullConnection) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Aggregations

AdaptrisConnection (com.adaptris.core.AdaptrisConnection)15 ArrayList (java.util.ArrayList)9 NullConnection (com.adaptris.core.NullConnection)6 Test (org.junit.Test)6 InitialContext (javax.naming.InitialContext)5 CoreException (com.adaptris.core.CoreException)4 Pattern (java.util.regex.Pattern)2 AllowsRetriesConnection (com.adaptris.core.AllowsRetriesConnection)1 ServiceException (com.adaptris.core.ServiceException)1 DatabaseConnection (com.adaptris.core.jdbc.DatabaseConnection)1 Connection (java.sql.Connection)1