diff --git a/src/main/java/org/springframework/integration/splunk/support/SplunkIndexWriter.java b/src/main/java/org/springframework/integration/splunk/support/SplunkIndexWriter.java index 66f301e..d0328d3 100644 --- a/src/main/java/org/springframework/integration/splunk/support/SplunkIndexWriter.java +++ b/src/main/java/org/springframework/integration/splunk/support/SplunkIndexWriter.java @@ -1,66 +1,63 @@ /* - * Copyright 2002-2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Copyright 2002-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ + package org.springframework.integration.splunk.support; import java.io.IOException; import java.net.Socket; -import org.springframework.integration.splunk.core.ServiceFactory; -import org.springframework.util.Assert; - import com.splunk.Args; import com.splunk.Index; import com.splunk.Receiver; import com.splunk.Service; +import org.springframework.integration.splunk.core.ServiceFactory; +import org.springframework.util.Assert; + /** - * - * DataWriter to stream data into Splunk using an optional index. If no index specified, + * + * DataWriter to stream data into Splunk using an optional index. If no index specified, * the main default index is used. * * @author Jarred Li * @author David Turanski + * @author Olivier Lamy * @since 1.0 - * */ - public class SplunkIndexWriter extends AbstractSplunkDataWriter { - private String indexName; - /** - * - * @param serviceFactory - * @param args - */ + + private String index; + public SplunkIndexWriter(ServiceFactory serviceFactory, Args args) { super(serviceFactory, args); } - - /* (non-Javadoc) - * @see org.springframework.integration.splunk.support.SplunkDataWriter#createSocket(com.splunk.Service) - */ + @Override protected Socket createSocket(Service service) throws IOException { Index indexObject = null; Receiver receiver = null; Socket socket = null; - if (indexName != null) { - indexObject = service.getIndexes().get(indexName); - Assert.notNull(indexObject,String.format("cannot find index [%s]",indexName)); + if (index != null) { + indexObject = service.getIndexes().get(index); + Assert.notNull(indexObject, String.format("cannot find index [%s]", index)); socket = indexObject.attach(args); - - - } else { + + } + else { receiver = service.getReceiver(); socket = receiver.attach(args); } @@ -69,6 +66,14 @@ public class SplunkIndexWriter extends AbstractSplunkDataWriter { } return socket; } - + + + public String getIndex() { + return index; + } + + public void setIndex(String index) { + this.index = index; + } } diff --git a/src/test/java/org/springframework/integration/splunk/config/xml/SplunkOutboundChannelAdapterParserStreamTests.java b/src/test/java/org/springframework/integration/splunk/config/xml/SplunkOutboundChannelAdapterParserStreamTests.java index 2ad3693..9e10243 100644 --- a/src/test/java/org/springframework/integration/splunk/config/xml/SplunkOutboundChannelAdapterParserStreamTests.java +++ b/src/test/java/org/springframework/integration/splunk/config/xml/SplunkOutboundChannelAdapterParserStreamTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2012 the original author or authors. + * Copyright 2011-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.splunk.config.xml; import static org.junit.Assert.*; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,6 +30,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Jarred Li + * @author Artem Bilan * @since 1.0 * */ @@ -40,18 +41,16 @@ public class SplunkOutboundChannelAdapterParserStreamTests { @Autowired private ApplicationContext appContext; - /** - * Test method for {@link org.springframework.integration.splunk.config.xml.SplunkOutboundChannelAdapterParser#parseConsumer(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)}. - */ @Test public void testParseConsumerElementParserContext() { Object adapter = appContext.getBean("splunkOutboundChannelAdapter"); - Assert.assertNotNull(adapter); + assertNotNull(adapter); AbstractSplunkDataWriter writer = appContext.getBean("splunkOutboundChannelAdapter.splunkExecutor.writer", AbstractSplunkDataWriter.class); - Assert.assertNotNull(writer); - assertTrue(writer instanceof SplunkIndexWriter); + assertNotNull(writer); + assertTrue(writer instanceof SplunkIndexWriter); + assertEquals("foo", ((SplunkIndexWriter) writer).getIndex()); } } diff --git a/src/test/resources/org/springframework/integration/splunk/config/xml/SplunkOutboundChannelAdapterParserStreamTests-context.xml b/src/test/resources/org/springframework/integration/splunk/config/xml/SplunkOutboundChannelAdapterParserStreamTests-context.xml index ec10a53..ea38767 100644 --- a/src/test/resources/org/springframework/integration/splunk/config/xml/SplunkOutboundChannelAdapterParserStreamTests-context.xml +++ b/src/test/resources/org/springframework/integration/splunk/config/xml/SplunkOutboundChannelAdapterParserStreamTests-context.xml @@ -1,24 +1,23 @@ - + - + - + id="splunkOutboundChannelAdapter" auto-startup="false" order="1" + channel="outputToSplunk" splunk-server-ref="splunkServer" + source-type="spring-integration" source="example5" + host="test.host" host-regex="test.host.*"> +