diff --git a/.gitignore b/.gitignore
index d96023ed..6280c868 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,5 @@ release.properties
.settings
.project
.classpath
+/oss-java-client.iml
+/.idea/
diff --git a/pom.xml b/pom.xml
index 435b38d2..0038d89d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,150 +1,146 @@
* 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 - * + *
+ * 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. @@ -15,49 +15,71 @@ */ package com.opensearchserver.client; -import java.net.URISyntaxException; -import java.net.URI; +import com.qwazr.utils.LinkUtils; import com.qwazr.utils.StringUtils; +import com.qwazr.utils.UBuilder; +import com.qwazr.utils.http.HttpRequest; +import com.qwazr.utils.http.ResponseValidator; import com.qwazr.utils.json.client.JsonClientAbstract; import com.qwazr.utils.server.RemoteService; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; + /** * This client is for OpenSearchServer v1.5.x - * */ public class JsonClient1 extends JsonClientAbstract { + private final String baseUrl; private final String login; private final String key; - public JsonClient1(String url, String login, String key, int msTimeout) + public JsonClient1(final String baseUrl, final String login, final String key, int msTimeout) throws URISyntaxException { - super(new RemoteService(new URI(url), msTimeout)); + super(new RemoteService(new URI(baseUrl), msTimeout)); + this.baseUrl = baseUrl + "/services/rest/"; this.login = login; this.key = key; } - public JsonClient1(ServerResource serverResource) throws URISyntaxException { - this(serverResource.url, serverResource.login, serverResource.api_key, - serverResource.time_out); + public JsonClient1(final ServerResource serverResource) throws URISyntaxException { + this(serverResource.url, serverResource.login, serverResource.api_key, serverResource.time_out); } /** * Build an URL for OpenSearchServer 1.5 - * - * @param paths - * an array of path which will be concatened + * + * @param paths an array of path which will be concatened * @return a prepared URIBuilder - * @throws URISyntaxException - * if the builded URI is not valid + * @throws URISyntaxException if the builded URI is not valid */ - final public UBuilder getBaseUrl(String... paths) throws URISyntaxException { - UBuilder uriBuilder = new UBuilder(StringUtils.fastConcat( - "/services/rest/", paths)); + final public UBuilder getBaseUrl(final String... paths) throws URISyntaxException, UnsupportedEncodingException { + final StringBuilder sb = new StringBuilder(baseUrl); + if (paths != null) + for (String path : paths) { + if (path.indexOf('/') == -1) + sb.append(LinkUtils.UTF8_URL_Encode(path)); + else + sb.append(path); + } + final UBuilder uriBuilder = new UBuilder(sb.toString()); if (!StringUtils.isEmpty(login)) uriBuilder.addParameter("login", login); if (!StringUtils.isEmpty(key)) uriBuilder.addParameter("key", key); return uriBuilder; } + + final public boolean execute200True404False(final HttpRequest request, final Object bodyObject, + final Integer msTimeOut, final ResponseValidator validator) { + switch (executeStatusCode(request, bodyObject, msTimeOut, validator)) { + case 200: + return true; + case 404: + return false; + } + return false; + } } diff --git a/src/main/java/com/opensearchserver/client/common/AbstractApi.java b/src/main/java/com/opensearchserver/client/common/AbstractApi.java index f747a0cb..c15b9d46 100644 --- a/src/main/java/com/opensearchserver/client/common/AbstractApi.java +++ b/src/main/java/com/opensearchserver/client/common/AbstractApi.java @@ -1,12 +1,12 @@ /** * Copyright 2015 OpenSearchServer Inc. - * + *
* 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 - * + *
+ * 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.
@@ -15,13 +15,19 @@
*/
package com.opensearchserver.client.common;
+import com.qwazr.utils.http.ResponseValidator;
import com.qwazr.utils.json.client.JsonClientAbstract;
public class AbstractApi
* 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
- *
+ *
+ * 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.
@@ -15,18 +15,15 @@
*/
package com.opensearchserver.client.v1;
-import java.io.IOException;
-import java.net.URISyntaxException;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.client.fluent.Request;
-import org.apache.http.client.utils.URIBuilder;
-
import com.opensearchserver.client.JsonClient1;
import com.opensearchserver.client.common.AbstractApi;
import com.opensearchserver.client.common.LanguageEnum;
import com.opensearchserver.client.common.analyzer.AnalyzerItem;
-import com.qwazr.utils.http.HttpUtils;
+import com.qwazr.utils.http.HttpRequest;
+import org.apache.http.client.utils.URIBuilder;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
public class AnalyzerApi1 extends AbstractApi
* 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
- *
+ *
+ * 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.
@@ -15,16 +15,13 @@
*/
package com.opensearchserver.client.v1;
-import java.io.IOException;
-import java.net.URISyntaxException;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.client.fluent.Request;
-import org.apache.http.client.utils.URIBuilder;
-
import com.opensearchserver.client.JsonClient1;
import com.opensearchserver.client.common.AbstractApi;
-import com.qwazr.utils.http.HttpUtils;
+import com.qwazr.utils.http.HttpRequest;
+import org.apache.http.client.utils.URIBuilder;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
public class DictionaryApi1 extends AbstractApi
* 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
- *
+ *
+ * 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.
@@ -15,16 +15,15 @@
*/
package com.opensearchserver.client.v1;
-import java.io.IOException;
-import java.net.URISyntaxException;
-
-import org.apache.http.client.fluent.Request;
-import org.apache.http.client.utils.URIBuilder;
-
import com.opensearchserver.client.JsonClient1;
import com.opensearchserver.client.common.AbstractApi;
import com.opensearchserver.client.common.search.query.DocumentsQuery;
import com.opensearchserver.client.v1.search.DocumentsResult1;
+import com.qwazr.utils.http.HttpRequest;
+import org.apache.http.client.utils.URIBuilder;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
/**
* @version For OpenSearchServer v1.5.x
@@ -37,24 +36,18 @@ public DocumentApi1(JsonClient1 client) {
/**
* Create or update a search field template
- *
- * @param indexName
- * The name of the index
- * @param query
- * The query
+ *
+ * @param indexName The name of the index
+ * @param query The query
* @return the current instance
- * @throws IOException
- * if any I/O error occurs
- * @throws URISyntaxException
- * if the URI is not valid
+ * @throws IOException if any I/O error occurs
+ * @throws URISyntaxException if the URI is not valid
*/
- public DocumentsResult1 documentsSearch(String indexName,
- DocumentsQuery query) throws IOException, URISyntaxException {
- URIBuilder uriBuilder = client.getBaseUrl("index/", indexName,
- "/documents");
- Request request = Request.Post(uriBuilder.build());
- return client
- .execute(request, query, null, DocumentsResult1.class, 200);
+ public DocumentsResult1 documentsSearch(String indexName, DocumentsQuery query)
+ throws IOException, URISyntaxException {
+ final URIBuilder uriBuilder = client.getBaseUrl("index/", indexName, "/documents");
+ final HttpRequest request = HttpRequest.Post(uriBuilder.build());
+ return client.executeJson(request, query, null, DocumentsResult1.class, validator_200);
}
}
diff --git a/src/main/java/com/opensearchserver/client/v1/FieldApi1.java b/src/main/java/com/opensearchserver/client/v1/FieldApi1.java
index 8822e3da..35708ef3 100644
--- a/src/main/java/com/opensearchserver/client/v1/FieldApi1.java
+++ b/src/main/java/com/opensearchserver/client/v1/FieldApi1.java
@@ -1,12 +1,12 @@
/**
* Copyright 2015 OpenSearchServer Inc.
- *
+ *
* 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
- *
+ *
+ * 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.
@@ -15,20 +15,17 @@
*/
package com.opensearchserver.client.v1;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.List;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.client.fluent.Request;
-import org.apache.http.client.utils.URIBuilder;
-
import com.opensearchserver.client.JsonClient1;
import com.opensearchserver.client.common.AbstractApi;
import com.opensearchserver.client.v1.field.ResultField;
import com.opensearchserver.client.v1.field.ResultFieldList;
import com.opensearchserver.client.v1.field.SchemaField;
-import com.qwazr.utils.http.HttpUtils;
+import com.qwazr.utils.http.HttpRequest;
+import org.apache.http.client.utils.URIBuilder;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.List;
public class FieldApi1 extends AbstractApi
* 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
- *
+ *
+ * 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.
@@ -15,17 +15,14 @@
*/
package com.opensearchserver.client.v1;
-import java.io.IOException;
-import java.net.URISyntaxException;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.client.fluent.Request;
-import org.apache.http.client.utils.URIBuilder;
-
import com.opensearchserver.client.JsonClient1;
import com.opensearchserver.client.common.AbstractApi;
import com.opensearchserver.client.common.index.TemplateEnum;
-import com.qwazr.utils.http.HttpUtils;
+import com.qwazr.utils.http.HttpRequest;
+import org.apache.http.client.utils.URIBuilder;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
public class IndexApi1 extends AbstractApi
* 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
- *
+ *
+ * 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.
@@ -15,17 +15,16 @@
*/
package com.opensearchserver.client.v1;
-import java.io.IOException;
-import java.net.URISyntaxException;
-
-import org.apache.http.client.fluent.Request;
-import org.apache.http.client.utils.URIBuilder;
-
import com.opensearchserver.client.JsonClient1;
import com.opensearchserver.client.common.AbstractApi;
import com.opensearchserver.client.common.CommonResult;
import com.opensearchserver.client.v1.replication.ReplicationItem;
import com.opensearchserver.client.v1.replication.ReplicationResult;
+import com.qwazr.utils.http.HttpRequest;
+import org.apache.http.client.utils.URIBuilder;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
/**
* @version For OpenSearchServer v1.5.x
@@ -38,89 +37,69 @@ public ReplicationApi1(JsonClient1 client) {
/**
* Retrieve a replication item
- *
- * @param indexName
- * the name of the index
- * @param replicationName
- * the name of the replication item
+ *
+ * @param indexName the name of the index
+ * @param replicationName the name of the replication item
* @return a replication item
- * @throws IOException
- * if any IO error occurs
- * @throws URISyntaxException
- * if the URI is not valid
+ * @throws IOException if any IO error occurs
+ * @throws URISyntaxException if the URI is not valid
*/
- public ReplicationResult getReplication(String indexName,
- String replicationName) throws IOException, URISyntaxException {
- URIBuilder uriBuilder = client.getBaseUrl("index/", indexName,
- "/replication").addParameter("name", replicationName);
- Request request = Request.Get(uriBuilder.build());
- return client
- .execute(request, null, null, ReplicationResult.class, 200);
+ public ReplicationResult getReplication(String indexName, String replicationName)
+ throws IOException, URISyntaxException {
+ final URIBuilder uriBuilder =
+ client.getBaseUrl("index/", indexName, "/replication").addParameter("name", replicationName);
+ final HttpRequest request = HttpRequest.Get(uriBuilder.build());
+ return client.executeJson(request, null, null, ReplicationResult.class, validator_200);
}
/**
* Create or update a replication item
- *
- * @param indexName
- * the name of the index
- * @param replicationItem
- * the replication item
+ *
+ * @param indexName the name of the index
+ * @param replicationItem the replication item
* @return the status
- * @throws IOException
- * if any IO error occurs
- * @throws URISyntaxException
- * if the URI is not valid
+ * @throws IOException if any IO error occurs
+ * @throws URISyntaxException if the URI is not valid
*/
- public CommonResult createUpdateReplication(String indexName,
- ReplicationItem replicationItem) throws IOException,
- URISyntaxException {
- URIBuilder uriBuilder = client.getBaseUrl("index/", indexName,
- "/replication");
- Request request = Request.Put(uriBuilder.build());
- return client.execute(request, replicationItem, null,
- CommonResult.class, 200, 201);
+ public CommonResult createUpdateReplication(String indexName, ReplicationItem replicationItem)
+ throws IOException, URISyntaxException {
+ final URIBuilder uriBuilder = client.getBaseUrl("index/", indexName, "/replication");
+ final HttpRequest request = HttpRequest.Put(uriBuilder.build());
+ return client.executeJson(request, replicationItem, null, CommonResult.class, validator_200_201);
}
/**
* Start a replication process
- *
- * @param indexName
- * the name of the index
- * @param replicationName
- * the name of the replication item
+ *
+ * @param indexName the name of the index
+ * @param replicationName the name of the replication item
* @return the status
- * @throws IOException
- * if any IO error occurs
- * @throws URISyntaxException
- * if the URI is not valid
+ * @throws IOException if any IO error occurs
+ * @throws URISyntaxException if the URI is not valid
*/
- public CommonResult executeReplication(String indexName,
- String replicationName) throws IOException, URISyntaxException {
- URIBuilder uriBuilder = client.getBaseUrl("index/", indexName,
- "/replication/run").addParameter("name", replicationName);
- Request request = Request.Put(uriBuilder.build());
- return client.execute(request, null, null, CommonResult.class, 200);
+ public CommonResult executeReplication(String indexName, String replicationName)
+ throws IOException, URISyntaxException {
+ final URIBuilder uriBuilder =
+ client.getBaseUrl("index/", indexName, "/replication/run").addParameter("name", replicationName);
+ final HttpRequest request = HttpRequest.Put(uriBuilder.build());
+ return client.executeJson(request, null, null, CommonResult.class, validator_200);
}
/**
* Delete a replication item
- *
- * @param indexName
- * the name of the index
- * @param replicationName
- * the name of the replication item
+ *
+ * @param indexName the name of the index
+ * @param replicationName the name of the replication item
* @return the status
- * @throws IOException
- * if any IO error occurs
- * @throws URISyntaxException
- * if the URI is not valid
+ * @throws IOException if any IO error occurs
+ * @throws URISyntaxException if the URI is not valid
*/
- public CommonResult deleteReplication(String indexName,
- String replicationName) throws IOException, URISyntaxException {
- URIBuilder uriBuilder = client.getBaseUrl("index/", indexName,
- "/replication").addParameter("name", replicationName);
- Request request = Request.Delete(uriBuilder.build());
- return client.execute(request, null, null, CommonResult.class, 200);
+ public CommonResult deleteReplication(String indexName, String replicationName)
+ throws IOException, URISyntaxException {
+ final URIBuilder uriBuilder =
+ client.getBaseUrl("index/", indexName, "/replication").addParameter("name", replicationName);
+ final HttpRequest request = HttpRequest.Delete(uriBuilder.build());
+ return client.executeJson(request, null, null, CommonResult.class, validator_200);
}
}
diff --git a/src/main/java/com/opensearchserver/client/v1/SearchApi1.java b/src/main/java/com/opensearchserver/client/v1/SearchApi1.java
index 26f93863..ff84438f 100644
--- a/src/main/java/com/opensearchserver/client/v1/SearchApi1.java
+++ b/src/main/java/com/opensearchserver/client/v1/SearchApi1.java
@@ -1,12 +1,12 @@
/**
* Copyright 2015 OpenSearchServer Inc.
- *
+ *
* 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
- *
+ *
+ * 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.
@@ -15,21 +15,18 @@
*/
package com.opensearchserver.client.v1;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.List;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.client.fluent.Request;
-import org.apache.http.client.utils.URIBuilder;
-
import com.opensearchserver.client.JsonClient1;
import com.opensearchserver.client.common.AbstractApi;
import com.opensearchserver.client.common.search.query.SearchFieldQuery;
import com.opensearchserver.client.common.search.query.SearchPatternQuery;
import com.opensearchserver.client.common.search.query.SearchQueryBatch;
import com.opensearchserver.client.v1.search.SearchResult1;
-import com.qwazr.utils.http.HttpUtils;
+import com.qwazr.utils.http.HttpRequest;
+import org.apache.http.client.utils.URIBuilder;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.List;
/**
* @version For OpenSearchServer v1.5.x
@@ -42,137 +39,100 @@ public SearchApi1(JsonClient1 client) {
/**
* Create or update a search field template
- *
- * @param indexName
- * The name of the index
- * @param template
- * The name of the template
- * @param query
- * The query
- * @throws IOException
- * if any IO error occurs
- * @throws URISyntaxException
- * if the URI is not valid
+ *
+ * @param indexName The name of the index
+ * @param template The name of the template
+ * @param query The query
+ * @throws IOException if any IO error occurs
+ * @throws URISyntaxException if the URI is not valid
*/
- public void createSearchFieldTemplate(String indexName, String template,
- SearchFieldQuery query) throws IOException, URISyntaxException {
- URIBuilder uriBuilder = client.getBaseUrl("index/", indexName,
- "/search/field/", template);
- Request request = Request.Put(uriBuilder.build());
- HttpResponse response = client.execute(request, query, null);
- HttpUtils.checkStatusCodes(response, 200, 201);
+ public void createSearchFieldTemplate(String indexName, String template, SearchFieldQuery query)
+ throws IOException, URISyntaxException {
+ final URIBuilder uriBuilder = client.getBaseUrl("index/", indexName, "/search/field/", template);
+ final HttpRequest request = HttpRequest.Put(uriBuilder.build());
+ client.execute(request, query, null, validator_200_201);
}
/**
* Execute a search with a search field template
- *
- * @param indexName
- * The name of the index
- * @param template
- * The name of the template
- * @param query
- * Any overriding query parameter
+ *
+ * @param indexName The name of the index
+ * @param template The name of the template
+ * @param query Any overriding query parameter
* @return the search result
- * @throws IOException
- * if any IO error occurs
- * @throws URISyntaxException
- * if the URI is not valid
+ * @throws IOException if any IO error occurs
+ * @throws URISyntaxException if the URI is not valid
*/
- public SearchResult1 executeSearchFieldTemplate(String indexName,
- String template, SearchFieldQuery query) throws IOException,
- URISyntaxException {
- URIBuilder uriBuilder = client.getBaseUrl("index/", indexName,
- "/search/field/", template);
- Request request = Request.Post(uriBuilder.build());
- return client.execute(request, query, null, SearchResult1.class, 200);
+ public SearchResult1 executeSearchFieldTemplate(String indexName, String template, SearchFieldQuery query)
+ throws IOException, URISyntaxException {
+ final URIBuilder uriBuilder = client.getBaseUrl("index/", indexName, "/search/field/", template);
+ final HttpRequest request = HttpRequest.Post(uriBuilder.build());
+ return client.executeJson(request, query, null, SearchResult1.class, validator_200);
}
/**
* Execute a search with a search field template
- *
- * @param indexName
- * The name of the index
- * @param template
- * The name of the template
- * @param query
- * Any overriding query parameter
+ *
+ * @param indexName The name of the index
+ * @param template The name of the template
+ * @param query Any overriding query parameter
* @return the search result
- * @throws IOException
- * if any IO error occurs
- * @throws URISyntaxException
- * if the URI is not valid
+ * @throws IOException if any IO error occurs
+ * @throws URISyntaxException if the URI is not valid
*/
- public SearchResult1 executeSearchPatternTemplate(String indexName,
- String template, SearchPatternQuery query) throws IOException,
- URISyntaxException {
- URIBuilder uriBuilder = client.getBaseUrl("index/", indexName,
- "/search/pattern/", template);
- Request request = Request.Post(uriBuilder.build());
- return client.execute(request, query, null, SearchResult1.class, 200);
+ public SearchResult1 executeSearchPatternTemplate(String indexName, String template, SearchPatternQuery query)
+ throws IOException, URISyntaxException {
+ final URIBuilder uriBuilder = client.getBaseUrl("index/", indexName, "/search/pattern/", template);
+ final HttpRequest request = HttpRequest.Post(uriBuilder.build());
+ return client.executeJson(request, query, null, SearchResult1.class, validator_200);
}
/**
* Execute a search field
- *
- * @param indexName
- * The name of the index
- * @param query
- * Any overriding query parameter
+ *
+ * @param indexName The name of the index
+ * @param query Any overriding query parameter
* @return the search result
- * @throws IOException
- * if any IO error occurs
- * @throws URISyntaxException
- * if the URI is not valid
+ * @throws IOException if any IO error occurs
+ * @throws URISyntaxException if the URI is not valid
*/
- public SearchResult1 executeSearchField(String indexName,
- SearchFieldQuery query) throws IOException, URISyntaxException {
- URIBuilder uriBuilder = client.getBaseUrl("index/", indexName,
- "/search/field");
- Request request = Request.Post(uriBuilder.build());
- return client.execute(request, query, null, SearchResult1.class, 200);
+ public SearchResult1 executeSearchField(String indexName, SearchFieldQuery query)
+ throws IOException, URISyntaxException {
+ final URIBuilder uriBuilder = client.getBaseUrl("index/", indexName, "/search/field");
+ final HttpRequest request = HttpRequest.Post(uriBuilder.build());
+ return client.executeJson(request, query, null, SearchResult1.class, validator_200);
}
/**
* Execute a search pattern
- *
- * @param indexName
- * The name of the index
- * @param query
- * Any overriding query parameter
+ *
+ * @param indexName The name of the index
+ * @param query Any overriding query parameter
* @return the search result
- * @throws IOException
- * if any IO error occurs
- * @throws URISyntaxException
- * if the URI is not valid
+ * @throws IOException if any IO error occurs
+ * @throws URISyntaxException if the URI is not valid
*/
- public SearchResult1 executeSearchPattern(String indexName,
- SearchPatternQuery query) throws IOException, URISyntaxException {
- URIBuilder uriBuilder = client.getBaseUrl("index/", indexName,
- "/search/pattern");
- Request request = Request.Post(uriBuilder.build());
- return client.execute(request, query, null, SearchResult1.class, 200);
+ public SearchResult1 executeSearchPattern(String indexName, SearchPatternQuery query)
+ throws IOException, URISyntaxException {
+ final URIBuilder uriBuilder = client.getBaseUrl("index/", indexName, "/search/pattern");
+ final HttpRequest request = HttpRequest.Post(uriBuilder.build());
+ return client.executeJson(request, query, null, SearchResult1.class, validator_200);
}
/**
* Execute a batch of search
- *
- * @param indexName
- * The name of the index
- * @param queryBatch
- * The queries
+ *
+ * @param indexName The name of the index
+ * @param queryBatch The queries
* @return a list of results
- * @throws IOException
- * if any IO error occurs
- * @throws URISyntaxException
- * if the URI is not valid
+ * @throws IOException if any IO error occurs
+ * @throws URISyntaxException if the URI is not valid
*/
- public List
* 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
- *
+ *
+ * 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.
@@ -15,20 +15,17 @@
*/
package com.opensearchserver.client.v1;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.client.fluent.Request;
-import org.apache.http.client.utils.URIBuilder;
-
import com.opensearchserver.client.JsonClient1;
import com.opensearchserver.client.common.AbstractApi;
import com.opensearchserver.client.common.LanguageEnum;
import com.opensearchserver.client.common.update.DocumentUpdate;
-import com.qwazr.utils.http.HttpUtils;
+import com.qwazr.utils.http.HttpRequest;
+import org.apache.http.client.utils.URIBuilder;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
public class UpdateApi1 extends AbstractApi
* 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
- *
+ *
+ * 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.
@@ -15,15 +15,6 @@
*/
package com.opensearchserver.client.v1;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlTransient;
-
-import org.apache.http.client.fluent.Request;
-import org.apache.http.client.utils.URIBuilder;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.type.TypeReference;
import com.opensearchserver.client.JsonClient1;
@@ -31,6 +22,13 @@
import com.opensearchserver.client.common.CommonListResult;
import com.opensearchserver.client.common.CommonResult;
import com.opensearchserver.client.v1.search.FieldValueList1;
+import com.qwazr.utils.http.HttpRequest;
+import org.apache.http.client.utils.URIBuilder;
+
+import javax.xml.bind.annotation.XmlTransient;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.List;
public class WebCrawlerApi1 extends AbstractApi
* 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
- *
+ *
+ * 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.
@@ -15,14 +15,6 @@
*/
package com.opensearchserver.client.test.v1;
-import java.io.IOException;
-import java.net.URISyntaxException;
-
-import org.junit.Assert;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
import com.opensearchserver.client.common.index.TemplateEnum;
import com.opensearchserver.client.common.search.query.SearchFieldQuery;
import com.opensearchserver.client.v1.IndexApi1;
@@ -31,14 +23,20 @@
import com.opensearchserver.client.v1.replication.ReplicationItem;
import com.opensearchserver.client.v1.replication.ReplicationResult;
import com.opensearchserver.client.v1.replication.ReplicationType;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ReplicationTest extends AbstractTest {
public static final String INDEX_NAME = "oss-java-client test replication";
public static final String INDEX_NAME_REPL = "oss-java-client test replication repl";
- public static final String REPLICATION_ITEM_NAME = OSS_URL + "/"
- + INDEX_NAME_REPL;
+ public static final String REPLICATION_ITEM_NAME = OSS_URL + "/" + INDEX_NAME_REPL;
public static final Integer REPLICATION_TIME_OUT = 60;
public static final String SEARCH_TEMPLATE_NAME = "search";
@@ -54,31 +52,28 @@ public void test001createIndexes() throws IOException, URISyntaxException {
}
@Test
- public void test010createReplication() throws IOException,
- URISyntaxException {
+ public void test010createReplication() throws IOException, URISyntaxException {
ReplicationApi1 replicationApi = new ReplicationApi1(client);
- ReplicationItem replicationItem = new ReplicationItem()
- .setReplicationType(ReplicationType.BACKUP_INDEX)
- .setRemoteUrl(OSS_URL).setRemoteIndexName(INDEX_NAME_REPL)
- .setRemoteLogin(OSS_LOGIN).setRemoteApiKey(OSS_APIKEY)
+ ReplicationItem replicationItem = new ReplicationItem().setReplicationType(ReplicationType.BACKUP_INDEX)
+ .setRemoteUrl(OSS_URL)
+ .setRemoteIndexName(INDEX_NAME_REPL)
+ .setRemoteLogin(OSS_LOGIN)
+ .setRemoteApiKey(OSS_APIKEY)
.setSecTimeOut(REPLICATION_TIME_OUT);
replicationApi.createUpdateReplication(INDEX_NAME, replicationItem);
}
@Test
- public void test020executeReplication() throws IOException,
- URISyntaxException {
+ public void test020executeReplication() throws IOException, URISyntaxException {
ReplicationApi1 replicationApi = new ReplicationApi1(client);
replicationApi.executeReplication(INDEX_NAME, REPLICATION_ITEM_NAME);
}
@Test
- public void test030waitReplication() throws IOException,
- URISyntaxException, InterruptedException {
+ public void test030waitReplication() throws IOException, URISyntaxException, InterruptedException {
ReplicationApi1 replicationApi = new ReplicationApi1(client);
for (int i = 0; i < 60; i++) {
- ReplicationResult result = replicationApi.getReplication(
- INDEX_NAME, REPLICATION_ITEM_NAME);
+ ReplicationResult result = replicationApi.getReplication(INDEX_NAME, REPLICATION_ITEM_NAME);
if (result.lastThread != null && !result.isActiveThread)
return;
Thread.sleep(2000);
@@ -89,15 +84,12 @@ public void test030waitReplication() throws IOException,
@Test
public void test040search() throws IOException, URISyntaxException {
SearchApi1 searchApi1 = new SearchApi1(client);
- SearchFieldQuery query = (SearchFieldQuery) new SearchFieldQuery()
- .setQuery("test");
- searchApi1.executeSearchFieldTemplate(INDEX_NAME_REPL,
- SEARCH_TEMPLATE_NAME, query);
+ SearchFieldQuery query = (SearchFieldQuery) new SearchFieldQuery().setQuery("test");
+ searchApi1.executeSearchFieldTemplate(INDEX_NAME_REPL, SEARCH_TEMPLATE_NAME, query);
}
@Test
- public void test500deleteReplication() throws IOException,
- URISyntaxException {
+ public void test500deleteReplication() throws IOException, URISyntaxException {
ReplicationApi1 replicationApi = new ReplicationApi1(client);
replicationApi.deleteReplication(INDEX_NAME, REPLICATION_ITEM_NAME);
}
diff --git a/src/test/java/com/opensearchserver/client/test/v1/SearchFieldTest.java b/src/test/java/com/opensearchserver/client/test/v1/SearchFieldTest.java
index cac69642..f8a39e05 100644
--- a/src/test/java/com/opensearchserver/client/test/v1/SearchFieldTest.java
+++ b/src/test/java/com/opensearchserver/client/test/v1/SearchFieldTest.java
@@ -1,12 +1,12 @@
/**
* Copyright 2015 OpenSearchServer Inc.
- *
+ *
* 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
- *
+ *
+ * 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.
@@ -15,11 +15,6 @@
*/
package com.opensearchserver.client.test.v1;
-import java.io.IOException;
-import java.net.URISyntaxException;
-
-import org.junit.Test;
-
import com.opensearchserver.client.JsonClient1;
import com.opensearchserver.client.common.search.query.SearchField;
import com.opensearchserver.client.common.search.query.SearchField.SearchFieldMode;
@@ -28,30 +23,31 @@
import com.opensearchserver.client.v1.SearchApi1;
import com.opensearchserver.client.v1.search.SearchResult1;
import com.qwazr.utils.json.JsonMapper;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
public class SearchFieldTest {
@Test
public void testSearchBooleanGroup() throws IOException, URISyntaxException {
- JsonClient1 client = new JsonClient1("http://localhost:8080", null,
- null, 50000);
+ JsonClient1 client = new JsonClient1("http://localhost:8080", null, null, 50000);
String queryGroup1 = "open search server";
String queryGroup2 = "en";
SearchApi1 searchApi = new SearchApi1(client);
- SearchFieldQuery searchFieldQuery = (SearchFieldQuery) new SearchFieldQuery()
- .setEmptyReturnsAll(false).setOperator(OperatorEnum.AND);
+ SearchFieldQuery searchFieldQuery =
+ (SearchFieldQuery) new SearchFieldQuery().setEmptyReturnsAll(false).setOperator(OperatorEnum.AND);
// If the queryGroup1 is not empty, we add the required fields
if (queryGroup1 != null && !queryGroup1.isEmpty()) {
// Create the search fields, affected to the first boolean group
- searchFieldQuery.addSearchField(new SearchField()
- .setField("content").setMode(SearchFieldMode.PATTERN)
- .setBooleanGroup(1));
+ searchFieldQuery.addSearchField(
+ new SearchField().setField("content").setMode(SearchFieldMode.PATTERN).setBooleanGroup(1));
- searchFieldQuery.addSearchField(new SearchField()
- .setField("contentExact").setMode(SearchFieldMode.PATTERN)
- .setBooleanGroup(1));
+ searchFieldQuery.addSearchField(
+ new SearchField().setField("contentExact").setMode(SearchFieldMode.PATTERN).setBooleanGroup(1));
// We set the text query
searchFieldQuery.setQueryStringMap("content", queryGroup1);
@@ -63,16 +59,14 @@ public void testSearchBooleanGroup() throws IOException, URISyntaxException {
if (queryGroup2 != null && !queryGroup2.isEmpty()) {
// Create the search fields, affected to the first boolean group
- searchFieldQuery.addSearchField(new SearchField().setField("lang")
- .setMode(SearchFieldMode.PATTERN).setBooleanGroup(2));
+ searchFieldQuery.addSearchField(
+ new SearchField().setField("lang").setMode(SearchFieldMode.PATTERN).setBooleanGroup(2));
searchFieldQuery.setQueryStringMap("lang", queryGroup2);
}
- System.out.println(JsonMapper.MAPPER
- .writeValueAsString(searchFieldQuery));
- SearchResult1 searchResult = searchApi.executeSearchField("web",
- searchFieldQuery);
+ System.out.println(JsonMapper.MAPPER.writeValueAsString(searchFieldQuery));
+ SearchResult1 searchResult = searchApi.executeSearchField("web", searchFieldQuery);
System.out.println(JsonMapper.MAPPER.writeValueAsString(searchResult));
}
> crawlWithData(
- String indexName, String url, Integer msTimeOut)
+ public CommonListResult
> crawlWithData(String indexName, String url, Integer msTimeOut)
throws IOException, URISyntaxException {
- URIBuilder uriBuilder = client
- .getBaseUrl("index/", indexName, "/crawler/web/crawl")
- .addParameter("url", url).addParameter("returnData", "true");
- Request request = Request.Get(uriBuilder.build());
- return client.execute(request, null, msTimeOut, LISTCRAWL_TYPEREF, 200);
+ final URIBuilder uriBuilder = client.getBaseUrl("index/", indexName, "/crawler/web/crawl")
+ .addParameter("url", url)
+ .addParameter("returnData", "true");
+ final HttpRequest request = HttpRequest.Get(uriBuilder.build());
+ return client.executeJson(request, null, msTimeOut, LISTCRAWL_TYPEREF, validator_200);
}
/**
* Crawl an URL
- *
- * @param indexName
- * The name of the index
- * @param url
- * The URL to crawl
- * @param msTimeOut
- * The timeout in milliseconds
+ *
+ * @param indexName The name of the index
+ * @param url The URL to crawl
+ * @param msTimeOut The timeout in milliseconds
* @return the status of the crawl
- * @throws IOException
- * if any IO error occurs
- * @throws URISyntaxException
- * if the URI is not valid
+ * @throws IOException if any IO error occurs
+ * @throws URISyntaxException if the URI is not valid
*/
- public CommonResult crawl(String indexName, String url, Integer msTimeOut)
- throws IOException, URISyntaxException {
- URIBuilder uriBuilder = client
- .getBaseUrl("index/", indexName, "/crawler/web/crawl")
- .addParameter("url", url).addParameter("returnData", "false");
- Request request = Request.Get(uriBuilder.build());
- return client
- .execute(request, null, msTimeOut, CommonResult.class, 200);
+ public CommonResult crawl(String indexName, String url, Integer msTimeOut) throws IOException, URISyntaxException {
+ final URIBuilder uriBuilder = client.getBaseUrl("index/", indexName, "/crawler/web/crawl")
+ .addParameter("url", url)
+ .addParameter("returnData", "false");
+ final HttpRequest request = HttpRequest.Get(uriBuilder.build());
+ return client.executeJson(request, null, msTimeOut, CommonResult.class, validator_200);
}
/**
* Enable or disable pattern inclusion and exclusion
- *
- * @param indexName
- * The name of the index
- * @param inclusionStatus
- * Enable or disable inclusion list
- * @param exclusionStatus
- * Enable or disable inclusion list
+ *
+ * @param indexName The name of the index
+ * @param inclusionStatus Enable or disable inclusion list
+ * @param exclusionStatus Enable or disable inclusion list
* @return the result of the call
- * @throws IOException
- * if any IO error occurs
- * @throws URISyntaxException
- * if the URI is not valid
+ * @throws IOException if any IO error occurs
+ * @throws URISyntaxException if the URI is not valid
*/
- public CommonResult setPatternStatus(String indexName,
- Boolean inclusionStatus, Boolean exclusionStatus)
+ public CommonResult setPatternStatus(String indexName, Boolean inclusionStatus, Boolean exclusionStatus)
throws IOException, URISyntaxException {
- URIBuilder uriBuilder = client.getBaseUrl("index/", indexName,
- "/crawler/web/patterns/status");
+ final URIBuilder uriBuilder = client.getBaseUrl("index/", indexName, "/crawler/web/patterns/status");
if (inclusionStatus != null)
uriBuilder.addParameter("inclusion", inclusionStatus.toString());
if (exclusionStatus != null)
uriBuilder.addParameter("exclusion", exclusionStatus.toString());
- Request request = Request.Put(uriBuilder.build());
- return client.execute(request, null, null, CommonResult.class, 200);
+ final HttpRequest request = HttpRequest.Put(uriBuilder.build());
+ return client.executeJson(request, null, null, CommonResult.class, validator_200);
}
}
diff --git a/src/test/java/com/opensearchserver/client/test/v1/ReplicationTest.java b/src/test/java/com/opensearchserver/client/test/v1/ReplicationTest.java
index db8fa39b..2e17cc85 100644
--- a/src/test/java/com/opensearchserver/client/test/v1/ReplicationTest.java
+++ b/src/test/java/com/opensearchserver/client/test/v1/ReplicationTest.java
@@ -1,12 +1,12 @@
/**
* Copyright 2015 OpenSearchServer Inc.
- *
+ *