Skip to content

Commit

Permalink
[GEOS-8349] Monitor REST API won't return xml/json representation for…
Browse files Browse the repository at this point in the history
… request since 2.12.0
  • Loading branch information
aaime committed Oct 20, 2017
1 parent f8e9894 commit 1ac5fdd
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
*/
package org.geoserver.monitor.rest;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.geoserver.monitor.Monitor;
import org.geoserver.monitor.Query;
import org.geoserver.monitor.Query.Comparison;
Expand All @@ -26,13 +19,14 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping(path = { RestBaseController.ROOT_PATH + "/monitor/requests/{request}",
Expand Down Expand Up @@ -74,9 +68,9 @@ String[] getFields(String fields) {
}
}

@GetMapping(produces = { MediaType.TEXT_HTML_VALUE })
@GetMapping(produces = { MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE })
@ResponseBody
protected RestWrapper handleObjectGetHtml(
protected RestWrapper handleObjectGetRestWrapper(
@PathVariable(name = "request", required = false) String req,
@RequestParam(name = "from", required = false) String from,
@RequestParam(name = "to", required = false) String to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public OwsRequestResource(Monitor monitor) {

@GetMapping(produces = { CSV_MEDIATYPE_VALUE, EXCEL_MEDIATYPE_VALUE, ZIP_MEDIATYPE_VALUE })
@ResponseBody
protected RestWrapper handleObjectGetHtml(
protected RestWrapper handleObjectGetRestWrapper(
@PathVariable(name = "request", required = false) String req,
@RequestParam(name = "from", required = false) String from,
@RequestParam(name = "to", required = false) String to,
Expand All @@ -38,7 +38,7 @@ protected RestWrapper handleObjectGetHtml(
@RequestParam(name = "count", required = false) Long count,
@RequestParam(name = "live", required = false) Boolean live,
@RequestParam(name = "fields", required = false) String fieldsSpec) throws Exception {
return super.handleObjectGetHtml(req, from, to, filter, order, offset, count, live,
return super.handleObjectGetRestWrapper(req, from, to, filter, order, offset, count, live,
fieldsSpec);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
package org.geoserver.monitor.rest;

import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import net.sf.json.JSONObject;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
Expand All @@ -36,6 +15,18 @@
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletResponse;
import org.w3c.dom.Document;

import java.io.*;
import java.text.ParseException;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.*;

public class RequestControllerTest extends GeoServerSystemTestSupport {

Expand Down Expand Up @@ -81,6 +72,49 @@ public void testGetHTMLById() throws Exception {
assertEquals("Request 5", document.select("#content > h1 > span").text());
}

/**
* This is undocumented/accidental behavior of 2.10.x (and previous) that actually got
* used by other projects, adding it back preserving its original structure (pure XStream
* reflection) even if it's really hard on the eyes....
*
* @throws Exception
*/
@Test
public void testGetXMLById() throws Exception {
MockHttpServletResponse response = getAsServletResponse(
RestBaseController.ROOT_PATH + "/monitor/requests/5.xml");
assertEquals(200, response.getStatus());

Document dom = dom(new ByteArrayInputStream(response.getContentAsByteArray()));
// print(dom);

assertXpathEvaluatesTo("5", "/org.geoserver.monitor.RequestData/id", dom);
assertXpathEvaluatesTo("RUNNING", "/org.geoserver.monitor.RequestData/status", dom);
}

/**
* This is undocumented/accidental behavior of 2.10.x (and previous) that actually got
* used by other projects, adding it back preserving its original structure (pure XStream
* reflection) even if it's really hard on the eyes....
*
* @throws Exception
*/
@Test
public void testGetJSONById() throws Exception {
MockHttpServletResponse response = getAsServletResponse(
RestBaseController.ROOT_PATH + "/monitor/requests/5.json");
assertEquals(200, response.getStatus());

JSONObject json = (JSONObject) json(response);
// print(json);

JSONObject data = json.getJSONObject("org.geoserver.monitor.RequestData");
assertNotNull(data);
assertEquals("5", data.getString("id"));
assertEquals("RUNNING", data.getString("status"));
}


@Test
public void testGetAllCSV() throws Exception {
MockHttpServletResponse response = getAsServletResponse(
Expand Down

0 comments on commit 1ac5fdd

Please sign in to comment.