Remove spurious references to org.json
This commit is contained in:
parent
a76d88122a
commit
b0e9e21a6b
@ -44,8 +44,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -116,20 +114,14 @@ public abstract class Command {
|
||||
* @return
|
||||
* @throws JSONException
|
||||
*/
|
||||
static protected EngineConfig getEngineConfig(HttpServletRequest request)
|
||||
throws JSONException {
|
||||
static protected EngineConfig getEngineConfig(HttpServletRequest request) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("parameter 'request' should not be null");
|
||||
}
|
||||
|
||||
String json = request.getParameter("engine");
|
||||
try{
|
||||
return (json == null) ? null :
|
||||
EngineConfig.reconstruct(json);
|
||||
} catch (JSONException e){
|
||||
logger.debug( json + " could not be parsed to JSON");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,21 +215,6 @@ public abstract class Command {
|
||||
return def;
|
||||
}
|
||||
|
||||
static protected JSONObject getJsonParameter(HttpServletRequest request, String name) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("parameter 'request' should not be null");
|
||||
}
|
||||
String value = request.getParameter(name);
|
||||
if (value != null) {
|
||||
try {
|
||||
return ParsingUtilities.evaluateJsonStringToObject(value);
|
||||
} catch (JSONException e) {
|
||||
logger.warn("error getting json parameter",e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static class HistoryEntryResponse {
|
||||
@JsonProperty("code")
|
||||
protected String getCode() { return "ok"; }
|
||||
@ -286,7 +263,7 @@ public abstract class Command {
|
||||
}
|
||||
|
||||
static protected void respond(HttpServletResponse response, String status, String message)
|
||||
throws IOException, JSONException {
|
||||
throws IOException {
|
||||
|
||||
Writer w = response.getWriter();
|
||||
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
|
||||
@ -301,14 +278,14 @@ public abstract class Command {
|
||||
}
|
||||
|
||||
static protected void respondJSON(HttpServletResponse response, Object o)
|
||||
throws IOException, JSONException {
|
||||
throws IOException {
|
||||
|
||||
respondJSON(response, o, new Properties());
|
||||
}
|
||||
|
||||
static protected void respondJSON(
|
||||
HttpServletResponse response, Object o, Properties options)
|
||||
throws IOException, JSONException {
|
||||
throws IOException {
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
@ -330,7 +307,6 @@ public abstract class Command {
|
||||
throw new ServletException("Response object can't be null");
|
||||
}
|
||||
|
||||
try {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
|
||||
@ -351,9 +327,6 @@ public abstract class Command {
|
||||
writer.close();
|
||||
w.flush();
|
||||
w.close();
|
||||
} catch (JSONException e1) {
|
||||
e.printStackTrace(response.getWriter());
|
||||
}
|
||||
}
|
||||
|
||||
protected void respondWithErrorPage(
|
||||
|
@ -40,8 +40,6 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
@ -69,11 +67,7 @@ public class GetAllProjectMetadataCommand extends Command {
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
String userMeta = (String)ProjectManager.singleton.getPreferenceStore().get("userMetadata");
|
||||
respondJSON(response, new AllProjectMetadata(ProjectManager.singleton.getAllProjectMetadata(), userMeta));
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -34,8 +34,6 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.refine.ProjectManager;
|
||||
import com.google.refine.commands.Command;
|
||||
@ -56,12 +54,8 @@ public class GetAllProjectTagsCommand extends Command {
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
try {
|
||||
Map<String, Integer> tagMap = ProjectManager.singleton.getAllProjectTags();
|
||||
Set<String> tags = tagMap == null ? Collections.emptySet() : tagMap.keySet();
|
||||
respondJSON(response, new AllProjectsTags(tags));
|
||||
} catch (JSONException e) {
|
||||
respondException(response, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -36,9 +36,6 @@ package com.google.refine.tests.commands;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.google.refine.browsing.Engine;
|
||||
import com.google.refine.browsing.EngineConfig;
|
||||
import com.google.refine.commands.Command;
|
||||
@ -55,7 +52,7 @@ public class CommandStub extends Command {
|
||||
}
|
||||
|
||||
public EngineConfig wrapGetEngineConfig(HttpServletRequest request)
|
||||
throws JSONException {
|
||||
{
|
||||
return getEngineConfig(request);
|
||||
}
|
||||
|
||||
@ -67,8 +64,4 @@ public class CommandStub extends Command {
|
||||
public int wrapGetIntegerParameter(HttpServletRequest request, String name,int def) {
|
||||
return getIntegerParameter(request, name, def);
|
||||
}
|
||||
|
||||
public JSONObject wrapGetJsonParameter(HttpServletRequest request,String name) {
|
||||
return getJsonParameter(request, name);
|
||||
}
|
||||
}
|
||||
|
@ -296,59 +296,4 @@ public class CommandTests extends RefineTest {
|
||||
verify(request, times(1)).getParameter("zeronumber");
|
||||
verify(request, times(1)).getParameter("negativenumber");
|
||||
}
|
||||
|
||||
// ---------------------getJsonParameter tests----------------
|
||||
@Test
|
||||
public void getJsonParameterWithNullParameters() {
|
||||
when(request.getParameter(null)).thenReturn(null);
|
||||
when(request.getParameter("")).thenReturn(null);
|
||||
|
||||
try {
|
||||
SUT.wrapGetJsonParameter(null, null);
|
||||
Assert.fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
Assert.assertNull(SUT.wrapGetJsonParameter(request, null));
|
||||
|
||||
try {
|
||||
SUT.wrapGetJsonParameter(null, "test");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
Assert.assertNull(SUT.wrapGetJsonParameter(request, ""));
|
||||
|
||||
verify(request, times(1)).getParameter(null);
|
||||
verify(request, times(1)).getParameter("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getJsonParameterRegressionTest() {
|
||||
when(request.getParameter("test")).thenReturn("{\"foo\":\"bar\"}");
|
||||
|
||||
JSONObject o = SUT.wrapGetJsonParameter(request, "test");
|
||||
Assert.assertNotNull(o);
|
||||
try {
|
||||
Assert.assertEquals("bar", o.getString("foo"));
|
||||
} catch (JSONException e) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
verify(request, times(1)).getParameter("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getJsonParameterWithMalformedJson() {
|
||||
when(request.getParameter("test")).thenReturn("brokenJSON");
|
||||
|
||||
try {
|
||||
Assert.assertNull(SUT.wrapGetJsonParameter(request, "test"));
|
||||
} catch (Exception e) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
verify(request, times(1)).getParameter("test");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user