geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject incubator-geode git commit: GEODE-1247: unable to stop server using http connection
Date Tue, 15 Nov 2016 21:41:14 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/develop 58e0026c6 -> bb3db4a6a


GEODE-1247: unable to stop server using http connection


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/bb3db4a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/bb3db4a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/bb3db4a6

Branch: refs/heads/develop
Commit: bb3db4a6a6f5057c8d4ebb87961708d131e5b447
Parents: 58e0026
Author: Jinmei Liao <jiliao@pivotal.io>
Authored: Mon Nov 14 12:41:17 2016 -0800
Committer: Jinmei Liao <jiliao@pivotal.io>
Committed: Tue Nov 15 15:40:42 2016 -0600

----------------------------------------------------------------------
 .../org/apache/geode/internal/util/IOUtils.java |  9 ++-
 .../web/shell/AbstractHttpOperationInvoker.java | 47 +++++++-----
 .../commands/QueryNamesOverHttpDUnitTest.java   | 79 ++++++++++++++++++++
 3 files changed, 112 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb3db4a6/geode-core/src/main/java/org/apache/geode/internal/util/IOUtils.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/util/IOUtils.java b/geode-core/src/main/java/org/apache/geode/internal/util/IOUtils.java
index 4c1cc5f..c1a1952 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/util/IOUtils.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/util/IOUtils.java
@@ -14,6 +14,9 @@
  */
 package org.apache.geode.internal.util;
 
+import org.apache.geode.internal.lang.ObjectUtils;
+import org.apache.geode.internal.lang.StringUtils;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.Closeable;
@@ -25,9 +28,6 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.ObjectStreamClass;
 
-import org.apache.geode.internal.lang.ObjectUtils;
-import org.apache.geode.internal.lang.StringUtils;
-
 /**
  * Reusable Input/Output operation utility methods.
  * <p/>
@@ -168,7 +168,8 @@ public abstract class IOUtils {
     ObjectInputStream objIn = null;
 
     try {
-      objIn = new ClassLoaderObjectInputStream(new ByteArrayInputStream(objBytes), loader);
+      ByteArrayInputStream bis = new ByteArrayInputStream(objBytes);
+      objIn = new ClassLoaderObjectInputStream(bis, loader);
       return objIn.readObject();
     } finally {
       close(objIn);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb3db4a6/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/AbstractHttpOperationInvoker.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/AbstractHttpOperationInvoker.java
b/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/AbstractHttpOperationInvoker.java
index 25eee82..fa05248 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/AbstractHttpOperationInvoker.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/shell/AbstractHttpOperationInvoker.java
@@ -15,23 +15,6 @@
 
 package org.apache.geode.management.internal.web.shell;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.URI;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import javax.management.ObjectName;
-import javax.management.QueryExp;
-
 import org.apache.geode.internal.GemFireVersion;
 import org.apache.geode.internal.lang.StringUtils;
 import org.apache.geode.internal.logging.LogService;
@@ -50,17 +33,35 @@ import org.apache.geode.management.internal.web.shell.support.HttpMBeanProxyFact
 import org.apache.geode.management.internal.web.util.UriUtils;
 import org.apache.geode.security.AuthenticationFailedException;
 import org.apache.geode.security.NotAuthorizedException;
-
 import org.apache.logging.log4j.Logger;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.http.client.ClientHttpResponse;
 import org.springframework.http.client.SimpleClientHttpRequestFactory;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
 import org.springframework.web.client.ResourceAccessException;
 import org.springframework.web.client.ResponseErrorHandler;
 import org.springframework.web.client.RestTemplate;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import javax.management.ObjectName;
+import javax.management.QueryExp;
+
 /**
  * The AbstractHttpOperationInvoker class is an abstract base class encapsulating common
  * functionality for all HTTP-based OperationInvoker implementations.
@@ -184,7 +185,15 @@ public abstract class AbstractHttpOperationInvoker implements HttpOperationInvok
     // add our custom HttpMessageConverter for serializing DTO Objects into the HTTP request
message
     // body
     // and de-serializing HTTP response message body content back into DTO Objects
-    this.restTemplate.getMessageConverters().add(new SerializableObjectHttpMessageConverter());
+    List<HttpMessageConverter<?>> converters = this.restTemplate.getMessageConverters();
+    // remove the MappingJacksonHttpConverter
+    for (int i = converters.size() - 1; i >= 0; i--) {
+      HttpMessageConverter converter = converters.get(i);
+      if (converter instanceof MappingJackson2HttpMessageConverter) {
+        converters.remove(converter);
+      }
+    }
+    converters.add(new SerializableObjectHttpMessageConverter());
 
     // set the ResponseErrorHandler handling any errors originating from our HTTP request
     this.restTemplate.setErrorHandler(new ResponseErrorHandler() {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb3db4a6/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/QueryNamesOverHttpDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/QueryNamesOverHttpDUnitTest.java
b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/QueryNamesOverHttpDUnitTest.java
new file mode 100644
index 0000000..1a19e5e
--- /dev/null
+++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/QueryNamesOverHttpDUnitTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.cli.commands;
+
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import org.apache.geode.internal.AvailablePortHelper;
+import org.apache.geode.management.internal.cli.shell.Gfsh;
+import org.apache.geode.management.internal.web.domain.Link;
+import org.apache.geode.management.internal.web.domain.LinkIndex;
+import org.apache.geode.management.internal.web.http.HttpMethod;
+import org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker;
+import org.apache.geode.test.dunit.rules.LocatorStarterRule;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Properties;
+import java.util.Set;
+import javax.management.ObjectName;
+import javax.management.Query;
+import javax.management.QueryExp;
+
+@Category(IntegrationTest.class)
+public class QueryNamesOverHttpDUnitTest {
+
+
+  protected static int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+  protected static int jmxPort = ports[0];
+  protected static int httpPort = ports[1];
+
+  private static Properties locatorProps = new Properties() {
+    {
+      setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
+      setProperty(HTTP_SERVICE_PORT, httpPort + "");
+      setProperty(JMX_MANAGER_PORT, jmxPort + "");
+    }
+  };
+
+  @Rule
+  public LocatorStarterRule locatorRule = new LocatorStarterRule(locatorProps);
+
+
+  @Test
+  public void testQueryNameOverHttp() throws Exception {
+
+    LinkIndex links = new LinkIndex();
+    links.add(new Link("mbean-query",
+        new URI("http://localhost:" + httpPort + "/gemfire/v1/mbean/query"), HttpMethod.POST));
+    RestHttpOperationInvoker invoker =
+        new RestHttpOperationInvoker(links, mock(Gfsh.class), new HashMap<>());
+
+    ObjectName objectName = ObjectName.getInstance("GemFire:type=Member,*");
+    QueryExp query = Query.eq(Query.attr("Name"), Query.value("mock"));
+
+    Set<ObjectName> names = invoker.queryNames(objectName, query);
+    assertTrue(names.isEmpty());
+  }
+}


Mime
View raw message