SLIDER-713 issuing proper Jersey client requests
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/5def63b6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/5def63b6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/5def63b6 Branch: refs/heads/develop Commit: 5def63b6bd40b433f7b455c742c738ef5f5a6957 Parents: bc7def4 Author: Steve Loughran <[email protected]> Authored: Wed Feb 18 19:01:15 2015 +0000 Committer: Steve Loughran <[email protected]> Committed: Wed Feb 18 19:01:15 2015 +0000 ---------------------------------------------------------------------- .../slider/client/rest/BaseRestClient.java | 4 +-- .../rest/SliderApplicationApiRestClient.java | 37 ++++++++------------ .../rest/RestAPIClientTestDelegates.groovy | 2 +- 3 files changed, 18 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5def63b6/slider-core/src/main/java/org/apache/slider/client/rest/BaseRestClient.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/rest/BaseRestClient.java b/slider-core/src/main/java/org/apache/slider/client/rest/BaseRestClient.java index c21844d..b0e64ac 100644 --- a/slider-core/src/main/java/org/apache/slider/client/rest/BaseRestClient.java +++ b/slider-core/src/main/java/org/apache/slider/client/rest/BaseRestClient.java @@ -75,8 +75,8 @@ public class BaseRestClient { throws IOException { try { Preconditions.checkArgument(c != null); - resource.accept(MediaType.APPLICATION_JSON_TYPE); - return resource.method(method.getVerb(), c); + return resource.accept(MediaType.APPLICATION_JSON_TYPE) + .method(method.getVerb(), c); } catch (ClientHandlerException ex) { throw ExceptionConverter.convertJerseyException(method.getVerb(), resource.getURI().toString(), http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5def63b6/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java b/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java index d304962..b1aa633 100644 --- a/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java +++ b/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java @@ -77,8 +77,7 @@ public class SliderApplicationApiRestClient extends BaseRestClient } /** - * Create a resource under the application path set up to accept - * JSON + * Create a resource under the application path * @param subpath path under application * @return a resource under the application path */ @@ -86,9 +85,7 @@ public class SliderApplicationApiRestClient extends BaseRestClient Preconditions.checkArgument(!StringUtils.isEmpty(subpath), "empty path"); Preconditions.checkNotNull(appResource, "Null app resource"); - WebResource resource = appResource.path(subpath); - resource.accept(MediaType.APPLICATION_JSON_TYPE); - return resource; + return appResource.path(subpath); } /** @@ -128,8 +125,7 @@ public class SliderApplicationApiRestClient extends BaseRestClient */ public <T> T appResourceOperation(HttpVerb method, String subpath, Class<T> c) throws IOException { - WebResource resource = applicationResource(subpath); - return exec(method, resource, c); + return exec(method, applicationResource(subpath), c); } @@ -144,8 +140,7 @@ public class SliderApplicationApiRestClient extends BaseRestClient public <T> T appResourceOperation(HttpVerb method, String subpath, GenericType<T> t) throws IOException { - WebResource resource = applicationResource(subpath); - return exec(method, resource, t); + return exec(method, applicationResource(subpath), t); } @@ -172,18 +167,15 @@ public class SliderApplicationApiRestClient extends BaseRestClient public void putDesiredResources(ConfTree updated) throws IOException { WebResource resource = applicationResource(MODEL_DESIRED_RESOURCES); try { - ConfTreeSerDeser serDeser = new ConfTreeSerDeser(); - String json = serDeser.toJson(updated); - - resource.accept(MediaType.APPLICATION_JSON_TYPE); - // entity to put - resource.type(MediaType.APPLICATION_JSON_TYPE); // put operation. The result is discarded; it does help validate // that the operation returned a JSON data structure as well as a 200 // response. - resource.put(ConfTree.class, json); - //ClientResponse response = resource.put(ClientResponse.class); + + resource.accept(MediaType.APPLICATION_JSON_TYPE) + .type(MediaType.APPLICATION_JSON_TYPE) + .entity(updated) + .put(ConfTree.class); } catch (ClientHandlerException ex) { throw ExceptionConverter.convertJerseyException("PUT", resource.getURI().toString(), @@ -276,10 +268,11 @@ public class SliderApplicationApiRestClient extends BaseRestClient */ public PingInformation pingPost(String text) throws IOException { WebResource pingResource = applicationResource(ACTION_PING); - pingResource.type(MediaType.APPLICATION_JSON_TYPE); Form f = new Form(); f.add("text", text); - return pingResource.post(PingInformation.class, f); + return pingResource + .type(MediaType.APPLICATION_JSON_TYPE) + .post(PingInformation.class, f); } /** @@ -290,10 +283,10 @@ public class SliderApplicationApiRestClient extends BaseRestClient */ public PingInformation pingPut(String text) throws IOException { WebResource pingResource = applicationResource(ACTION_PING); - pingResource.type(MediaType.APPLICATION_JSON_TYPE); Form f = new Form(); - f.add("text", text); - return pingResource.put(PingInformation.class, f); + return pingResource + .type(MediaType.TEXT_PLAIN) + .put(PingInformation.class, text); } @Override http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/5def63b6/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy index fc3a29e..81cfabb 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy @@ -62,7 +62,7 @@ class RestAPIClientTestDelegates extends AbstractAppApiTestDelegates { void testPing() { super.testPing() // test the other verbs -// restClient.pingPut("Put!") + restClient.pingPut("Put!") restClient.pingGet("Get!") restClient.pingPost("Post!") }
