-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw an exception when an entity-level action would be invoked witho…
…ut an id. Entity-level actions are performed on a specific resource, and so the id value in the request is mandatory. Today, if the client forgets to call .id(...) to supply a value the request can be built and sent to the server where it will cause an error with a mysterious error message that implies that there is no action of that name, i.e. "POST operation named myAction not supported on resource '...' URI: '...'" Here we fix that so that a) The problem is caught on the client side during the RequestBuilder.build() method call so that the request cannot be sent to the server. b) A sensible error message is given where the stack trace's line number will lead the developer straight to the root of the problem: "Missing or null id value; we cannot invoke this entity-level action."
- Loading branch information
Showing
5 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...-client/src/main/java/com/linkedin/restli/client/base/EntityActionRequestBuilderBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.linkedin.restli.client.base; | ||
|
||
import com.linkedin.restli.client.ActionRequest; | ||
import com.linkedin.restli.client.RestliRequestOptions; | ||
import com.linkedin.restli.common.ResourceSpec; | ||
|
||
/** | ||
* The abstract base class for all generated request builders classes for entity-level actions. | ||
*/ | ||
public abstract class EntityActionRequestBuilderBase<K, V, RB extends ActionRequestBuilderBase<K, V, RB>> | ||
extends ActionRequestBuilderBase<K, V, RB> | ||
{ | ||
protected EntityActionRequestBuilderBase(String baseUriTemplate, Class<V> elementClass, ResourceSpec resourceSpec, | ||
RestliRequestOptions requestOptions) | ||
{ | ||
super(baseUriTemplate, elementClass, resourceSpec, requestOptions); | ||
} | ||
|
||
@Override | ||
public ActionRequest<V> build() { | ||
if (!isIdPresent()) | ||
{ | ||
throw new IllegalStateException("Missing or null id value; we cannot invoke this entity-level action."); | ||
} | ||
return super.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters