diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-04-29 19:04:05 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-04-29 19:04:05 +0200 |
commit | ee958a2ab2676beb6490ebc352d29834141a2dc4 (patch) | |
tree | fd4d1b57d70a3392a5d99af6c5e6ef00838db158 /vespaclient-container-plugin | |
parent | b23bab182bcf5383d63837e0bb558ef4194cb2a4 (diff) |
Explicitly require non-empty (or null) route
Diffstat (limited to 'vespaclient-container-plugin')
2 files changed, 14 insertions, 19 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java index cf22d25b510..0f4adf0179f 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java @@ -21,12 +21,12 @@ import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol; import com.yahoo.documentapi.metrics.DocumentApiMetrics; import com.yahoo.documentapi.metrics.DocumentOperationStatus; import com.yahoo.documentapi.metrics.DocumentOperationType; -import com.yahoo.messagebus.ErrorCode; import com.yahoo.messagebus.StaticThrottlePolicy; import com.yahoo.metrics.simple.MetricReceiver; import com.yahoo.vdslib.VisitorOrdering; import com.yahoo.vespaclient.ClusterDef; import com.yahoo.vespaxmlparser.FeedOperation; +import com.yahoo.vespaxmlparser.VespaXMLFeedReader; import com.yahoo.yolean.concurrent.ConcurrentResourcePool; import com.yahoo.yolean.concurrent.ResourceFactory; import org.apache.commons.lang3.exception.ExceptionUtils; @@ -108,19 +108,10 @@ public class OperationHandlerImpl implements OperationHandler { documentAccess.shutdown(); } - private static final int HTTP_STATUS_SERVER_ERROR = 500; private static final int HTTP_STATUS_BAD_REQUEST = 400; private static final int HTTP_STATUS_INSUFFICIENT_STORAGE = 507; private static final int HTTP_PRE_CONDIDTION_FAILED = 412; - private static boolean isFatalMBusErrorCode(Set<Integer> errorCodes) { - for (Integer e : errorCodes) { - if (ErrorCode.isFatal(e) && ErrorCode.isMBusError(e)) { - return true; - } - } - return false; - } public static int getHTTPStatusCode(Set<Integer> errorCodes) { if (errorCodes.size() == 1 && errorCodes.contains(DocumentProtocol.ERROR_NO_SPACE)) { return HTTP_STATUS_INSUFFICIENT_STORAGE; @@ -128,9 +119,6 @@ public class OperationHandlerImpl implements OperationHandler { if (errorCodes.contains(DocumentProtocol.ERROR_TEST_AND_SET_CONDITION_FAILED)) { return HTTP_PRE_CONDIDTION_FAILED; } - if (isFatalMBusErrorCode(errorCodes)) { - return HTTP_STATUS_SERVER_ERROR; - } return HTTP_STATUS_BAD_REQUEST; } @@ -182,10 +170,9 @@ public class OperationHandlerImpl implements OperationHandler { } } - private VisitResult doVisit( - VisitorControlHandler visitorControlHandler, - LocalDataVisitorHandler localDataVisitorHandler, - RestUri restUri) throws RestApiException { + private VisitResult doVisit(VisitorControlHandler visitorControlHandler, + LocalDataVisitorHandler localDataVisitorHandler, + RestUri restUri) throws RestApiException { try { visitorControlHandler.waitUntilDone(); // VisitorParameters' session timeout implicitly triggers timeout failures. throwIfFatalVisitingError(visitorControlHandler, restUri); @@ -208,7 +195,8 @@ public class OperationHandlerImpl implements OperationHandler { if (! (session instanceof MessageBusSyncSession)) { // Not sure if this ever could happen but better be safe. throw new RestApiException(Response.createErrorResponse( - 400, "Can not set route since the API is not using message bus.", RestUri.apiErrorCodes.NO_ROUTE_WHEN_NOT_PART_OF_MESSAGEBUS)); + 400, "Can not set route since the API is not using message bus.", + RestUri.apiErrorCodes.NO_ROUTE_WHEN_NOT_PART_OF_MESSAGEBUS)); } ((MessageBusSyncSession) session).setRoute(route.orElse("default")); } diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java index b4992fb519b..698c37244a1 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java @@ -210,7 +210,7 @@ public class RestApi extends LoggingRequestHandler { } String condition = request.getProperty(CONDITION_PARAMETER_NAME); - Optional<String> route = Optional.ofNullable(request.getProperty(ROUTE_PARAMETER_NAME)); + Optional<String> route = Optional.ofNullable(nonEmpty(request.getProperty(ROUTE_PARAMETER_NAME), ROUTE_PARAMETER_NAME)); Optional<ObjectNode> resultJson = Optional.empty(); switch (request.getMethod()) { @@ -351,6 +351,13 @@ public class RestApi extends LoggingRequestHandler { return builder.toString(); } + + private String nonEmpty(String value, String name) { + if (value != null && value.isEmpty()) + throw new IllegalArgumentException("'" + name + "' cannot be empty"); + return value; + } + private static long parseAndValidateVisitNumericId(String value) { try { return Long.parseLong(value); |