[OLINGO-663] Add new exceptiontext and right status code

This commit is contained in:
Christian Amend 2015-05-28 11:02:18 +02:00
parent 29b169def4
commit ea89f7213e
7 changed files with 25 additions and 15 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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() {

View File

@ -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);
}
}

View File

@ -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.

View File

@ -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());
}
}