Juan Hernandez has uploaded a new change for review. Change subject: restapi: Use X-Ovirt-Expect instead of Expect ......................................................................
restapi: Use X-Ovirt-Expect instead of Expect The HTTP Expect header is rejected by the Apache web server if its value is anything other than 100-continue. To avoid problems we have an explicit configuration to remove it. As users may want to use that behaviour this patch changes the RESTAPI so that it will accept both the Expect and X-Ovirt-Expect headers. Change-Id: I6b66b1f04b286c756d4c1e89c3555c1c95593881 Bug-Url: https://bugzilla.redhat.com/1093784 Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com> --- A backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ExpectationHelper.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendResource.java 3 files changed, 59 insertions(+), 14 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/30/27930/1 diff --git a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ExpectationHelper.java b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ExpectationHelper.java new file mode 100644 index 0000000..8f7f9cd --- /dev/null +++ b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/ExpectationHelper.java @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2014 Red Hat, 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 +* +* 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.ovirt.engine.api.utils; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.ws.rs.core.HttpHeaders; + +/** + * This class contains helper methods to work with the {@code Expect} header. + */ +public class ExpectationHelper { + /** + * The names of the headers that can contain expectations. By default the HTTP {@code Expect} should be used, but + * this is rejected by the Apache web server if the value is anything other than {@code 100-continue}, so we also + * accept {@code X-Ovirt-Expect}. + */ + private static final String[] HEADERS = { + "Expect", + "X-Ovirt-Expect" + }; + + /** + * Return the values contained in the {@code Expect} and {@code X-Ovirt-Expect} headers. + */ + public static Set<String> getExpectations(HttpHeaders headers) { + Set<String> expectations = new HashSet<>(); + for (String header : HEADERS) { + List<String> values = headers.getRequestHeader(header); + if (values != null) { + expectations.addAll(values); + } + } + return expectations; + } +} diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java index 437e733..dc99c63 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendCollectionResource.java @@ -5,6 +5,7 @@ import java.net.URI; import java.util.HashMap; import java.util.List; +import java.util.Set; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; @@ -13,6 +14,7 @@ import org.ovirt.engine.api.common.util.StatusUtils; import org.ovirt.engine.api.model.ActionableResource; import org.ovirt.engine.api.model.BaseResource; +import org.ovirt.engine.api.utils.ExpectationHelper; import org.ovirt.engine.api.utils.LinkHelper; import org.ovirt.engine.core.common.action.VdcActionParametersBase; import org.ovirt.engine.core.common.action.VdcActionType; @@ -28,7 +30,6 @@ public abstract class AbstractBackendCollectionResource<R extends BaseResource, Q /* extends IVdcQueryable */> extends AbstractBackendResource<R, Q> { - private static final String EXPECT_HEADER = "Expect"; private static final String BLOCKING_EXPECTATION = "201-created"; private static final String CREATION_STATUS_REL = "creation_status"; public static final String FROM_CONSTRAINT_PARAMETER = "from"; @@ -136,12 +137,8 @@ } protected boolean expectBlocking() { - boolean expectBlocking = false; - List<String> expect = httpHeaders.getRequestHeader(EXPECT_HEADER); - if (expect != null && expect.size() > 0) { - expectBlocking = expect.get(0).equalsIgnoreCase(BLOCKING_EXPECTATION); - } - return expectBlocking; + Set<String> expectations = ExpectationHelper.getExpectations(httpHeaders); + return expectations.contains(BLOCKING_EXPECTATION); } protected void handleAsynchrony(VdcReturnValueBase result, R model) { diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendResource.java index 0adc8b2..e16a881c 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendResource.java @@ -5,6 +5,7 @@ import java.text.MessageFormat; import java.util.HashMap; import java.util.List; +import java.util.Set; import javax.ws.rs.GET; import javax.ws.rs.core.Response; @@ -20,6 +21,7 @@ import org.ovirt.engine.api.restapi.resource.validation.Validator; import org.ovirt.engine.api.restapi.util.ErrorMessageHelper; import org.ovirt.engine.api.restapi.util.SessionHelper; +import org.ovirt.engine.api.utils.ExpectationHelper; import org.ovirt.engine.api.utils.LinkHelper; import org.ovirt.engine.core.common.action.LogoutUserParameters; import org.ovirt.engine.core.common.action.VdcActionParametersBase; @@ -46,7 +48,6 @@ private static final String ASYNC_CONSTRAINT = "async"; public static final String FORCE_CONSTRAINT = "force"; protected static final String MAX = "max"; - private static final String EXPECT_HEADER = "Expect"; private static final String NON_BLOCKING_EXPECTATION = "202-accepted"; protected static final Log LOG = LogFactory.getLog(BackendResource.class); public static final String POPULATE = "All-Content"; @@ -220,12 +221,8 @@ } protected boolean expectNonBlocking() { - boolean expectNonBlocking = false; - List<String> expect = httpHeaders.getRequestHeader(EXPECT_HEADER); - if (expect != null && expect.size() > 0) { - expectNonBlocking = expect.get(0).equalsIgnoreCase(NON_BLOCKING_EXPECTATION); - } - return expectNonBlocking; + Set<String> expectations = ExpectationHelper.getExpectations(httpHeaders); + return expectations.contains(NON_BLOCKING_EXPECTATION); } protected Response performNonBlockingAction(VdcActionType task, VdcActionParametersBase params, Action action) { try { -- To view, visit http://gerrit.ovirt.org/27930 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6b66b1f04b286c756d4c1e89c3555c1c95593881 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches