mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-06 16:49:09 +00:00
[OLINGO-663] Add new exceptiontext and right status code
This commit is contained in:
parent
29b169def4
commit
ea89f7213e
@ -19,7 +19,7 @@
|
||||
package org.apache.olingo.server.api;
|
||||
|
||||
/**
|
||||
* <p>Processors that would like to support concurrency control for certain entity sets can implement this
|
||||
* <p>Processors that would like to support etags for certain entity sets can implement this
|
||||
* interface.</p>
|
||||
* <p>If implemented this interface can be registered at the ODataHttpHandler. This will result in change request to
|
||||
* require an if-match/if-none-match or an if-modified-since/if-unmodified-since header. Otherwise the request will
|
||||
|
@ -103,6 +103,12 @@ public class ODataExceptionHelper {
|
||||
.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
|
||||
}
|
||||
|
||||
public static ODataServerError createServerErrorObject(final PreconditionRequiredException e,
|
||||
final Locale requestedLocale) {
|
||||
return basicTranslatedError(e, requestedLocale)
|
||||
.setStatusCode(HttpStatusCode.PRECONDITION_REQUIRED.getStatusCode());
|
||||
}
|
||||
|
||||
public static ODataServerError
|
||||
createServerErrorObject(final ODataTranslatedException e, final Locale requestedLocale) {
|
||||
return basicTranslatedError(e, requestedLocale);
|
||||
|
@ -93,6 +93,9 @@ public class ODataHandler {
|
||||
} catch (DeserializerException e) {
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
handleException(request, response, serverError);
|
||||
} catch (PreconditionRequiredException e) {
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
handleException(request, response, serverError);
|
||||
}catch (ODataHandlerException e) {
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
handleException(request, response, serverError);
|
||||
|
@ -24,8 +24,7 @@ public class PreconditionRequiredException extends ODataTranslatedException {
|
||||
private static final long serialVersionUID = -8112658467394158700L;
|
||||
|
||||
public static enum MessageKeys implements MessageKey {
|
||||
/** parameter: required header */
|
||||
PRECONDITION_REQUIRED;
|
||||
MISSING_HEADER;
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
|
@ -60,7 +60,7 @@ public class PreconditionsValidator {
|
||||
private void checkETagHeaderPresent() throws PreconditionRequiredException {
|
||||
if (ifMatch == null && ifNoneMatch == null) {
|
||||
throw new PreconditionRequiredException("Expected an if-match or if-none-match header",
|
||||
PreconditionRequiredException.MessageKeys.PRECONDITION_REQUIRED);
|
||||
PreconditionRequiredException.MessageKeys.MISSING_HEADER);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,3 +143,5 @@ BatchDeserializerException.MISSING_MANDATORY_HEADER=Missing mandatory header at
|
||||
BatchDeserializerException.INVALID_BASE_URI=The base URI do not match the service base URI at line '%1$s'.
|
||||
|
||||
BatchSerializerExecption.MISSING_CONTENT_ID=Each request within a change set required exactly one content id.
|
||||
|
||||
PreconditionRequiredException.MISSING_HEADER=The Operation you requested on this Entity requires an if-match or if-none-match header.
|
@ -69,7 +69,7 @@ public class PreconditionsValidatorTest {
|
||||
new PreconditionsValidator(new ETagSupport(), uriInfo, null, null).validatePreconditions(false);
|
||||
fail("Expected a PreconditionRequiredException but was not thrown");
|
||||
} catch (PreconditionRequiredException e) {
|
||||
assertEquals(PreconditionRequiredException.MessageKeys.PRECONDITION_REQUIRED, e.getMessageKey());
|
||||
assertEquals(PreconditionRequiredException.MessageKeys.MISSING_HEADER, e.getMessageKey());
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ public class PreconditionsValidatorTest {
|
||||
new PreconditionsValidator(new ETagSupport("ESKeyNav"), uriInfo, null, null).validatePreconditions(false);
|
||||
fail("Expected a PreconditionRequiredException but was not thrown");
|
||||
} catch (PreconditionRequiredException e) {
|
||||
assertEquals(PreconditionRequiredException.MessageKeys.PRECONDITION_REQUIRED, e.getMessageKey());
|
||||
assertEquals(PreconditionRequiredException.MessageKeys.MISSING_HEADER, e.getMessageKey());
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ public class PreconditionsValidatorTest {
|
||||
new PreconditionsValidator(new ETagSupport(), uriInfo, null, null).validatePreconditions(true);
|
||||
fail("Expected a PreconditionRequiredException but was not thrown");
|
||||
} catch (PreconditionRequiredException e) {
|
||||
assertEquals(PreconditionRequiredException.MessageKeys.PRECONDITION_REQUIRED, e.getMessageKey());
|
||||
assertEquals(PreconditionRequiredException.MessageKeys.MISSING_HEADER, e.getMessageKey());
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ public class PreconditionsValidatorTest {
|
||||
new PreconditionsValidator(new ETagSupport(), uriInfo, null, null).validatePreconditions(false);
|
||||
fail("Expected a PreconditionRequiredException but was not thrown");
|
||||
} catch (PreconditionRequiredException e) {
|
||||
assertEquals(PreconditionRequiredException.MessageKeys.PRECONDITION_REQUIRED, e.getMessageKey());
|
||||
assertEquals(PreconditionRequiredException.MessageKeys.MISSING_HEADER, e.getMessageKey());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user