Skip to content

Commit

Permalink
refactor: simplify EntityProcessor
Browse files Browse the repository at this point in the history
This patch ...

... simplifies the EntityProcessor by replacing ambiguous method names
and logic.

... removes the EntityProcessorTest, because all the tests are already
part of ODataUpdateEntityTest, ODataCreateEntityTest,
ODataDeleteEntityTest and ODataReadEntityTest.

... improves error handling in ODataEndpointHandler, by setting the
correct status code in case that the error is of type
ODataApplicationException.
  • Loading branch information
pk-work authored and SAPDaniloWork committed Mar 12, 2021
1 parent 52f43ab commit 6bd0a21
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpMethod;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataHandler;
import org.apache.olingo.server.api.ODataLibraryException;
import org.apache.olingo.server.api.ODataRequest;
Expand Down Expand Up @@ -306,7 +307,8 @@ public void handle(RoutingContext routingContext) {
}, asyncODataResponse -> {
// failed to map / process OData request, so fail the web request
if (asyncODataResponse.failed()) {
routingContext.fail(-1, asyncODataResponse.cause());
Throwable cause = asyncODataResponse.cause();
routingContext.fail(evaluateStatusCode(cause), cause);
return;
}

Expand All @@ -316,20 +318,25 @@ public void handle(RoutingContext routingContext) {
processPromise.future().onComplete(asyncResult -> {
// (asynchronously) retrieving the odata response failed, so fail the web request
if (asyncResult.failed()) {
routingContext.fail(-1, asyncResult.cause());
Throwable cause = asyncResult.cause();
routingContext.fail(evaluateStatusCode(cause), cause);
return;
}

try {
// map the odataResponse to the routingContext.response
mapODataResponse(odataResponse, routingContext.response());
} catch (IOException | ODataRuntimeException e) {
routingContext.fail(e);
routingContext.fail(-1, e);
}
});
});
}

private static int evaluateStatusCode(Throwable t) {
return t instanceof ODataApplicationException ? ((ODataApplicationException) t).getStatusCode() : -1;
}

/**
* Maps a Vert.x RoutingContext into a new ODataRequest.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void readEntityCollection(ODataRequest request, ODataResponse response, U
} catch (ODataException e) {
processPromise.fail(e);
}
}).onFailure(e -> processPromise.fail(e));
}).onFailure(processPromise::fail);
} catch (ODataException e) {
processPromise.fail(e);
}
Expand Down
Loading

0 comments on commit 6bd0a21

Please sign in to comment.