@@ -960,6 +960,11 @@ public final void fieldCapsAsync(FieldCapabilitiesRequest fieldCapabilitiesReque
960
960
FieldCapabilitiesResponse ::fromXContent , listener , emptySet ());
961
961
}
962
962
963
+ /**
964
+ * @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
965
+ * layer has been added to the ReST client, and requests should extend {@link Validatable} instead of {@link ActionRequest}.
966
+ */
967
+ @ Deprecated
963
968
protected final <Req extends ActionRequest , Resp > Resp performRequestAndParseEntity (Req request ,
964
969
CheckedFunction <Req , Request , IOException > requestConverter ,
965
970
RequestOptions options ,
@@ -969,15 +974,58 @@ protected final <Req extends ActionRequest, Resp> Resp performRequestAndParseEnt
969
974
response -> parseEntity (response .getEntity (), entityParser ), ignores );
970
975
}
971
976
977
+ /**
978
+ * Defines a helper method for performing a request and then parsing the returned entity using the provided entityParser.
979
+ */
980
+ protected final <Req extends Validatable , Resp > Resp performRequestAndParseEntity (Req request ,
981
+ CheckedFunction <Req , Request , IOException > requestConverter ,
982
+ RequestOptions options ,
983
+ CheckedFunction <XContentParser , Resp , IOException > entityParser ,
984
+ Set <Integer > ignores ) throws IOException {
985
+ return performRequest (request , requestConverter , options ,
986
+ response -> parseEntity (response .getEntity (), entityParser ), ignores );
987
+ }
988
+
989
+ /**
990
+ * @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
991
+ * layer has been added to the ReST client, and requests should extend {@link Validatable} instead of {@link ActionRequest}.
992
+ */
993
+ @ Deprecated
972
994
protected final <Req extends ActionRequest , Resp > Resp performRequest (Req request ,
973
- CheckedFunction <Req , Request , IOException > requestConverter ,
974
- RequestOptions options ,
975
- CheckedFunction <Response , Resp , IOException > responseConverter ,
976
- Set <Integer > ignores ) throws IOException {
995
+ CheckedFunction <Req , Request , IOException > requestConverter ,
996
+ RequestOptions options ,
997
+ CheckedFunction <Response , Resp , IOException > responseConverter ,
998
+ Set <Integer > ignores ) throws IOException {
977
999
ActionRequestValidationException validationException = request .validate ();
978
- if (validationException != null ) {
1000
+ if (validationException != null && validationException . validationErrors (). isEmpty () == false ) {
979
1001
throw validationException ;
980
1002
}
1003
+ return internalPerformRequest (request , requestConverter , options , responseConverter , ignores );
1004
+ }
1005
+
1006
+ /**
1007
+ * Defines a helper method for performing a request.
1008
+ */
1009
+ protected final <Req extends Validatable , Resp > Resp performRequest (Req request ,
1010
+ CheckedFunction <Req , Request , IOException > requestConverter ,
1011
+ RequestOptions options ,
1012
+ CheckedFunction <Response , Resp , IOException > responseConverter ,
1013
+ Set <Integer > ignores ) throws IOException {
1014
+ ValidationException validationException = request .validate ();
1015
+ if (validationException != null && validationException .validationErrors ().isEmpty () == false ) {
1016
+ throw validationException ;
1017
+ }
1018
+ return internalPerformRequest (request , requestConverter , options , responseConverter , ignores );
1019
+ }
1020
+
1021
+ /**
1022
+ * Provides common functionality for performing a request.
1023
+ */
1024
+ private <Req , Resp > Resp internalPerformRequest (Req request ,
1025
+ CheckedFunction <Req , Request , IOException > requestConverter ,
1026
+ RequestOptions options ,
1027
+ CheckedFunction <Response , Resp , IOException > responseConverter ,
1028
+ Set <Integer > ignores ) throws IOException {
981
1029
Request req = requestConverter .apply (request );
982
1030
req .setOptions (options );
983
1031
Response response ;
@@ -1005,25 +1053,75 @@ protected final <Req extends ActionRequest, Resp> Resp performRequest(Req reques
1005
1053
}
1006
1054
}
1007
1055
1056
+ /**
1057
+ * @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
1058
+ * layer has been added to the ReST client, and requests should extend {@link Validatable} instead of {@link ActionRequest}.
1059
+ */
1060
+ @ Deprecated
1008
1061
protected final <Req extends ActionRequest , Resp > void performRequestAsyncAndParseEntity (Req request ,
1009
- CheckedFunction <Req , Request , IOException > requestConverter ,
1010
- RequestOptions options ,
1011
- CheckedFunction <XContentParser , Resp , IOException > entityParser ,
1012
- ActionListener <Resp > listener , Set <Integer > ignores ) {
1062
+ CheckedFunction <Req , Request , IOException > requestConverter ,
1063
+ RequestOptions options ,
1064
+ CheckedFunction <XContentParser , Resp , IOException > entityParser ,
1065
+ ActionListener <Resp > listener , Set <Integer > ignores ) {
1013
1066
performRequestAsync (request , requestConverter , options ,
1014
1067
response -> parseEntity (response .getEntity (), entityParser ), listener , ignores );
1015
1068
}
1016
1069
1070
+ /**
1071
+ * Defines a helper method for asynchronously performing a request.
1072
+ */
1073
+ protected final <Req extends Validatable , Resp > void performRequestAsyncAndParseEntity (Req request ,
1074
+ CheckedFunction <Req , Request , IOException > requestConverter ,
1075
+ RequestOptions options ,
1076
+ CheckedFunction <XContentParser , Resp , IOException > entityParser ,
1077
+ ActionListener <Resp > listener , Set <Integer > ignores ) {
1078
+ performRequestAsync (request , requestConverter , options ,
1079
+ response -> parseEntity (response .getEntity (), entityParser ), listener , ignores );
1080
+ }
1081
+
1082
+
1083
+ /**
1084
+ * @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
1085
+ * layer has been added to the ReST client, and requests should extend {@link Validatable} instead of {@link ActionRequest}.
1086
+ */
1087
+ @ Deprecated
1017
1088
protected final <Req extends ActionRequest , Resp > void performRequestAsync (Req request ,
1018
- CheckedFunction <Req , Request , IOException > requestConverter ,
1019
- RequestOptions options ,
1020
- CheckedFunction <Response , Resp , IOException > responseConverter ,
1021
- ActionListener <Resp > listener , Set <Integer > ignores ) {
1089
+ CheckedFunction <Req , Request , IOException > requestConverter ,
1090
+ RequestOptions options ,
1091
+ CheckedFunction <Response , Resp , IOException > responseConverter ,
1092
+ ActionListener <Resp > listener , Set <Integer > ignores ) {
1022
1093
ActionRequestValidationException validationException = request .validate ();
1023
- if (validationException != null ) {
1094
+ if (validationException != null && validationException . validationErrors (). isEmpty () == false ) {
1024
1095
listener .onFailure (validationException );
1025
1096
return ;
1026
1097
}
1098
+ internalPerformRequestAsync (request , requestConverter , options , responseConverter , listener , ignores );
1099
+ }
1100
+
1101
+ /**
1102
+ * Defines a helper method for asynchronously performing a request.
1103
+ */
1104
+ protected final <Req extends Validatable , Resp > void performRequestAsync (Req request ,
1105
+ CheckedFunction <Req , Request , IOException > requestConverter ,
1106
+ RequestOptions options ,
1107
+ CheckedFunction <Response , Resp , IOException > responseConverter ,
1108
+ ActionListener <Resp > listener , Set <Integer > ignores ) {
1109
+ ValidationException validationException = request .validate ();
1110
+ if (validationException != null && validationException .validationErrors ().isEmpty () == false ) {
1111
+ listener .onFailure (validationException );
1112
+ return ;
1113
+ }
1114
+ internalPerformRequestAsync (request , requestConverter , options , responseConverter , listener , ignores );
1115
+ }
1116
+
1117
+ /**
1118
+ * Provides common functionality for asynchronously performing a request.
1119
+ */
1120
+ private <Req , Resp > void internalPerformRequestAsync (Req request ,
1121
+ CheckedFunction <Req , Request , IOException > requestConverter ,
1122
+ RequestOptions options ,
1123
+ CheckedFunction <Response , Resp , IOException > responseConverter ,
1124
+ ActionListener <Resp > listener , Set <Integer > ignores ) {
1027
1125
Request req ;
1028
1126
try {
1029
1127
req = requestConverter .apply (request );
@@ -1037,6 +1135,7 @@ protected final <Req extends ActionRequest, Resp> void performRequestAsync(Req r
1037
1135
client .performRequestAsync (req , responseListener );
1038
1136
}
1039
1137
1138
+
1040
1139
final <Resp > ResponseListener wrapResponseListener (CheckedFunction <Response , Resp , IOException > responseConverter ,
1041
1140
ActionListener <Resp > actionListener , Set <Integer > ignores ) {
1042
1141
return new ResponseListener () {
0 commit comments