Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-1098 removed org.json dep, replaced usage with Jackson #2127

Merged
merged 1 commit into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,6 @@
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<!-- Testing: JUnit -->
<dependency>
<groupId>junit</groupId>
Expand Down
5 changes: 0 additions & 5 deletions tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,6 @@
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<!-- Testing: JUnit -->
<dependency>
<groupId>junit</groupId>
Expand Down
4 changes: 0 additions & 4 deletions tools/workbench/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
import org.eclipse.rdf4j.workbench.base.TransformationServlet;
import org.eclipse.rdf4j.workbench.util.TupleResultBuilder;
import org.eclipse.rdf4j.workbench.util.WorkbenchRequest;
import org.json.JSONObject;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

/**
* Servlet responsible for presenting the list of repositories, and deleting the chosen one.
*/
public class DeleteServlet extends TransformationServlet {

private static final ObjectMapper mapper = new ObjectMapper();

/**
* Deletes the repository with the given ID, then redirects to the repository selection page. If given a "checkSafe"
* parameter, instead returns JSON response with safe field set to true if safe, false if not.
Expand All @@ -45,8 +49,10 @@ protected void service(WorkbenchRequest req, HttpServletResponse resp, String xs
super.service(req, resp, xslPath);
} else {
// Respond to 'checkSafe' XmlHttpRequest with JSON.
ObjectNode jsonObject = mapper.createObjectNode();
jsonObject.put("safe", manager.isSafeToRemove(checkSafe));
final PrintWriter writer = new PrintWriter(new BufferedWriter(resp.getWriter()));
writer.write(new JSONObject().put("safe", manager.isSafeToRemove(checkSafe)).toString());
writer.write(mapper.writeValueAsString(jsonObject));
writer.flush();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@
import org.eclipse.rdf4j.workbench.util.QueryStorage;
import org.eclipse.rdf4j.workbench.util.TupleResultBuilder;
import org.eclipse.rdf4j.workbench.util.WorkbenchRequest;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class QueryServlet extends TransformationServlet {

protected static final String REF = "ref";
Expand All @@ -72,6 +73,8 @@ public class QueryServlet extends TransformationServlet {

private static final QueryEvaluator EVAL = QueryEvaluator.INSTANCE;

private static final ObjectMapper mapper = new ObjectMapper();

private QueryStorage storage;

protected boolean writeQueryCookie;
Expand Down Expand Up @@ -157,7 +160,7 @@ protected boolean shouldWriteQueryCookie(String queryText) {

@Override
protected void service(final WorkbenchRequest req, final HttpServletResponse resp, final String xslPath)
throws IOException, RDF4JException, BadRequestException, JSONException {
throws IOException, RDF4JException, BadRequestException {
if (!writeQueryCookie) {
// If we suppressed putting the query text into the cookies before.
cookies.addCookie(req, resp, REF, "hash");
Expand All @@ -167,11 +170,11 @@ protected void service(final WorkbenchRequest req, final HttpServletResponse res
cookies.addCookie(req, resp, QUERY, hash);
}
if ("get".equals(req.getParameter("action"))) {
JSONObject json = new JSONObject();
json.put("queryText", getQueryText(req));
ObjectNode jsonObject = mapper.createObjectNode();
jsonObject.put("queryText", getQueryText(req));
PrintWriter writer = new PrintWriter(new BufferedWriter(resp.getWriter()));
try {
writer.write(json.toString());
writer.write(mapper.writeValueAsString(jsonObject));
} finally {
writer.flush();
}
Expand Down Expand Up @@ -201,7 +204,7 @@ private void handleStandardBrowserRequest(WorkbenchRequest req, HttpServletRespo

@Override
protected void doPost(final WorkbenchRequest req, final HttpServletResponse resp, final String xslPath)
throws IOException, BadRequestException, RDF4JException, JSONException {
throws IOException, BadRequestException, RDF4JException {
final String action = req.getParameter("action");
if ("save".equals(action)) {
saveQuery(req, resp);
Expand Down Expand Up @@ -237,17 +240,19 @@ protected void doPost(final WorkbenchRequest req, final HttpServletResponse resp
}

private void saveQuery(final WorkbenchRequest req, final HttpServletResponse resp)
throws IOException, BadRequestException, RDF4JException, JSONException {
throws IOException, BadRequestException, RDF4JException {
resp.setContentType("application/json");
final JSONObject json = new JSONObject();
ObjectNode jsonObject = mapper.createObjectNode();
jsonObject.put("queryText", getQueryText(req));

final HTTPRepository http = (HTTPRepository) repository;
final boolean accessible = storage.checkAccess(http);
json.put("accessible", accessible);
jsonObject.put("accessible", accessible);
if (accessible) {
final String queryName = req.getParameter("query-name");
String userName = getUserNameFromParameter(req, SERVER_USER);
final boolean existed = storage.askExists(http, queryName, userName);
json.put("existed", existed);
jsonObject.put("existed", existed);
final boolean written = Boolean.valueOf(req.getParameter("overwrite")) || !existed;
if (written) {
final boolean shared = !Boolean.valueOf(req.getParameter("save-private"));
Expand All @@ -262,10 +267,10 @@ private void saveQuery(final WorkbenchRequest req, final HttpServletResponse res
storage.saveQuery(http, queryName, userName, shared, queryLanguage, queryText, infer, rowsPerPage);
}
}
json.put("written", written);
jsonObject.put("written", written);
}
final PrintWriter writer = new PrintWriter(new BufferedWriter(resp.getWriter()));
writer.write(json.toString());
writer.write(mapper.writeValueAsString(jsonObject));
writer.flush();
}

Expand Down