You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2012/09/10 12:18:11 UTC
svn commit: r1382732 - in /camel/trunk/components/camel-elasticsearch/src:
main/java/org/apache/camel/component/elasticsearch/
test/java/org/apache/camel/component/elasticsearch/ test/resources/
Author: bvahdat
Date: Mon Sep 10 10:18:11 2012
New Revision: 1382732
URL: http://svn.apache.org/viewvc?rev=1382732&view=rev
Log:
CAMEL-5586: Polished the camel-elasticsearch codebase.
Modified:
camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchConfiguration.java
camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchEndpoint.java
camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
camel/trunk/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentTest.java
camel/trunk/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/SpringElasticsearchTest.java
camel/trunk/components/camel-elasticsearch/src/test/resources/SpringElasticsearchTest.xml
Modified: camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchConfiguration.java?rev=1382732&r1=1382731&r2=1382732&view=diff
==============================================================================
--- camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchConfiguration.java (original)
+++ camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchConfiguration.java Mon Sep 10 10:18:11 2012
@@ -49,7 +49,6 @@ public class ElasticsearchConfiguration
private String operation;
public ElasticsearchConfiguration(URI uri, Map<String, Object> parameters) throws Exception {
-
String protocol = uri.getScheme();
if (!protocol.equalsIgnoreCase(PROTOCOL)) {
Modified: camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchEndpoint.java?rev=1382732&r1=1382731&r2=1382732&view=diff
==============================================================================
--- camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchEndpoint.java (original)
+++ camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchEndpoint.java Mon Sep 10 10:18:11 2012
@@ -80,12 +80,6 @@ public class ElasticsearchEndpoint exten
super.doStop();
}
- @Override
- protected void doShutdown() throws Exception {
- // TODO Auto-generated method stub
- super.doShutdown();
- }
-
public Client getClient() {
return client;
}
Modified: camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java?rev=1382732&r1=1382731&r2=1382732&view=diff
==============================================================================
--- camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java (original)
+++ camel/trunk/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java Mon Sep 10 10:18:11 2012
@@ -35,25 +35,26 @@ import org.elasticsearch.common.xcontent
*/
public class ElasticsearchProducer extends DefaultProducer {
- private ElasticsearchEndpoint endpoint;
-
public ElasticsearchProducer(ElasticsearchEndpoint endpoint) {
super(endpoint);
- this.endpoint = endpoint;
}
- public void process(Exchange exchange) throws Exception {
+ @Override
+ public ElasticsearchEndpoint getEndpoint() {
+ return (ElasticsearchEndpoint) super.getEndpoint();
+ }
- String operation = (String) exchange.getIn().getHeader(ElasticsearchConfiguration.PARAM_OPERATION);
+ public void process(Exchange exchange) throws Exception {
+ String operation = exchange.getIn().getHeader(ElasticsearchConfiguration.PARAM_OPERATION, String.class);
if (operation == null) {
- operation = endpoint.getConfig().getOperation();
+ operation = getEndpoint().getConfig().getOperation();
}
if (operation == null) {
throw new IllegalArgumentException(ElasticsearchConfiguration.PARAM_OPERATION + " is missing");
}
- Client client = endpoint.getClient();
+ Client client = getEndpoint().getClient();
if (operation.equalsIgnoreCase(ElasticsearchConfiguration.OPERATION_INDEX)) {
addToIndex(client, exchange);
@@ -67,15 +68,14 @@ public class ElasticsearchProducer exten
}
public void getById(Client client, Exchange exchange) {
-
String indexName = exchange.getIn().getHeader(ElasticsearchConfiguration.PARAM_INDEX_NAME, String.class);
if (indexName == null) {
- indexName = endpoint.getConfig().getIndexName();
+ indexName = getEndpoint().getConfig().getIndexName();
}
String indexType = exchange.getIn().getHeader(ElasticsearchConfiguration.PARAM_INDEX_TYPE, String.class);
if (indexType == null) {
- indexType = endpoint.getConfig().getIndexType();
+ indexType = getEndpoint().getConfig().getIndexType();
}
String indexId = exchange.getIn().getBody(String.class);
@@ -85,15 +85,14 @@ public class ElasticsearchProducer exten
}
public void deleteById(Client client, Exchange exchange) {
-
String indexName = exchange.getIn().getHeader(ElasticsearchConfiguration.PARAM_INDEX_NAME, String.class);
if (indexName == null) {
- indexName = endpoint.getConfig().getIndexName();
+ indexName = getEndpoint().getConfig().getIndexName();
}
String indexType = exchange.getIn().getHeader(ElasticsearchConfiguration.PARAM_INDEX_TYPE, String.class);
if (indexType == null) {
- indexType = endpoint.getConfig().getIndexType();
+ indexType = getEndpoint().getConfig().getIndexType();
}
String indexId = exchange.getIn().getBody(String.class);
@@ -103,15 +102,14 @@ public class ElasticsearchProducer exten
}
public void addToIndex(Client client, Exchange exchange) {
-
String indexName = exchange.getIn().getHeader(ElasticsearchConfiguration.PARAM_INDEX_NAME, String.class);
if (indexName == null) {
- indexName = endpoint.getConfig().getIndexName();
+ indexName = getEndpoint().getConfig().getIndexName();
}
String indexType = exchange.getIn().getHeader(ElasticsearchConfiguration.PARAM_INDEX_TYPE, String.class);
if (indexType == null) {
- indexType = endpoint.getConfig().getIndexType();
+ indexType = getEndpoint().getConfig().getIndexType();
}
IndexRequestBuilder prepareIndex = client.prepareIndex(indexName, indexType);
Modified: camel/trunk/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentTest.java?rev=1382732&r1=1382731&r2=1382732&view=diff
==============================================================================
--- camel/trunk/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentTest.java (original)
+++ camel/trunk/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentTest.java Mon Sep 10 10:18:11 2012
@@ -29,56 +29,54 @@ public class ElasticsearchComponentTest
@Test
public void testIndex() throws Exception {
- HashMap<String, String> map = new HashMap<String, String>();
+ Map<String, String> map = new HashMap<String, String>();
map.put("content", "test");
- String indexId = (String) template.requestBody("direct:index", map);
+ String indexId = template.requestBody("direct:index", map, String.class);
assertNotNull("indexId should be set", indexId);
}
@Test
public void testGet() throws Exception {
//first, INDEX a value
- HashMap<String, String> map = new HashMap<String, String>();
+ Map<String, String> map = new HashMap<String, String>();
map.put("content", "test");
sendBody("direct:index", map);
- String indexId = (String) template.requestBody("direct:index", map);
+ String indexId = template.requestBody("direct:index", map, String.class);
assertNotNull("indexId should be set", indexId);
//now, verify GET succeeded
- GetResponse response = (GetResponse) template.requestBody("direct:get", indexId);
+ GetResponse response = template.requestBody("direct:get", indexId, GetResponse.class);
assertNotNull("response should not be null", response);
assertNotNull("response source should not be null", response.getSource());
}
@Test
public void testDelete() throws Exception {
-
//first, INDEX a value
- HashMap<String, String> map = new HashMap<String, String>();
+ Map<String, String> map = new HashMap<String, String>();
map.put("content", "test");
sendBody("direct:index", map);
- String indexId = (String) template.requestBody("direct:index", map);
+ String indexId = template.requestBody("direct:index", map, String.class);
assertNotNull("indexId should be set", indexId);
//now, verify GET succeeded
- GetResponse response = (GetResponse) template.requestBody("direct:get", indexId);
+ GetResponse response = template.requestBody("direct:get", indexId, GetResponse.class);
assertNotNull("response should not be null", response);
assertNotNull("response source should not be null", response.getSource());
//now, perform DELETE
- DeleteResponse deleteResponse = (DeleteResponse) template.requestBody("direct:delete", indexId);
+ DeleteResponse deleteResponse = template.requestBody("direct:delete", indexId, DeleteResponse.class);
assertNotNull("response should not be null", deleteResponse);
//now, verify GET fails to find the indexed value
- response = (GetResponse) template.requestBody("direct:get", indexId);
+ response = template.requestBody("direct:get", indexId, GetResponse.class);
assertNotNull("response should not be null", response);
assertNull("response source should be null", response.getSource());
}
@Test
public void testIndexWithHeaders() throws Exception {
-
- HashMap<String, String> map = new HashMap<String, String>();
+ Map<String, String> map = new HashMap<String, String>();
map.put("content", "test");
Map<String, Object> headers = new HashMap<String, Object>();
@@ -86,15 +84,14 @@ public class ElasticsearchComponentTest
headers.put(ElasticsearchConfiguration.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConfiguration.PARAM_INDEX_TYPE, "tweet");
- String indexId = (String) template.requestBodyAndHeaders("direct:start", map, headers);
+ String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
assertNotNull("indexId should be set", indexId);
}
@Test
public void testGetWithHeaders() throws Exception {
-
//first, INDEX a value
- HashMap<String, String> map = new HashMap<String, String>();
+ Map<String, String> map = new HashMap<String, String>();
map.put("content", "test");
Map<String, Object> headers = new HashMap<String, Object>();
@@ -102,20 +99,19 @@ public class ElasticsearchComponentTest
headers.put(ElasticsearchConfiguration.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConfiguration.PARAM_INDEX_TYPE, "tweet");
- String indexId = (String) template.requestBodyAndHeaders("direct:start", map, headers);
+ String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
//now, verify GET
headers.put(ElasticsearchConfiguration.PARAM_OPERATION, ElasticsearchConfiguration.OPERATION_GET_BY_ID);
- GetResponse response = (GetResponse) template.requestBodyAndHeaders("direct:start", indexId, headers);
+ GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
assertNotNull("response should not be null", response);
assertNotNull("response source should not be null", response.getSource());
}
@Test
public void testDeleteWithHeaders() throws Exception {
-
//first, INDEX a value
- HashMap<String, String> map = new HashMap<String, String>();
+ Map<String, String> map = new HashMap<String, String>();
map.put("content", "test");
Map<String, Object> headers = new HashMap<String, Object>();
@@ -123,22 +119,22 @@ public class ElasticsearchComponentTest
headers.put(ElasticsearchConfiguration.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConfiguration.PARAM_INDEX_TYPE, "tweet");
- String indexId = (String) template.requestBodyAndHeaders("direct:start", map, headers);
+ String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
//now, verify GET
headers.put(ElasticsearchConfiguration.PARAM_OPERATION, ElasticsearchConfiguration.OPERATION_GET_BY_ID);
- GetResponse response = (GetResponse) template.requestBodyAndHeaders("direct:start", indexId, headers);
+ GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
assertNotNull("response should not be null", response);
assertNotNull("response source should not be null", response.getSource());
//now, perform DELETE
headers.put(ElasticsearchConfiguration.PARAM_OPERATION, ElasticsearchConfiguration.OPERATION_DELETE);
- DeleteResponse deleteResponse = (DeleteResponse) template.requestBodyAndHeaders("direct:start", indexId, headers);
+ DeleteResponse deleteResponse = template.requestBodyAndHeaders("direct:start", indexId, headers, DeleteResponse.class);
assertNotNull("response should not be null", deleteResponse);
//now, verify GET fails to find the indexed value
headers.put(ElasticsearchConfiguration.PARAM_OPERATION, ElasticsearchConfiguration.OPERATION_GET_BY_ID);
- response = (GetResponse) template.requestBodyAndHeaders("direct:start", indexId, headers);
+ response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
assertNotNull("response should not be null", response);
assertNull("response source should be null", response.getSource());
}
Modified: camel/trunk/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/SpringElasticsearchTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/SpringElasticsearchTest.java?rev=1382732&r1=1382731&r2=1382732&view=diff
==============================================================================
--- camel/trunk/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/SpringElasticsearchTest.java (original)
+++ camel/trunk/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/SpringElasticsearchTest.java Mon Sep 10 10:18:11 2012
@@ -38,7 +38,6 @@ public class SpringElasticsearchTest ext
@Test
public void testSendBody() throws Exception {
-
mock.expectedMinimumMessageCount(1);
Map<String, String> body = new HashMap<String, String>();
Modified: camel/trunk/components/camel-elasticsearch/src/test/resources/SpringElasticsearchTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-elasticsearch/src/test/resources/SpringElasticsearchTest.xml?rev=1382732&r1=1382731&r2=1382732&view=diff
==============================================================================
--- camel/trunk/components/camel-elasticsearch/src/test/resources/SpringElasticsearchTest.xml (original)
+++ camel/trunk/components/camel-elasticsearch/src/test/resources/SpringElasticsearchTest.xml Mon Sep 10 10:18:11 2012
@@ -1,3 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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 specific language governing permissions and
+ limitations under the License.
+-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="