You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2017/10/06 15:55:16 UTC

[geode] branch develop updated: GEODE-3096: Unify gfsh Http clients (#875)

This is an automated email from the ASF dual-hosted git repository.

jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 2c3cd6b  GEODE-3096: Unify gfsh Http clients (#875)
2c3cd6b is described below

commit 2c3cd6b3713cc32b1cf57ef72e1fd92646588160
Author: jinmeiliao <ji...@pivotal.io>
AuthorDate: Fri Oct 6 08:55:14 2017 -0700

    GEODE-3096: Unify gfsh Http clients (#875)
---
 .../internal/web/http/support/HttpRequester.java   | 26 ++--------
 .../internal/web/shell/HttpOperationInvoker.java   |  4 --
 .../RestApiCallForCommandNotFoundException.java    | 42 ----------------
 .../web/shell/RestOperationErrorHandler.java       | 58 ----------------------
 4 files changed, 3 insertions(+), 127 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/http/support/HttpRequester.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/http/support/HttpRequester.java
index 7a8bfed..55d15aa 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/http/support/HttpRequester.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/http/support/HttpRequester.java
@@ -15,10 +15,9 @@
 
 package org.apache.geode.management.internal.web.http.support;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.net.URI;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Arrays;
@@ -26,6 +25,7 @@ import java.util.List;
 import java.util.Properties;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
@@ -41,8 +41,6 @@ import org.springframework.web.client.RestTemplate;
 import org.springframework.web.util.UriComponentsBuilder;
 
 import org.apache.geode.internal.GemFireVersion;
-import org.apache.geode.internal.util.IOUtils;
-import org.apache.geode.management.internal.cli.shell.Gfsh;
 import org.apache.geode.management.internal.web.http.converter.SerializableObjectHttpMessageConverter;
 import org.apache.geode.security.AuthenticationFailedException;
 import org.apache.geode.security.NotAuthorizedException;
@@ -102,7 +100,7 @@ public class HttpRequester {
     this.restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
       @Override
       public void handleError(final ClientHttpResponse response) throws IOException {
-        String body = readBody(response);
+        String body = IOUtils.toString(response.getBody(), StandardCharsets.UTF_8);
         final String message = String.format("The HTTP request failed with: %1$d - %2$s.",
             response.getRawStatusCode(), body);
 
@@ -114,24 +112,6 @@ public class HttpRequester {
           throw new RuntimeException(message);
         }
       }
-
-      private String readBody(final ClientHttpResponse response) throws IOException {
-        BufferedReader responseBodyReader = null;
-        try {
-          responseBodyReader = new BufferedReader(new InputStreamReader(response.getBody()));
-
-          final StringBuilder buffer = new StringBuilder();
-          String line;
-
-          while ((line = responseBodyReader.readLine()) != null) {
-            buffer.append(line).append(Gfsh.LINE_SEPARATOR);
-          }
-
-          return buffer.toString().trim();
-        } finally {
-          IOUtils.close(responseBodyReader);
-        }
-      }
     });
   }
 
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/HttpOperationInvoker.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/HttpOperationInvoker.java
index 2b24eec..859dd8f 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/HttpOperationInvoker.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/HttpOperationInvoker.java
@@ -261,8 +261,6 @@ public class HttpOperationInvoker implements OperationInvoker {
    * @param attributeName name of the attribute who's value will be fetched.
    * @return the value of the named attribute for the named resource (typically an MBean).
    * @throws MBeanAccessException if an MBean access error occurs.
-   * @throws RestApiCallForCommandNotFoundException if the REST API web service endpoint for
-   *         accessing an attribute on an MBean does not exists!
    */
   @Override
   public Object getAttribute(final String resourceName, final String attributeName) {
@@ -327,8 +325,6 @@ public class HttpOperationInvoker implements OperationInvoker {
    * @param signatures an array containing the signature of the operation.
    * @return result of the operation invocation.
    * @throws MBeanAccessException if an MBean access error occurs.
-   * @throws RestApiCallForCommandNotFoundException if the REST API web service endpoint for
-   *         invoking an operation on an MBean does not exists!
    */
   @Override
   public Object invoke(final String resourceName, final String operationName, final Object[] params,
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/RestApiCallForCommandNotFoundException.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/RestApiCallForCommandNotFoundException.java
deleted file mode 100644
index 7d4b97a..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/RestApiCallForCommandNotFoundException.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.management.internal.web.shell;
-
-/**
- * The NoRestApiCallForCommandException class...
- * <p/>
- * 
- * @see java.lang.RuntimeException
- * @since GemFire 8.0
- */
-@SuppressWarnings("unused")
-public class RestApiCallForCommandNotFoundException extends RuntimeException {
-  private static final long serialVersionUID = 6686566370779394304L;
-
-  public RestApiCallForCommandNotFoundException() {}
-
-  public RestApiCallForCommandNotFoundException(final String message) {
-    super(message);
-  }
-
-  public RestApiCallForCommandNotFoundException(final Throwable cause) {
-    super(cause);
-  }
-
-  public RestApiCallForCommandNotFoundException(final String message, final Throwable cause) {
-    super(message, cause);
-  }
-
-}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/RestOperationErrorHandler.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/RestOperationErrorHandler.java
deleted file mode 100644
index 676030b..0000000
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/RestOperationErrorHandler.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.management.internal.web.shell;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-import org.apache.commons.io.IOUtils;
-import org.springframework.http.client.ClientHttpResponse;
-import org.springframework.web.client.DefaultResponseErrorHandler;
-
-import org.apache.geode.management.internal.cli.shell.Gfsh;
-import org.apache.geode.security.AuthenticationFailedException;
-import org.apache.geode.security.NotAuthorizedException;
-
-public class RestOperationErrorHandler extends DefaultResponseErrorHandler {
-  private final Gfsh gfsh;
-
-  RestOperationErrorHandler(Gfsh gfsh) {
-    this.gfsh = gfsh;
-  }
-
-  public RestOperationErrorHandler() {
-    this(null);
-  }
-
-  @Override
-  public void handleError(final ClientHttpResponse response) throws IOException {
-    String body = IOUtils.toString(response.getBody(), StandardCharsets.UTF_8);
-    final String message = String.format("The HTTP request failed with: %1$d - %2$s",
-        response.getRawStatusCode(), body);
-
-    if (gfsh != null && gfsh.getDebug()) {
-      gfsh.logSevere(body, null);
-    }
-
-    if (response.getRawStatusCode() == 401) {
-      throw new AuthenticationFailedException(message);
-    } else if (response.getRawStatusCode() == 403) {
-      throw new NotAuthorizedException(message);
-    } else {
-      throw new RuntimeException(message);
-    }
-
-  }
-}

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].