HBASE-17713 the interface '/version/cluster' with header 'Accept: application/json' return is not JSON but plain text

Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
Guangxu Cheng 2017-09-06 11:58:24 +08:00 committed by tedyu
parent f0c1cd50c2
commit d7a74a75a1
4 changed files with 22 additions and 7 deletions

View File

@ -23,6 +23,7 @@ import org.codehaus.jackson.annotate.JsonValue;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
@ -47,7 +48,7 @@ public class StorageClusterVersionModel implements Serializable {
/**
* @return the storage cluster version
*/
@XmlValue
@XmlAttribute(name="Version")
public String getVersion() {
return version;
}
@ -62,7 +63,6 @@ public class StorageClusterVersionModel implements Serializable {
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@JsonValue
@Override
public String toString() {
return version;

View File

@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.rest;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@ -35,6 +36,8 @@ import org.apache.hadoop.hbase.rest.model.VersionModel;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
import org.codehaus.jackson.map.ObjectMapper;
import org.glassfish.jersey.servlet.ServletContainer;
import static org.junit.Assert.*;
@ -128,6 +131,12 @@ public class TestVersionResource {
Response response = client.get("/version", Constants.MIMETYPE_JSON);
assertTrue(response.getCode() == 200);
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
ObjectMapper mapper = new JacksonJaxbJsonProvider()
.locateMapper(VersionModel.class, MediaType.APPLICATION_JSON_TYPE);
VersionModel model
= mapper.readValue(response.getBody(), VersionModel.class);
validate(model);
LOG.info("success retrieving Stargate version as JSON");
}
@Test
@ -169,11 +178,17 @@ public class TestVersionResource {
}
@Test
public void doTestGetStorageClusterVersionJSON() throws IOException {
public void testGetStorageClusterVersionJSON() throws IOException {
Response response = client.get("/version/cluster", Constants.MIMETYPE_JSON);
assertTrue(response.getCode() == 200);
assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
}
ObjectMapper mapper = new JacksonJaxbJsonProvider()
.locateMapper(StorageClusterVersionModel.class, MediaType.APPLICATION_JSON_TYPE);
StorageClusterVersionModel clusterVersionModel
= mapper.readValue(response.getBody(), StorageClusterVersionModel.class);
assertNotNull(clusterVersionModel);
assertNotNull(clusterVersionModel.getVersion());
LOG.info("success retrieving storage cluster version as JSON");
}
}

View File

@ -41,7 +41,7 @@ public class TestXmlParsing {
@Test
public void testParsingClusterVersion() throws Exception {
final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ "<ClusterVersion>2.0.0</ClusterVersion>";
+ "<ClusterVersion Version=\"2.0.0\"/>";
Client client = mock(Client.class);
RemoteAdmin admin = new RemoteAdmin(client, HBaseConfiguration.create(), null);
Response resp = new Response(200, null, xml.getBytes());

View File

@ -31,9 +31,9 @@ public class TestStorageClusterVersionModel extends TestModelBase<StorageCluster
super(StorageClusterVersionModel.class);
AS_XML =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"+
"<ClusterVersion>" + VERSION + "</ClusterVersion>";
"<ClusterVersion Version=\"" + VERSION + "\"/>";
AS_JSON = "\"0.0.1-testing\"";
AS_JSON = "{\"Version\": \"0.0.1-testing\"}";
}
protected StorageClusterVersionModel buildTestModel() {