@Test public void testGetInputStream() throws Exception { DatabaseEntry entry = new DatabaseEntry("mySourcePartner", "myDestinationPartner"); createDatabase(Arrays.asList(entry)); JdbcConnection jdbcConn = configure(new JdbcConnection()); ServiceFromDatabase extractor = new ServiceFromDatabase().withQuery(SELECT_STMT).withConnection(jdbcConn); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); msg.addMetadata("source", "mySourcePartner"); msg.addMetadata("destination", "myDestinationPartner"); try { LifecycleHelper.initAndStart(extractor); try (InputStream in = extractor.getInputStream(msg)) { assertNotNull(in); assertEquals(ServiceList.class, DefaultMarshaller.getDefaultMarshaller().unmarshal(in).getClass()); } } finally { LifecycleHelper.stopAndClose(extractor); } }
@Override public InputStream getInputStream(AdaptrisMessage m) throws Exception { Args.notBlank(getQuery(), "query"); Connection jdbcCon = getConnection().retrieveConnection(DatabaseConnection.class).connect(); String jdbcQuery = m.resolve(getQuery(), true); ResultSet resultSet = null; Statement statement = null; InputStream result = null; try { statement = jdbcCon.createStatement(); resultSet = statement.executeQuery(jdbcQuery); if (resultSet.next()) { result = new ServiceInputStream(resultSet, statement); } else { throw new ServiceException("No results from [" + jdbcQuery + "]"); } } catch (Exception e) { JdbcUtil.closeQuietly(resultSet, statement); throw e; } return result; }
ServiceFromDatabase extends ExtractorWithConnection { @Override public InputStream getInputStream(AdaptrisMessage m) throws Exception { Args.notBlank(getQuery(), "query"); Connection jdbcCon = getConnection().retrieveConnection(DatabaseConnection.class).connect(); String jdbcQuery = m.resolve(getQuery(), true); ResultSet resultSet = null; Statement statement = null; InputStream result = null; try { statement = jdbcCon.createStatement(); resultSet = statement.executeQuery(jdbcQuery); if (resultSet.next()) { result = new ServiceInputStream(resultSet, statement); } else { throw new ServiceException("No results from [" + jdbcQuery + "]"); } } catch (Exception e) { JdbcUtil.closeQuietly(resultSet, statement); throw e; } return result; } }
ServiceFromDatabase extends ExtractorWithConnection { @Override public InputStream getInputStream(AdaptrisMessage m) throws Exception { Args.notBlank(getQuery(), "query"); Connection jdbcCon = getConnection().retrieveConnection(DatabaseConnection.class).connect(); String jdbcQuery = m.resolve(getQuery(), true); ResultSet resultSet = null; Statement statement = null; InputStream result = null; try { statement = jdbcCon.createStatement(); resultSet = statement.executeQuery(jdbcQuery); if (resultSet.next()) { result = new ServiceInputStream(resultSet, statement); } else { throw new ServiceException("No results from [" + jdbcQuery + "]"); } } catch (Exception e) { JdbcUtil.closeQuietly(resultSet, statement); throw e; } return result; } ServiceFromDatabase(); }
ServiceFromDatabase extends ExtractorWithConnection { @Override public InputStream getInputStream(AdaptrisMessage m) throws Exception { Args.notBlank(getQuery(), "query"); Connection jdbcCon = getConnection().retrieveConnection(DatabaseConnection.class).connect(); String jdbcQuery = m.resolve(getQuery(), true); ResultSet resultSet = null; Statement statement = null; InputStream result = null; try { statement = jdbcCon.createStatement(); resultSet = statement.executeQuery(jdbcQuery); if (resultSet.next()) { result = new ServiceInputStream(resultSet, statement); } else { throw new ServiceException("No results from [" + jdbcQuery + "]"); } } catch (Exception e) { JdbcUtil.closeQuietly(resultSet, statement); throw e; } return result; } ServiceFromDatabase(); @Override InputStream getInputStream(AdaptrisMessage m); String getQuery(); void setQuery(String query); ServiceFromDatabase withQuery(String q); }
ServiceFromDatabase extends ExtractorWithConnection { @Override public InputStream getInputStream(AdaptrisMessage m) throws Exception { Args.notBlank(getQuery(), "query"); Connection jdbcCon = getConnection().retrieveConnection(DatabaseConnection.class).connect(); String jdbcQuery = m.resolve(getQuery(), true); ResultSet resultSet = null; Statement statement = null; InputStream result = null; try { statement = jdbcCon.createStatement(); resultSet = statement.executeQuery(jdbcQuery); if (resultSet.next()) { result = new ServiceInputStream(resultSet, statement); } else { throw new ServiceException("No results from [" + jdbcQuery + "]"); } } catch (Exception e) { JdbcUtil.closeQuietly(resultSet, statement); throw e; } return result; } ServiceFromDatabase(); @Override InputStream getInputStream(AdaptrisMessage m); String getQuery(); void setQuery(String query); ServiceFromDatabase withQuery(String q);  }