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 javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.velocity.VelocityContext;
|
import org.apache.velocity.VelocityContext;
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -116,20 +114,14 @@ public abstract class Command {
|
|||||||
* @return
|
* @return
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
static protected EngineConfig getEngineConfig(HttpServletRequest request)
|
static protected EngineConfig getEngineConfig(HttpServletRequest request) {
|
||||||
throws JSONException {
|
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
throw new IllegalArgumentException("parameter 'request' should not be null");
|
throw new IllegalArgumentException("parameter 'request' should not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
String json = request.getParameter("engine");
|
String json = request.getParameter("engine");
|
||||||
try{
|
return (json == null) ? null :
|
||||||
return (json == null) ? null :
|
|
||||||
EngineConfig.reconstruct(json);
|
EngineConfig.reconstruct(json);
|
||||||
} catch (JSONException e){
|
|
||||||
logger.debug( json + " could not be parsed to JSON");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -222,21 +214,6 @@ public abstract class Command {
|
|||||||
}
|
}
|
||||||
return def;
|
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 {
|
protected static class HistoryEntryResponse {
|
||||||
@JsonProperty("code")
|
@JsonProperty("code")
|
||||||
@ -286,7 +263,7 @@ public abstract class Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static protected void respond(HttpServletResponse response, String status, String message)
|
static protected void respond(HttpServletResponse response, String status, String message)
|
||||||
throws IOException, JSONException {
|
throws IOException {
|
||||||
|
|
||||||
Writer w = response.getWriter();
|
Writer w = response.getWriter();
|
||||||
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
|
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
|
||||||
@ -301,14 +278,14 @@ public abstract class Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static protected void respondJSON(HttpServletResponse response, Object o)
|
static protected void respondJSON(HttpServletResponse response, Object o)
|
||||||
throws IOException, JSONException {
|
throws IOException {
|
||||||
|
|
||||||
respondJSON(response, o, new Properties());
|
respondJSON(response, o, new Properties());
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected void respondJSON(
|
static protected void respondJSON(
|
||||||
HttpServletResponse response, Object o, Properties options)
|
HttpServletResponse response, Object o, Properties options)
|
||||||
throws IOException, JSONException {
|
throws IOException {
|
||||||
|
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding("UTF-8");
|
||||||
response.setHeader("Content-Type", "application/json");
|
response.setHeader("Content-Type", "application/json");
|
||||||
@ -330,30 +307,26 @@ public abstract class Command {
|
|||||||
throw new ServletException("Response object can't be null");
|
throw new ServletException("Response object can't be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
response.setCharacterEncoding("UTF-8");
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setHeader("Content-Type", "application/json");
|
||||||
response.setHeader("Content-Type", "application/json");
|
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
StringWriter sw = new StringWriter();
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
e.printStackTrace(pw);
|
||||||
e.printStackTrace(pw);
|
pw.flush();
|
||||||
pw.flush();
|
sw.flush();
|
||||||
sw.flush();
|
|
||||||
|
Writer w = response.getWriter();
|
||||||
Writer w = response.getWriter();
|
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
|
||||||
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
|
writer.writeStartObject();
|
||||||
writer.writeStartObject();
|
writer.writeStringField("code", "error");
|
||||||
writer.writeStringField("code", "error");
|
writer.writeStringField("message", e.getMessage());
|
||||||
writer.writeStringField("message", e.getMessage());
|
writer.writeStringField("stack", sw.toString());
|
||||||
writer.writeStringField("stack", sw.toString());
|
writer.writeEndObject();
|
||||||
writer.writeEndObject();
|
writer.flush();
|
||||||
writer.flush();
|
writer.close();
|
||||||
writer.close();
|
w.flush();
|
||||||
w.flush();
|
w.close();
|
||||||
w.close();
|
|
||||||
} catch (JSONException e1) {
|
|
||||||
e.printStackTrace(response.getWriter());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void respondWithErrorPage(
|
protected void respondWithErrorPage(
|
||||||
|
@ -40,8 +40,6 @@ import javax.servlet.ServletException;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
@ -69,11 +67,7 @@ public class GetAllProjectMetadataCommand extends Command {
|
|||||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
|
||||||
try {
|
String userMeta = (String)ProjectManager.singleton.getPreferenceStore().get("userMetadata");
|
||||||
String userMeta = (String)ProjectManager.singleton.getPreferenceStore().get("userMetadata");
|
respondJSON(response, new AllProjectMetadata(ProjectManager.singleton.getAllProjectMetadata(), userMeta));
|
||||||
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.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.google.refine.ProjectManager;
|
import com.google.refine.ProjectManager;
|
||||||
import com.google.refine.commands.Command;
|
import com.google.refine.commands.Command;
|
||||||
@ -56,12 +54,8 @@ public class GetAllProjectTagsCommand extends Command {
|
|||||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
|
||||||
try {
|
Map<String, Integer> tagMap = ProjectManager.singleton.getAllProjectTags();
|
||||||
Map<String, Integer> tagMap = ProjectManager.singleton.getAllProjectTags();
|
Set<String> tags = tagMap == null ? Collections.emptySet() : tagMap.keySet();
|
||||||
Set<String> tags = tagMap == null ? Collections.emptySet() : tagMap.keySet();
|
respondJSON(response, new AllProjectsTags(tags));
|
||||||
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.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.google.refine.browsing.Engine;
|
import com.google.refine.browsing.Engine;
|
||||||
import com.google.refine.browsing.EngineConfig;
|
import com.google.refine.browsing.EngineConfig;
|
||||||
import com.google.refine.commands.Command;
|
import com.google.refine.commands.Command;
|
||||||
@ -55,7 +52,7 @@ public class CommandStub extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public EngineConfig wrapGetEngineConfig(HttpServletRequest request)
|
public EngineConfig wrapGetEngineConfig(HttpServletRequest request)
|
||||||
throws JSONException {
|
{
|
||||||
return getEngineConfig(request);
|
return getEngineConfig(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,8 +64,4 @@ public class CommandStub extends Command {
|
|||||||
public int wrapGetIntegerParameter(HttpServletRequest request, String name,int def) {
|
public int wrapGetIntegerParameter(HttpServletRequest request, String name,int def) {
|
||||||
return getIntegerParameter(request, name, 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("zeronumber");
|
||||||
verify(request, times(1)).getParameter("negativenumber");
|
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