1
1
package io .searchbox .action ;
2
2
3
3
import com .google .common .collect .HashMultimap ;
4
+ import com .google .common .collect .LinkedHashMultimap ;
4
5
import com .google .common .collect .Multimap ;
5
6
import com .google .gson .Gson ;
6
7
import com .google .gson .JsonObject ;
@@ -37,8 +38,8 @@ public abstract class AbstractAction<T extends JestResult> implements Action<T>
37
38
protected Object payload ;
38
39
39
40
private final ConcurrentMap <String , Object > headerMap = new ConcurrentHashMap <String , Object >();
40
- private final Multimap <String , Object > parameterMap = HashMultimap .create ();
41
- private final Set <String > cleanApiParameters = new HashSet <String >();
41
+ private final Multimap <String , Object > parameterMap = LinkedHashMultimap .create ();
42
+ private final Set <String > cleanApiParameters = new LinkedHashSet <String >();
42
43
private String URI ;
43
44
private String pathToResult ;
44
45
@@ -68,7 +69,7 @@ protected T createNewElasticSearchResult(T result, String responseBody, int stat
68
69
result .setJsonObject (jsonMap );
69
70
result .setPathToResult (getPathToResult ());
70
71
71
- if ((statusCode / 100 ) == 2 ) {
72
+ if (isHttpSuccessful (statusCode ) ) {
72
73
result .setSucceeded (true );
73
74
log .debug ("Request and operation succeeded" );
74
75
} else {
@@ -85,9 +86,13 @@ protected T createNewElasticSearchResult(T result, String responseBody, int stat
85
86
return result ;
86
87
}
87
88
89
+ protected boolean isHttpSuccessful (int httpCode ) {
90
+ return (httpCode / 100 ) == 2 ;
91
+ }
92
+
88
93
protected JsonObject parseResponseBody (String responseBody ) {
89
94
if (responseBody != null && !responseBody .trim ().isEmpty ()) {
90
- return new JsonParser ().parse (responseBody ).getAsJsonObject ();
95
+ return new JsonParser ().parse (responseBody ).getAsJsonObject ();
91
96
}
92
97
return new JsonObject ();
93
98
}
@@ -143,9 +148,9 @@ protected void setURI(String URI) {
143
148
144
149
@ Override
145
150
public String getData (Gson gson ) {
146
- if (payload == null ){
151
+ if (payload == null ) {
147
152
return null ;
148
- } else if (payload instanceof String ) {
153
+ } else if (payload instanceof String ) {
149
154
return (String ) payload ;
150
155
} else {
151
156
return gson .toJson (payload );
@@ -184,7 +189,7 @@ protected String buildURI() {
184
189
protected String buildQueryString () throws UnsupportedEncodingException {
185
190
StringBuilder queryString = new StringBuilder ();
186
191
187
- if (!cleanApiParameters .isEmpty ()) {
192
+ if (!cleanApiParameters .isEmpty ()) {
188
193
queryString .append ("/" ).append (StringUtils .join (cleanApiParameters , "," ));
189
194
}
190
195
@@ -246,9 +251,9 @@ public boolean equals(Object obj) {
246
251
247
252
@ SuppressWarnings ("unchecked" )
248
253
protected static abstract class Builder <T extends Action , K > {
249
- protected Multimap <String , Object > parameters = HashMultimap .<String , Object >create ();
250
- protected Map <String , Object > headers = new HashMap <String , Object >();
251
- protected Set <String > cleanApiParameters = new HashSet <String >();
254
+ protected Multimap <String , Object > parameters = LinkedHashMultimap .<String , Object >create ();
255
+ protected Map <String , Object > headers = new LinkedHashMap <String , Object >();
256
+ protected Set <String > cleanApiParameters = new LinkedHashSet <String >();
252
257
253
258
public K addCleanApiParameter (String key ) {
254
259
cleanApiParameters .add (key );
0 commit comments