You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2018/12/23 11:25:00 UTC
[qpid-broker-j] 01/03: QPID-6948: [Broker-J] Fix generation of json
response for operations returning void
This is an automated email from the ASF dual-hosted git repository.
orudyy pushed a commit to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git
commit 4ba02114181b6efa6bdd9cdc1c96e10581e66781
Author: Alex Rudyy <or...@apache.org>
AuthorDate: Fri Dec 21 14:48:10 2018 +0000
QPID-6948: [Broker-J] Fix generation of json response for operations returning void
(cherry picked from commit eb4c0d16913295d8a5e081b18052bc5e93cc306c)
---
.../management/plugin/servlet/rest/RestServlet.java | 13 ++++---------
.../java/org/apache/qpid/tests/http/HttpTestHelper.java | 9 +++++++--
.../qpid/tests/http/rest/model/OperationTest.java | 17 +++++++++++++++++
3 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java b/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
index 9a53d11..ed41fcd 100644
--- a/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
+++ b/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
@@ -255,23 +255,18 @@ public class RestServlet extends AbstractServlet
content.release();
}
}
- else if (body != null)
+ else
{
response.setContentType(APPLICATION_JSON);
- Object data;
- if (managementResponse.getType() == ResponseType.MODEL_OBJECT)
+ if (body != null && managementResponse.getType() == ResponseType.MODEL_OBJECT)
{
- data = controller.formatConfiguredObject(
+ body = controller.formatConfiguredObject(
managementResponse.getBody(),
parameters,
managementRequest.isSecure()
|| managementRequest.isConfidentialOperationAllowedOnInsecureChannel());
}
- else
- {
- data = managementResponse.getBody();
- }
- writeJsonResponse(data, request, response);
+ writeJsonResponse(body, request, response);
}
}
diff --git a/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java b/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java
index 04bb288..ef6d9b1 100644
--- a/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java
+++ b/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java
@@ -28,6 +28,7 @@ import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@@ -241,7 +242,9 @@ public class HttpTestHelper
responseCode = connection.getResponseCode();
Assert.assertEquals(String.format("Unexpected response code from : %s", path), expectedResponseCode, responseCode);
- return new ObjectMapper().readValue(new ByteArrayInputStream(readConnectionInputStream(connection)), valueTypeRef);
+ byte[] data = readConnectionInputStream(connection);
+ LOGGER.debug("Response : {}", new String(data, StandardCharsets.UTF_8));
+ return new ObjectMapper().readValue(new ByteArrayInputStream(data), valueTypeRef);
}
finally
{
@@ -263,7 +266,9 @@ public class HttpTestHelper
responseCode = connection.getResponseCode();
Assert.assertEquals(String.format("Unexpected response code from : %s", path), expectedResponseCode, responseCode);
- return new ObjectMapper().readValue(new ByteArrayInputStream(readConnectionInputStream(connection)), valueTypeRef);
+ byte[] buf = readConnectionInputStream(connection);
+ LOGGER.debug("Response data: {}", new String(buf, StandardCharsets.UTF_8));
+ return new ObjectMapper().readValue(new ByteArrayInputStream(buf), valueTypeRef);
}
finally
{
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/OperationTest.java b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/OperationTest.java
index 4ce88a4..ade744a 100644
--- a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/OperationTest.java
+++ b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/OperationTest.java
@@ -26,8 +26,11 @@ import static org.apache.qpid.server.management.plugin.servlet.rest.AbstractServ
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import java.io.FileNotFoundException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -37,6 +40,7 @@ import org.junit.Test;
import org.apache.qpid.tests.http.HttpRequestConfig;
import org.apache.qpid.tests.http.HttpTestBase;
+import org.apache.qpid.tests.http.HttpTestHelper;
@HttpRequestConfig
public class OperationTest extends HttpTestBase
@@ -89,4 +93,17 @@ public class OperationTest extends HttpTestBase
{
getHelper().submitRequest("virtualhost/notfound", "POST", Collections.emptyMap(), SC_NOT_FOUND);
}
+
+ @Test
+ public void invokeOperationReturningVoid() throws Exception
+ {
+ final HttpTestHelper brokerHelper = new HttpTestHelper(getBrokerAdmin());
+ final Void response = brokerHelper.postJson("broker/performGC",
+ Collections.emptyMap(),
+ new TypeReference<Void>()
+ {
+ },
+ SC_OK);
+ assertThat(response, is(nullValue()));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org