5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-10 07:31:32 +08:00

SQOOP-1786: Sqoop2: Stop using JSONValue.parse method call

(Jarek Jarcec Cecho via Abraham Elmahrek)
This commit is contained in:
Abraham Elmahrek 2014-11-26 02:47:11 -08:00
parent 6ea427f9fe
commit 39e99cc5f0
28 changed files with 187 additions and 62 deletions

View File

@ -19,8 +19,8 @@
import org.apache.sqoop.json.ConnectorBean; import org.apache.sqoop.json.ConnectorBean;
import org.apache.sqoop.json.ConnectorsBean; import org.apache.sqoop.json.ConnectorsBean;
import org.apache.sqoop.json.JSONUtils;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
/** /**
* Provide Read semantics over RESTfull HTTP API for connectors. Only read is * Provide Read semantics over RESTfull HTTP API for connectors. Only read is
@ -37,7 +37,7 @@ public ConnectorBean read(String serverUrl, Long cid) {
} else { } else {
response = super.get(serverUrl + RESOURCE + cid); response = super.get(serverUrl + RESOURCE + cid);
} }
JSONObject jsonObject = (JSONObject) JSONValue.parse(response); JSONObject jsonObject = JSONUtils.parse(response);
// defaults to all // defaults to all
ConnectorBean bean = new ConnectorsBean(); ConnectorBean bean = new ConnectorsBean();
if (cid != null) { if (cid != null) {

View File

@ -18,8 +18,8 @@
package org.apache.sqoop.client.request; package org.apache.sqoop.client.request;
import org.apache.sqoop.json.DriverBean; import org.apache.sqoop.json.DriverBean;
import org.apache.sqoop.json.JSONUtils;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
/** /**
* Provide read semantics over RESTfull HTTP API for driver * Provide read semantics over RESTfull HTTP API for driver
@ -31,7 +31,7 @@ public class DriverResourceRequest extends ResourceRequest {
public DriverBean read(String serverUrl) { public DriverBean read(String serverUrl) {
String response = null; String response = null;
response = super.get(serverUrl + RESOURCE); response = super.get(serverUrl + RESOURCE);
JSONObject jsonObject = (JSONObject) JSONValue.parse(response); JSONObject jsonObject = JSONUtils.parse(response);
DriverBean driverBean = new DriverBean(); DriverBean driverBean = new DriverBean();
driverBean.restore(jsonObject); driverBean.restore(jsonObject);
return driverBean; return driverBean;

View File

@ -17,13 +17,13 @@
*/ */
package org.apache.sqoop.client.request; package org.apache.sqoop.client.request;
import org.apache.sqoop.json.JSONUtils;
import org.apache.sqoop.json.JobBean; import org.apache.sqoop.json.JobBean;
import org.apache.sqoop.json.JobsBean; import org.apache.sqoop.json.JobsBean;
import org.apache.sqoop.json.SubmissionBean; import org.apache.sqoop.json.SubmissionBean;
import org.apache.sqoop.json.ValidationResultBean; import org.apache.sqoop.json.ValidationResultBean;
import org.apache.sqoop.model.MJob; import org.apache.sqoop.model.MJob;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
/** /**
* Provide CRUD semantics over RESTfull HTTP API for jobs. All operations are * Provide CRUD semantics over RESTfull HTTP API for jobs. All operations are
@ -46,7 +46,7 @@ public JobBean read(String serverUrl, Long jobId) {
} else { } else {
response = super.get(serverUrl + RESOURCE + jobId); response = super.get(serverUrl + RESOURCE + jobId);
} }
JSONObject jsonObject = (JSONObject) JSONValue.parse(response); JSONObject jsonObject = JSONUtils.parse(response);
// defaults to all // defaults to all
JobBean bean = new JobsBean(); JobBean bean = new JobsBean();
if (jobId != null) { if (jobId != null) {
@ -62,7 +62,7 @@ public ValidationResultBean create(String serverUrl, MJob job) {
JSONObject jobJson = jobBean.extract(false); JSONObject jobJson = jobBean.extract(false);
String response = super.post(serverUrl + RESOURCE, jobJson.toJSONString()); String response = super.post(serverUrl + RESOURCE, jobJson.toJSONString());
ValidationResultBean validationResultBean = new ValidationResultBean(); ValidationResultBean validationResultBean = new ValidationResultBean();
validationResultBean.restore((JSONObject) JSONValue.parse(response)); validationResultBean.restore(JSONUtils.parse(response));
return validationResultBean; return validationResultBean;
} }
@ -73,7 +73,7 @@ public ValidationResultBean update(String serverUrl, MJob job) {
String response = super.put(serverUrl + RESOURCE + job.getPersistenceId(), String response = super.put(serverUrl + RESOURCE + job.getPersistenceId(),
jobJson.toJSONString()); jobJson.toJSONString());
ValidationResultBean validationBean = new ValidationResultBean(); ValidationResultBean validationBean = new ValidationResultBean();
validationBean.restore((JSONObject) JSONValue.parse(response)); validationBean.restore(JSONUtils.parse(response));
return validationBean; return validationBean;
} }
@ -106,7 +106,7 @@ public SubmissionBean status(String serverUrl, Long jobId) {
private SubmissionBean createJobSubmissionResponse(String response) { private SubmissionBean createJobSubmissionResponse(String response) {
SubmissionBean submissionBean = new SubmissionBean(); SubmissionBean submissionBean = new SubmissionBean();
submissionBean.restore((JSONObject) JSONValue.parse(response)); submissionBean.restore(JSONUtils.parse(response));
return submissionBean; return submissionBean;
} }
} }

View File

@ -17,12 +17,12 @@
*/ */
package org.apache.sqoop.client.request; package org.apache.sqoop.client.request;
import org.apache.sqoop.json.JSONUtils;
import org.apache.sqoop.json.LinkBean; import org.apache.sqoop.json.LinkBean;
import org.apache.sqoop.json.LinksBean; import org.apache.sqoop.json.LinksBean;
import org.apache.sqoop.json.ValidationResultBean; import org.apache.sqoop.json.ValidationResultBean;
import org.apache.sqoop.model.MLink; import org.apache.sqoop.model.MLink;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
/** /**
* Provide CRUD semantics over RESTfull HTTP API for links. All operations * Provide CRUD semantics over RESTfull HTTP API for links. All operations
@ -42,7 +42,7 @@ public LinkBean read(String serverUrl, Long linkId) {
} else { } else {
response = super.get(serverUrl + LINK_RESOURCE + linkId); response = super.get(serverUrl + LINK_RESOURCE + linkId);
} }
JSONObject jsonObject = (JSONObject) JSONValue.parse(response); JSONObject jsonObject = JSONUtils.parse(response);
// defaults to all // defaults to all
LinkBean bean = new LinksBean(); LinkBean bean = new LinksBean();
if (linkId != null) { if (linkId != null) {
@ -58,7 +58,7 @@ public ValidationResultBean create(String serverUrl, MLink link) {
JSONObject linkJson = linkBean.extract(false); JSONObject linkJson = linkBean.extract(false);
String response = super.post(serverUrl + LINK_RESOURCE, linkJson.toJSONString()); String response = super.post(serverUrl + LINK_RESOURCE, linkJson.toJSONString());
ValidationResultBean validationBean = new ValidationResultBean(); ValidationResultBean validationBean = new ValidationResultBean();
validationBean.restore((JSONObject) JSONValue.parse(response)); validationBean.restore(JSONUtils.parse(response));
return validationBean; return validationBean;
} }
@ -68,7 +68,7 @@ public ValidationResultBean update(String serverUrl, MLink link) {
JSONObject linkJson = linkBean.extract(false); JSONObject linkJson = linkBean.extract(false);
String response = super.put(serverUrl + LINK_RESOURCE + link.getPersistenceId(), linkJson.toJSONString()); String response = super.put(serverUrl + LINK_RESOURCE + link.getPersistenceId(), linkJson.toJSONString());
ValidationResultBean validationBean = new ValidationResultBean(); ValidationResultBean validationBean = new ValidationResultBean();
validationBean.restore((JSONObject) JSONValue.parse(response)); validationBean.restore(JSONUtils.parse(response));
return validationBean; return validationBean;
} }

View File

@ -23,9 +23,9 @@
import org.apache.sqoop.client.ClientError; import org.apache.sqoop.client.ClientError;
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.common.SqoopProtocolConstants; import org.apache.sqoop.common.SqoopProtocolConstants;
import org.apache.sqoop.json.JSONUtils;
import org.apache.sqoop.json.ThrowableBean; import org.apache.sqoop.json.ThrowableBean;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -107,7 +107,7 @@ protected String doHttpRequest(String strURL, String method, String data) {
} }
reader.close(); reader.close();
JSONObject json = (JSONObject) JSONValue.parse(result.toString()); JSONObject json = JSONUtils.parse(result.toString());
ex.restore(json); ex.restore(json);
throw new SqoopException(ClientError.CLIENT_0001, ex.getThrowable()); throw new SqoopException(ClientError.CLIENT_0001, ex.getThrowable());

View File

@ -17,9 +17,9 @@
*/ */
package org.apache.sqoop.client.request; package org.apache.sqoop.client.request;
import org.apache.sqoop.json.JSONUtils;
import org.apache.sqoop.json.SubmissionsBean; import org.apache.sqoop.json.SubmissionsBean;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
/** /**
* Provide CRD semantics over RESTfull HTTP API for submissions. Please note * Provide CRD semantics over RESTfull HTTP API for submissions. Please note
@ -36,7 +36,7 @@ public SubmissionsBean read(String serverUrl, Long jid) {
} else { } else {
response = super.get(serverUrl + RESOURCE + jid); response = super.get(serverUrl + RESOURCE + jid);
} }
JSONObject jsonObject = (JSONObject) JSONValue.parse(response); JSONObject jsonObject = JSONUtils.parse(response);
SubmissionsBean submissionBean = new SubmissionsBean(); SubmissionsBean submissionBean = new SubmissionsBean();
submissionBean.restore(jsonObject); submissionBean.restore(jsonObject);
return submissionBean; return submissionBean;

View File

@ -17,15 +17,15 @@
*/ */
package org.apache.sqoop.client.request; package org.apache.sqoop.client.request;
import org.apache.sqoop.json.JSONUtils;
import org.apache.sqoop.json.VersionBean; import org.apache.sqoop.json.VersionBean;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
public class VersionResourceRequest extends ResourceRequest public class VersionResourceRequest extends ResourceRequest
{ {
public VersionBean read(String serverUrl) { public VersionBean read(String serverUrl) {
String response = super.get(serverUrl + "version"); String response = super.get(serverUrl + "version");
JSONObject jsonObject = (JSONObject)JSONValue.parse(response); JSONObject jsonObject = JSONUtils.parse(response);
VersionBean versionBean = new VersionBean(); VersionBean versionBean = new VersionBean();
versionBean.restore(jsonObject); versionBean.restore(jsonObject);

View File

@ -0,0 +1,70 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.sqoop.json;
import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.json.util.SerializationError;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.io.Reader;
/**
*/
public class JSONUtils {
/**
* Parse given string as JSON and return corresponding JSONObject.
*
* This method will throw SqoopException on any parsing error.
*
* @param input JSON encoded String
* @return
*/
public static JSONObject parse(String input) {
try {
return (JSONObject) JSONValue.parseWithException(input);
} catch (ParseException e) {
throw new SqoopException(SerializationError.SERIALIZATION_002, e);
}
}
/**
* Parse given reader as JSON and return corresponding JSONObject.
*
* This method will throw SqoopException on any parsing error.
*
* @param reader
* @return
*/
public static JSONObject parse(Reader reader) {
try {
return (JSONObject) JSONValue.parseWithException(reader);
} catch (ParseException e) {
throw new SqoopException(SerializationError.SERIALIZATION_002, e);
} catch (IOException e) {
throw new SqoopException(SerializationError.SERIALIZATION_002, e);
}
}
private JSONUtils() {
// Instantiation is prohibited
}
}

View File

@ -23,6 +23,8 @@ public enum SerializationError implements ErrorCode {
SERIALIZATION_001("Attempt to pass a non-map object to MAP type."), SERIALIZATION_001("Attempt to pass a non-map object to MAP type."),
SERIALIZATION_002("Invalid JSON"),
; ;
private final String message; private final String message;

View File

@ -19,12 +19,12 @@
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.json.JSONUtils;
import org.apache.sqoop.utils.ClassUtils; import org.apache.sqoop.utils.ClassUtils;
import org.apache.sqoop.validation.ConfigValidationRunner; import org.apache.sqoop.validation.ConfigValidationRunner;
import org.apache.sqoop.validation.Message; import org.apache.sqoop.validation.Message;
import org.apache.sqoop.validation.ConfigValidationResult; import org.apache.sqoop.validation.ConfigValidationResult;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.HashMap; import java.util.HashMap;
@ -456,7 +456,7 @@ public static void fillValues(String json, Object configuration) {
Class<?> klass = configuration.getClass(); Class<?> klass = configuration.getClass();
Set<String> configNames = new HashSet<String>(); Set<String> configNames = new HashSet<String>();
JSONObject jsonConfigs = (JSONObject) JSONValue.parse(json); JSONObject jsonConfigs = JSONUtils.parse(json);
for(Field configField : klass.getDeclaredFields()) { for(Field configField : klass.getDeclaredFields()) {
configField.setAccessible(true); configField.setAccessible(true);

View File

@ -30,7 +30,6 @@
import org.apache.sqoop.json.util.ConfigTestUtil; import org.apache.sqoop.json.util.ConfigTestUtil;
import org.apache.sqoop.model.MConnector; import org.apache.sqoop.model.MConnector;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test; import org.junit.Test;
public class TestConnectorBean { public class TestConnectorBean {
@ -57,7 +56,7 @@ public void testConnectorSerialization() {
String connectorJSONString = connectorJSON.toJSONString(); String connectorJSONString = connectorJSON.toJSONString();
// Retrieved transferred object // Retrieved transferred object
JSONObject parsedConnectors = (JSONObject) JSONValue.parse(connectorJSONString); JSONObject parsedConnectors = JSONUtils.parse(connectorJSONString);
ConnectorBean parsedConnectorBean = new ConnectorBean(); ConnectorBean parsedConnectorBean = new ConnectorBean();
parsedConnectorBean.restore(parsedConnectors); parsedConnectorBean.restore(parsedConnectors);
assertEquals(connectors.size(), 1); assertEquals(connectors.size(), 1);

View File

@ -30,7 +30,6 @@
import org.apache.sqoop.json.util.ConfigTestUtil; import org.apache.sqoop.json.util.ConfigTestUtil;
import org.apache.sqoop.model.MConnector; import org.apache.sqoop.model.MConnector;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test; import org.junit.Test;
public class TestConnectorsBean { public class TestConnectorsBean {
@ -55,7 +54,7 @@ public void testConnectorsSerialization() {
String connectorsJSONString = connectorsJSON.toJSONString(); String connectorsJSONString = connectorsJSON.toJSONString();
// Retrieved transferred object // Retrieved transferred object
JSONObject parsedConnectors = (JSONObject) JSONValue.parse(connectorsJSONString); JSONObject parsedConnectors = JSONUtils.parse(connectorsJSONString);
ConnectorsBean parsedConnectorsBean = new ConnectorsBean(); ConnectorsBean parsedConnectorsBean = new ConnectorsBean();
parsedConnectorsBean.restore(parsedConnectors); parsedConnectorsBean.restore(parsedConnectors);
@ -89,7 +88,7 @@ public void testSingleDirection() {
String string = json.toJSONString(); String string = json.toJSONString();
// Retrieved transferred object // Retrieved transferred object
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); JSONObject retrievedJson = JSONUtils.parse(string);
ConnectorsBean retrievedBean = new ConnectorsBean(); ConnectorsBean retrievedBean = new ConnectorsBean();
retrievedBean.restore(retrievedJson); retrievedBean.restore(retrievedJson);
@ -118,7 +117,7 @@ public void testNoDirection() {
String string = json.toJSONString(); String string = json.toJSONString();
// Retrieved transferred object // Retrieved transferred object
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); JSONObject retrievedJson = JSONUtils.parse(string);
ConnectorsBean retrievedBean = new ConnectorsBean(); ConnectorsBean retrievedBean = new ConnectorsBean();
retrievedBean.restore(retrievedJson); retrievedBean.restore(retrievedJson);

View File

@ -24,7 +24,6 @@
import org.apache.sqoop.json.util.ConfigTestUtil; import org.apache.sqoop.json.util.ConfigTestUtil;
import org.apache.sqoop.model.MDriver; import org.apache.sqoop.model.MDriver;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test; import org.junit.Test;
/** /**
@ -48,7 +47,7 @@ public void testSerialization() {
String string = json.toJSONString(); String string = json.toJSONString();
// Retrieved transferred object // Retrieved transferred object
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); JSONObject retrievedJson = JSONUtils.parse(string);
DriverBean retrievedBean = new DriverBean(); DriverBean retrievedBean = new DriverBean();
retrievedBean.restore(retrievedJson); retrievedBean.restore(retrievedJson);

View File

@ -0,0 +1,64 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.sqoop.json;
import org.apache.sqoop.common.SqoopException;
import org.json.simple.JSONObject;
import org.junit.Test;
import java.io.Reader;
import java.io.StringReader;
import static org.junit.Assert.assertEquals;
/**
*/
public class TestJSONUtils {
@Test
public void testString() {
JSONObject object = JSONUtils.parse("{\"id\":3}");
assertEquals((long)3, object.get("id"));
}
@Test(expected = SqoopException.class)
public void testStringInvalid() {
JSONUtils.parse("{");
}
@Test(expected = NullPointerException.class)
public void testStringNull() {
JSONUtils.parse((String)null);
}
@Test
public void testReader() {
JSONObject object = JSONUtils.parse(new StringReader("{\"id\":3}"));
assertEquals((long)3, object.get("id"));
}
@Test(expected = SqoopException.class)
public void testReaderInvalid() {
JSONUtils.parse(new StringReader("{"));
}
@Test(expected = NullPointerException.class)
public void testReaderNull() {
JSONUtils.parse((Reader)null);
}
}

View File

@ -26,7 +26,6 @@
import org.apache.sqoop.model.MJob; import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MStringInput; import org.apache.sqoop.model.MStringInput;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import org.junit.Test; import org.junit.Test;
@ -53,7 +52,7 @@ public void testJobSerialization() throws ParseException {
String jobJsonString = json.toJSONString(); String jobJsonString = json.toJSONString();
// Retrieved transferred object // Retrieved transferred object
JSONObject parsedJobJson = (JSONObject) JSONValue.parse(jobJsonString); JSONObject parsedJobJson = JSONUtils.parse(jobJsonString);
JobBean parsedJobBean = new JobBean(); JobBean parsedJobBean = new JobBean();
parsedJobBean.restore(parsedJobJson); parsedJobBean.restore(parsedJobJson);
MJob target = parsedJobBean.getJobs().get(0); MJob target = parsedJobBean.getJobs().get(0);

View File

@ -28,7 +28,6 @@
import org.apache.sqoop.model.MJob; import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MStringInput; import org.apache.sqoop.model.MStringInput;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import org.junit.Test; import org.junit.Test;
@ -60,7 +59,7 @@ public void testJobsSerialization() throws ParseException {
String jobJsonString = json.toJSONString(); String jobJsonString = json.toJSONString();
// Retrieved transferred object // Retrieved transferred object
JSONObject parsedJobsJson = (JSONObject) JSONValue.parse(jobJsonString); JSONObject parsedJobsJson = JSONUtils.parse(jobJsonString);
JobsBean parsedJobsBean = new JobsBean(); JobsBean parsedJobsBean = new JobsBean();
parsedJobsBean.restore(parsedJobsJson); parsedJobsBean.restore(parsedJobsJson);
MJob retrievedJob1 = parsedJobsBean.getJobs().get(0); MJob retrievedJob1 = parsedJobsBean.getJobs().get(0);

View File

@ -29,7 +29,6 @@
import org.apache.sqoop.model.MStringInput; import org.apache.sqoop.model.MStringInput;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test; import org.junit.Test;
public class TestLinkBean { public class TestLinkBean {
@ -62,7 +61,7 @@ public void testLinkSerialization() {
String linkJsonString = json.toJSONString(); String linkJsonString = json.toJSONString();
// Retrieved transferred object // Retrieved transferred object
JSONObject parsedLinkJson = (JSONObject) JSONValue.parse(linkJsonString); JSONObject parsedLinkJson = JSONUtils.parse(linkJsonString);
LinkBean retrievedBean = new LinkBean(); LinkBean retrievedBean = new LinkBean();
retrievedBean.restore(parsedLinkJson); retrievedBean.restore(parsedLinkJson);
MLink retrievedLink = retrievedBean.getLinks().get(0); MLink retrievedLink = retrievedBean.getLinks().get(0);

View File

@ -30,7 +30,6 @@
import org.apache.sqoop.model.MStringInput; import org.apache.sqoop.model.MStringInput;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test; import org.junit.Test;
public class TestLinksBean { public class TestLinksBean {
@ -70,7 +69,7 @@ public void testLinksSerialization() {
String linkJsonString = json.toJSONString(); String linkJsonString = json.toJSONString();
// Retrieved transferred object // Retrieved transferred object
JSONObject parsedLinkJson = (JSONObject) JSONValue.parse(linkJsonString); JSONObject parsedLinkJson = JSONUtils.parse(linkJsonString);
LinksBean retrievedBean = new LinksBean(); LinksBean retrievedBean = new LinksBean();
retrievedBean.restore(parsedLinkJson); retrievedBean.restore(parsedLinkJson);
MLink targetLink1 = retrievedBean.getLinks().get(0); MLink targetLink1 = retrievedBean.getLinks().get(0);

View File

@ -20,7 +20,6 @@
import org.apache.sqoop.json.util.TestSchemaSerialization; import org.apache.sqoop.json.util.TestSchemaSerialization;
import org.apache.sqoop.schema.Schema; import org.apache.sqoop.schema.Schema;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
/** /**
* Run the same tests as TestSchemaSerialization, but using the SchamaBean * Run the same tests as TestSchemaSerialization, but using the SchamaBean
@ -41,7 +40,7 @@ protected Schema transfer(Schema schema) {
String transferredString = extractJson.toJSONString(); String transferredString = extractJson.toJSONString();
JSONObject restoreJson = (JSONObject) JSONValue.parse(transferredString); JSONObject restoreJson = JSONUtils.parse(transferredString);
SchemaBean restoreBean = new SchemaBean(); SchemaBean restoreBean = new SchemaBean();
restoreBean.restore(restoreJson); restoreBean.restore(restoreJson);

View File

@ -26,7 +26,6 @@
import org.apache.sqoop.submission.counter.CounterGroup; import org.apache.sqoop.submission.counter.CounterGroup;
import org.apache.sqoop.submission.counter.Counters; import org.apache.sqoop.submission.counter.Counters;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
@ -460,7 +459,7 @@ private MSubmission transfer(MSubmission submission) {
String string = json.toString(); String string = json.toString();
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); JSONObject retrievedJson = JSONUtils.parse(string);
SubmissionsBean retrievedBean = new SubmissionsBean(); SubmissionsBean retrievedBean = new SubmissionsBean();
retrievedBean.restore(retrievedJson); retrievedBean.restore(retrievedJson);
@ -479,7 +478,7 @@ private List<MSubmission> transfer(List<MSubmission> submissions) {
String string = json.toString(); String string = json.toString();
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); JSONObject retrievedJson = JSONUtils.parse(string);
SubmissionsBean retrievedBean = new SubmissionsBean(); SubmissionsBean retrievedBean = new SubmissionsBean();
retrievedBean.restore(retrievedJson); retrievedBean.restore(retrievedJson);

View File

@ -20,7 +20,6 @@
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.json.util.SerializationError; import org.apache.sqoop.json.util.SerializationError;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -68,7 +67,7 @@ public Throwable transfer(Throwable source) {
String string = json.toJSONString(); String string = json.toJSONString();
// Retrieved transferred object // Retrieved transferred object
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); JSONObject retrievedJson = JSONUtils.parse(string);
ThrowableBean retrievedBean = new ThrowableBean(); ThrowableBean retrievedBean = new ThrowableBean();
retrievedBean.restore(retrievedJson); retrievedBean.restore(retrievedJson);
return retrievedBean.getThrowable(); return retrievedBean.getThrowable();

View File

@ -21,7 +21,6 @@
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
import org.apache.sqoop.validation.ConfigValidationResult; import org.apache.sqoop.validation.ConfigValidationResult;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test; import org.junit.Test;
import java.util.LinkedList; import java.util.LinkedList;
@ -115,7 +114,7 @@ private Long transfer(Long id) {
String string = json.toString(); String string = json.toString();
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); JSONObject retrievedJson = JSONUtils.parse(string);
ValidationResultBean retrievedBean = new ValidationResultBean(); ValidationResultBean retrievedBean = new ValidationResultBean();
retrievedBean.restore(retrievedJson); retrievedBean.restore(retrievedJson);
@ -128,7 +127,7 @@ private ConfigValidationResult[] transfer(ConfigValidationResult [] results) {
String string = json.toString(); String string = json.toString();
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string); JSONObject retrievedJson = JSONUtils.parse(string);
ValidationResultBean retrievedBean = new ValidationResultBean(); ValidationResultBean retrievedBean = new ValidationResultBean();
retrievedBean.restore(retrievedJson); retrievedBean.restore(retrievedJson);

View File

@ -26,6 +26,7 @@
import java.util.Map; import java.util.Map;
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.json.JSONUtils;
import org.apache.sqoop.model.MBooleanInput; import org.apache.sqoop.model.MBooleanInput;
import org.apache.sqoop.model.MConfig; import org.apache.sqoop.model.MConfig;
import org.apache.sqoop.model.MConfigType; import org.apache.sqoop.model.MConfigType;
@ -35,7 +36,6 @@
import org.apache.sqoop.model.MMapInput; import org.apache.sqoop.model.MMapInput;
import org.apache.sqoop.model.MStringInput; import org.apache.sqoop.model.MStringInput;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test; import org.junit.Test;
/** /**
@ -63,7 +63,7 @@ public void testAllDataTypes() {
// Exchange the data on string level // Exchange the data on string level
String serializedJson = jsonObject.toJSONString(); String serializedJson = jsonObject.toJSONString();
JSONObject retrievedJson = (JSONObject) JSONValue.parse(serializedJson); JSONObject retrievedJson = JSONUtils.parse(serializedJson);
// And retrieve back from JSON representation // And retrieve back from JSON representation
MConfig retrieved = ConfigInputSerialization.restoreConfig(retrievedJson); MConfig retrieved = ConfigInputSerialization.restoreConfig(retrievedJson);
@ -90,7 +90,7 @@ public void testMapDataType() {
String serializedJson = jsonObject.toJSONString(); String serializedJson = jsonObject.toJSONString();
// Deserialize // Deserialize
JSONObject retrievedJson = (JSONObject) JSONValue.parse(serializedJson); JSONObject retrievedJson = JSONUtils.parse(serializedJson);
MConfig retrieved = ConfigInputSerialization.restoreConfig(retrievedJson); MConfig retrieved = ConfigInputSerialization.restoreConfig(retrievedJson);
assertEquals(map, retrieved.getMapInput("Map").getValue()); assertEquals(map, retrieved.getMapInput("Map").getValue());
} }
@ -111,7 +111,7 @@ public void testMapDataTypeException() {
// Replace map value with a fake string to force exception // Replace map value with a fake string to force exception
String badSerializedJson = serializedJson.replace("{\"A\":\"B\"}", "\"nonsensical string\""); String badSerializedJson = serializedJson.replace("{\"A\":\"B\"}", "\"nonsensical string\"");
System.out.println(badSerializedJson); System.out.println(badSerializedJson);
JSONObject retrievedJson = (JSONObject) JSONValue.parse(badSerializedJson); JSONObject retrievedJson = JSONUtils.parse(badSerializedJson);
ConfigInputSerialization.restoreConfig(retrievedJson); ConfigInputSerialization.restoreConfig(retrievedJson);
} }

View File

@ -23,6 +23,7 @@
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import org.apache.sqoop.json.JSONUtils;
import org.apache.sqoop.schema.NullSchema; import org.apache.sqoop.schema.NullSchema;
import org.apache.sqoop.schema.Schema; import org.apache.sqoop.schema.Schema;
import org.apache.sqoop.schema.type.Array; import org.apache.sqoop.schema.type.Array;
@ -40,7 +41,6 @@
import org.apache.sqoop.schema.type.Time; import org.apache.sqoop.schema.type.Time;
import org.apache.sqoop.schema.type.Unknown; import org.apache.sqoop.schema.type.Unknown;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test; import org.junit.Test;
/** /**
@ -52,7 +52,7 @@ public class TestSchemaSerialization {
public void testSchemaNull() { public void testSchemaNull() {
// a null schema is treated as a NullSchema // a null schema is treated as a NullSchema
JSONObject extractJson = SchemaSerialization.extractSchema(null); JSONObject extractJson = SchemaSerialization.extractSchema(null);
JSONObject restoreJson = (JSONObject) JSONValue.parse(extractJson.toJSONString()); JSONObject restoreJson = JSONUtils.parse(extractJson.toJSONString());
assertEquals(NullSchema.getInstance(), SchemaSerialization.restoreSchema(restoreJson)); assertEquals(NullSchema.getInstance(), SchemaSerialization.restoreSchema(restoreJson));
} }
@ -189,7 +189,7 @@ private void transferAndAssert(Schema schema) {
protected Schema transfer(Schema schema) { protected Schema transfer(Schema schema) {
JSONObject extractJson = SchemaSerialization.extractSchema(schema); JSONObject extractJson = SchemaSerialization.extractSchema(schema);
String transferredString = extractJson.toJSONString(); String transferredString = extractJson.toJSONString();
JSONObject restoreJson = (JSONObject) JSONValue.parse(transferredString); JSONObject restoreJson = JSONUtils.parse(transferredString);
return SchemaSerialization.restoreSchema(restoreJson); return SchemaSerialization.restoreSchema(restoreJson);
} }
} }

View File

@ -24,12 +24,12 @@
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import org.apache.sqoop.common.Direction; import org.apache.sqoop.common.Direction;
import org.apache.sqoop.job.MRJobConstants; import org.apache.sqoop.job.MRJobConstants;
import org.apache.sqoop.json.JSONUtils;
import org.apache.sqoop.json.util.SchemaSerialization; import org.apache.sqoop.json.util.SchemaSerialization;
import org.apache.sqoop.model.ConfigUtils; import org.apache.sqoop.model.ConfigUtils;
import org.apache.sqoop.schema.Schema; import org.apache.sqoop.schema.Schema;
import org.apache.sqoop.utils.ClassUtils; import org.apache.sqoop.utils.ClassUtils;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import java.io.InputStream; import java.io.InputStream;
import java.util.Properties; import java.util.Properties;
@ -228,7 +228,7 @@ private static Schema getSchemaFromBytes(byte[] bytes) {
return null; return null;
} }
JSONObject jsonSchema = (JSONObject) JSONValue.parse(new String(bytes)); JSONObject jsonSchema = JSONUtils.parse(new String(bytes));
return SchemaSerialization.restoreSchema(jsonSchema); return SchemaSerialization.restoreSchema(jsonSchema);
} }

View File

@ -30,6 +30,7 @@
import org.apache.sqoop.connector.spi.SqoopConnector; import org.apache.sqoop.connector.spi.SqoopConnector;
import org.apache.sqoop.driver.Driver; import org.apache.sqoop.driver.Driver;
import org.apache.sqoop.driver.JobManager; import org.apache.sqoop.driver.JobManager;
import org.apache.sqoop.json.JSONUtils;
import org.apache.sqoop.json.JobBean; import org.apache.sqoop.json.JobBean;
import org.apache.sqoop.json.JobsBean; import org.apache.sqoop.json.JobsBean;
import org.apache.sqoop.json.JsonBean; import org.apache.sqoop.json.JsonBean;
@ -51,7 +52,6 @@
import org.apache.sqoop.validation.ConfigValidationResult; import org.apache.sqoop.validation.ConfigValidationResult;
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
public class JobRequestHandler implements RequestHandler { public class JobRequestHandler implements RequestHandler {
@ -156,7 +156,7 @@ private JsonBean createUpdateJob(RequestContext ctx, boolean create) {
JobBean bean = new JobBean(); JobBean bean = new JobBean();
try { try {
JSONObject json = (JSONObject) JSONValue.parse(ctx.getRequest().getReader()); JSONObject json = JSONUtils.parse(ctx.getRequest().getReader());
bean.restore(json); bean.restore(json);
} catch (IOException e) { } catch (IOException e) {
throw new SqoopException(ServerError.SERVER_0003, "Can't read request content", e); throw new SqoopException(ServerError.SERVER_0003, "Can't read request content", e);

View File

@ -27,6 +27,7 @@
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.connector.ConnectorManager; import org.apache.sqoop.connector.ConnectorManager;
import org.apache.sqoop.connector.spi.SqoopConnector; import org.apache.sqoop.connector.spi.SqoopConnector;
import org.apache.sqoop.json.JSONUtils;
import org.apache.sqoop.json.JsonBean; import org.apache.sqoop.json.JsonBean;
import org.apache.sqoop.json.LinkBean; import org.apache.sqoop.json.LinkBean;
import org.apache.sqoop.json.LinksBean; import org.apache.sqoop.json.LinksBean;
@ -42,7 +43,6 @@
import org.apache.sqoop.server.common.ServerError; import org.apache.sqoop.server.common.ServerError;
import org.apache.sqoop.validation.ConfigValidationResult; import org.apache.sqoop.validation.ConfigValidationResult;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
public class LinkRequestHandler implements RequestHandler { public class LinkRequestHandler implements RequestHandler {
@ -110,7 +110,7 @@ private JsonBean createUpdateLink(RequestContext ctx, boolean create) {
LinkBean linkBean = new LinkBean(); LinkBean linkBean = new LinkBean();
try { try {
JSONObject postData = (JSONObject) JSONValue.parse(ctx.getRequest().getReader()); JSONObject postData = JSONUtils.parse(ctx.getRequest().getReader());
linkBean.restore(postData); linkBean.restore(postData);
} catch (IOException e) { } catch (IOException e) {
throw new SqoopException(ServerError.SERVER_0003, "Can't read request content", e); throw new SqoopException(ServerError.SERVER_0003, "Can't read request content", e);

View File

@ -42,6 +42,7 @@
import org.apache.sqoop.connector.spi.SqoopConnector; import org.apache.sqoop.connector.spi.SqoopConnector;
import org.apache.sqoop.driver.Driver; import org.apache.sqoop.driver.Driver;
import org.apache.sqoop.driver.DriverUpgrader; import org.apache.sqoop.driver.DriverUpgrader;
import org.apache.sqoop.json.JSONUtils;
import org.apache.sqoop.json.JobBean; import org.apache.sqoop.json.JobBean;
import org.apache.sqoop.json.LinkBean; import org.apache.sqoop.json.LinkBean;
import org.apache.sqoop.json.SubmissionBean; import org.apache.sqoop.json.SubmissionBean;
@ -66,7 +67,6 @@
import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Status;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
/** /**
* Load user-created content of Sqoop repository from a JSON formatted file The * Load user-created content of Sqoop repository from a JSON formatted file The
@ -93,7 +93,7 @@ public boolean runToolWithConfiguration(String[] arguments) {
LOG.info("Reading JSON from file" + inputFileName); LOG.info("Reading JSON from file" + inputFileName);
InputStream input = new FileInputStream(inputFileName); InputStream input = new FileInputStream(inputFileName);
String jsonTxt = IOUtils.toString(input, Charsets.UTF_8); String jsonTxt = IOUtils.toString(input, Charsets.UTF_8);
JSONObject json = (JSONObject) JSONValue.parse(jsonTxt); JSONObject json = JSONUtils.parse(jsonTxt);
boolean res = load(json); boolean res = load(json);
input.close(); input.close();
return res; return res;