You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2017/10/26 13:31:56 UTC
[camel] 01/02: CAMEL-11949 - Camel-Elasticsearch5-Rest: Add a Ping
Operation to Producer
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9c12472b671a94efd9a83a7af721797612a5f32a
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Oct 26 15:25:46 2017 +0200
CAMEL-11949 - Camel-Elasticsearch5-Rest: Add a Ping Operation to Producer
---
.../elasticsearch5/ElasticsearchOperation.java | 3 +-
.../elasticsearch5/ElasticsearchProducer.java | 3 +-
.../elasticsearch5/ElasticsearchPingTest.java | 39 ++++++++++++++++++++++
3 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchOperation.java b/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchOperation.java
index 11b57f8..fee5cff 100644
--- a/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchOperation.java
+++ b/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchOperation.java
@@ -40,7 +40,8 @@ public enum ElasticsearchOperation {
Delete("Delete"),
DeleteIndex("DeleteIndex"),
Search("Search"),
- Exists("Exists");
+ Exists("Exists"),
+ Ping("Ping");
private final String text;
diff --git a/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java b/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
index 620174d..a6daf57 100644
--- a/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
+++ b/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
@@ -201,10 +201,11 @@ public class ElasticsearchProducer extends DefaultProducer {
} else if (operation == ElasticsearchOperation.Search) {
SearchRequest searchRequest = ElasticsearchActionRequestConverter.toSearchRequest(message.getBody(), exchange);
message.setBody(restHighLevelClient.search(searchRequest).getHits());
+ } else if (operation == ElasticsearchOperation.Ping) {
+ message.setBody(restHighLevelClient.ping());
} else {
throw new IllegalArgumentException(ElasticsearchConstants.PARAM_OPERATION + " value '" + operation + "' is not supported");
}
-
// If we set params via the configuration on this exchange, remove them
// now. This preserves legacy behavior for this component and enables a
// use case where one message can be sent to multiple elasticsearch
diff --git a/components/camel-elasticsearch5-rest/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchPingTest.java b/components/camel-elasticsearch5-rest/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchPingTest.java
new file mode 100644
index 0000000..f350670
--- /dev/null
+++ b/components/camel-elasticsearch5-rest/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchPingTest.java
@@ -0,0 +1,39 @@
+/**
+ * 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.
+ */
+package org.apache.camel.component.elasticsearch5;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class ElasticsearchPingTest extends ElasticsearchBaseTest {
+
+ @Test
+ public void testPing() throws Exception {
+ boolean pingResult = template.requestBody("direct:ping", "test", Boolean.class);
+ assertTrue("indexId should be set", pingResult);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:ping").to("elasticsearch5-rest://elasticsearch?operation=Ping&hostAddresses=localhost:" + ES_BASE_HTTP_PORT);
+ }
+ };
+ }
+}
--
To stop receiving notification emails like this one, please contact
"commits@camel.apache.org" <co...@camel.apache.org>.