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:
parent
6ea427f9fe
commit
39e99cc5f0
@ -19,8 +19,8 @@
|
||||
|
||||
import org.apache.sqoop.json.ConnectorBean;
|
||||
import org.apache.sqoop.json.ConnectorsBean;
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
/**
|
||||
* Provide Read semantics over RESTfull HTTP API for connectors. Only read is
|
||||
@ -37,7 +37,7 @@ public ConnectorBean read(String serverUrl, Long cid) {
|
||||
} else {
|
||||
response = super.get(serverUrl + RESOURCE + cid);
|
||||
}
|
||||
JSONObject jsonObject = (JSONObject) JSONValue.parse(response);
|
||||
JSONObject jsonObject = JSONUtils.parse(response);
|
||||
// defaults to all
|
||||
ConnectorBean bean = new ConnectorsBean();
|
||||
if (cid != null) {
|
||||
|
@ -18,8 +18,8 @@
|
||||
package org.apache.sqoop.client.request;
|
||||
|
||||
import org.apache.sqoop.json.DriverBean;
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
/**
|
||||
* Provide read semantics over RESTfull HTTP API for driver
|
||||
@ -31,7 +31,7 @@ public class DriverResourceRequest extends ResourceRequest {
|
||||
public DriverBean read(String serverUrl) {
|
||||
String response = null;
|
||||
response = super.get(serverUrl + RESOURCE);
|
||||
JSONObject jsonObject = (JSONObject) JSONValue.parse(response);
|
||||
JSONObject jsonObject = JSONUtils.parse(response);
|
||||
DriverBean driverBean = new DriverBean();
|
||||
driverBean.restore(jsonObject);
|
||||
return driverBean;
|
||||
|
@ -17,13 +17,13 @@
|
||||
*/
|
||||
package org.apache.sqoop.client.request;
|
||||
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.apache.sqoop.json.JobBean;
|
||||
import org.apache.sqoop.json.JobsBean;
|
||||
import org.apache.sqoop.json.SubmissionBean;
|
||||
import org.apache.sqoop.json.ValidationResultBean;
|
||||
import org.apache.sqoop.model.MJob;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
/**
|
||||
* Provide CRUD semantics over RESTfull HTTP API for jobs. All operations are
|
||||
@ -46,7 +46,7 @@ public JobBean read(String serverUrl, Long jobId) {
|
||||
} else {
|
||||
response = super.get(serverUrl + RESOURCE + jobId);
|
||||
}
|
||||
JSONObject jsonObject = (JSONObject) JSONValue.parse(response);
|
||||
JSONObject jsonObject = JSONUtils.parse(response);
|
||||
// defaults to all
|
||||
JobBean bean = new JobsBean();
|
||||
if (jobId != null) {
|
||||
@ -62,7 +62,7 @@ public ValidationResultBean create(String serverUrl, MJob job) {
|
||||
JSONObject jobJson = jobBean.extract(false);
|
||||
String response = super.post(serverUrl + RESOURCE, jobJson.toJSONString());
|
||||
ValidationResultBean validationResultBean = new ValidationResultBean();
|
||||
validationResultBean.restore((JSONObject) JSONValue.parse(response));
|
||||
validationResultBean.restore(JSONUtils.parse(response));
|
||||
return validationResultBean;
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ public ValidationResultBean update(String serverUrl, MJob job) {
|
||||
String response = super.put(serverUrl + RESOURCE + job.getPersistenceId(),
|
||||
jobJson.toJSONString());
|
||||
ValidationResultBean validationBean = new ValidationResultBean();
|
||||
validationBean.restore((JSONObject) JSONValue.parse(response));
|
||||
validationBean.restore(JSONUtils.parse(response));
|
||||
return validationBean;
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ public SubmissionBean status(String serverUrl, Long jobId) {
|
||||
|
||||
private SubmissionBean createJobSubmissionResponse(String response) {
|
||||
SubmissionBean submissionBean = new SubmissionBean();
|
||||
submissionBean.restore((JSONObject) JSONValue.parse(response));
|
||||
submissionBean.restore(JSONUtils.parse(response));
|
||||
return submissionBean;
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +17,12 @@
|
||||
*/
|
||||
package org.apache.sqoop.client.request;
|
||||
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.apache.sqoop.json.LinkBean;
|
||||
import org.apache.sqoop.json.LinksBean;
|
||||
import org.apache.sqoop.json.ValidationResultBean;
|
||||
import org.apache.sqoop.model.MLink;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
/**
|
||||
* Provide CRUD semantics over RESTfull HTTP API for links. All operations
|
||||
@ -42,7 +42,7 @@ public LinkBean read(String serverUrl, Long linkId) {
|
||||
} else {
|
||||
response = super.get(serverUrl + LINK_RESOURCE + linkId);
|
||||
}
|
||||
JSONObject jsonObject = (JSONObject) JSONValue.parse(response);
|
||||
JSONObject jsonObject = JSONUtils.parse(response);
|
||||
// defaults to all
|
||||
LinkBean bean = new LinksBean();
|
||||
if (linkId != null) {
|
||||
@ -58,7 +58,7 @@ public ValidationResultBean create(String serverUrl, MLink link) {
|
||||
JSONObject linkJson = linkBean.extract(false);
|
||||
String response = super.post(serverUrl + LINK_RESOURCE, linkJson.toJSONString());
|
||||
ValidationResultBean validationBean = new ValidationResultBean();
|
||||
validationBean.restore((JSONObject) JSONValue.parse(response));
|
||||
validationBean.restore(JSONUtils.parse(response));
|
||||
return validationBean;
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ public ValidationResultBean update(String serverUrl, MLink link) {
|
||||
JSONObject linkJson = linkBean.extract(false);
|
||||
String response = super.put(serverUrl + LINK_RESOURCE + link.getPersistenceId(), linkJson.toJSONString());
|
||||
ValidationResultBean validationBean = new ValidationResultBean();
|
||||
validationBean.restore((JSONObject) JSONValue.parse(response));
|
||||
validationBean.restore(JSONUtils.parse(response));
|
||||
return validationBean;
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,9 @@
|
||||
import org.apache.sqoop.client.ClientError;
|
||||
import org.apache.sqoop.common.SqoopException;
|
||||
import org.apache.sqoop.common.SqoopProtocolConstants;
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.apache.sqoop.json.ThrowableBean;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
@ -107,7 +107,7 @@ protected String doHttpRequest(String strURL, String method, String data) {
|
||||
}
|
||||
reader.close();
|
||||
|
||||
JSONObject json = (JSONObject) JSONValue.parse(result.toString());
|
||||
JSONObject json = JSONUtils.parse(result.toString());
|
||||
ex.restore(json);
|
||||
|
||||
throw new SqoopException(ClientError.CLIENT_0001, ex.getThrowable());
|
||||
|
@ -17,9 +17,9 @@
|
||||
*/
|
||||
package org.apache.sqoop.client.request;
|
||||
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.apache.sqoop.json.SubmissionsBean;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
/**
|
||||
* Provide CRD semantics over RESTfull HTTP API for submissions. Please note
|
||||
@ -36,7 +36,7 @@ public SubmissionsBean read(String serverUrl, Long jid) {
|
||||
} else {
|
||||
response = super.get(serverUrl + RESOURCE + jid);
|
||||
}
|
||||
JSONObject jsonObject = (JSONObject) JSONValue.parse(response);
|
||||
JSONObject jsonObject = JSONUtils.parse(response);
|
||||
SubmissionsBean submissionBean = new SubmissionsBean();
|
||||
submissionBean.restore(jsonObject);
|
||||
return submissionBean;
|
||||
|
@ -17,15 +17,15 @@
|
||||
*/
|
||||
package org.apache.sqoop.client.request;
|
||||
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.apache.sqoop.json.VersionBean;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
public class VersionResourceRequest extends ResourceRequest
|
||||
{
|
||||
public VersionBean read(String serverUrl) {
|
||||
String response = super.get(serverUrl + "version");
|
||||
JSONObject jsonObject = (JSONObject)JSONValue.parse(response);
|
||||
JSONObject jsonObject = JSONUtils.parse(response);
|
||||
|
||||
VersionBean versionBean = new VersionBean();
|
||||
versionBean.restore(jsonObject);
|
||||
|
70
common/src/main/java/org/apache/sqoop/json/JSONUtils.java
Normal file
70
common/src/main/java/org/apache/sqoop/json/JSONUtils.java
Normal 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
|
||||
}
|
||||
}
|
@ -23,6 +23,8 @@ public enum SerializationError implements ErrorCode {
|
||||
|
||||
SERIALIZATION_001("Attempt to pass a non-map object to MAP type."),
|
||||
|
||||
SERIALIZATION_002("Invalid JSON"),
|
||||
|
||||
;
|
||||
|
||||
private final String message;
|
||||
|
@ -19,12 +19,12 @@
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.sqoop.common.SqoopException;
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.apache.sqoop.utils.ClassUtils;
|
||||
import org.apache.sqoop.validation.ConfigValidationRunner;
|
||||
import org.apache.sqoop.validation.Message;
|
||||
import org.apache.sqoop.validation.ConfigValidationResult;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
@ -456,7 +456,7 @@ public static void fillValues(String json, Object configuration) {
|
||||
Class<?> klass = configuration.getClass();
|
||||
|
||||
Set<String> configNames = new HashSet<String>();
|
||||
JSONObject jsonConfigs = (JSONObject) JSONValue.parse(json);
|
||||
JSONObject jsonConfigs = JSONUtils.parse(json);
|
||||
|
||||
for(Field configField : klass.getDeclaredFields()) {
|
||||
configField.setAccessible(true);
|
||||
|
@ -30,7 +30,6 @@
|
||||
import org.apache.sqoop.json.util.ConfigTestUtil;
|
||||
import org.apache.sqoop.model.MConnector;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestConnectorBean {
|
||||
@ -57,7 +56,7 @@ public void testConnectorSerialization() {
|
||||
String connectorJSONString = connectorJSON.toJSONString();
|
||||
|
||||
// Retrieved transferred object
|
||||
JSONObject parsedConnectors = (JSONObject) JSONValue.parse(connectorJSONString);
|
||||
JSONObject parsedConnectors = JSONUtils.parse(connectorJSONString);
|
||||
ConnectorBean parsedConnectorBean = new ConnectorBean();
|
||||
parsedConnectorBean.restore(parsedConnectors);
|
||||
assertEquals(connectors.size(), 1);
|
||||
|
@ -30,7 +30,6 @@
|
||||
import org.apache.sqoop.json.util.ConfigTestUtil;
|
||||
import org.apache.sqoop.model.MConnector;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestConnectorsBean {
|
||||
@ -55,7 +54,7 @@ public void testConnectorsSerialization() {
|
||||
String connectorsJSONString = connectorsJSON.toJSONString();
|
||||
|
||||
// Retrieved transferred object
|
||||
JSONObject parsedConnectors = (JSONObject) JSONValue.parse(connectorsJSONString);
|
||||
JSONObject parsedConnectors = JSONUtils.parse(connectorsJSONString);
|
||||
ConnectorsBean parsedConnectorsBean = new ConnectorsBean();
|
||||
parsedConnectorsBean.restore(parsedConnectors);
|
||||
|
||||
@ -89,7 +88,7 @@ public void testSingleDirection() {
|
||||
String string = json.toJSONString();
|
||||
|
||||
// Retrieved transferred object
|
||||
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string);
|
||||
JSONObject retrievedJson = JSONUtils.parse(string);
|
||||
ConnectorsBean retrievedBean = new ConnectorsBean();
|
||||
retrievedBean.restore(retrievedJson);
|
||||
|
||||
@ -118,7 +117,7 @@ public void testNoDirection() {
|
||||
String string = json.toJSONString();
|
||||
|
||||
// Retrieved transferred object
|
||||
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string);
|
||||
JSONObject retrievedJson = JSONUtils.parse(string);
|
||||
ConnectorsBean retrievedBean = new ConnectorsBean();
|
||||
retrievedBean.restore(retrievedJson);
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
import org.apache.sqoop.json.util.ConfigTestUtil;
|
||||
import org.apache.sqoop.model.MDriver;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -48,7 +47,7 @@ public void testSerialization() {
|
||||
String string = json.toJSONString();
|
||||
|
||||
// Retrieved transferred object
|
||||
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string);
|
||||
JSONObject retrievedJson = JSONUtils.parse(string);
|
||||
DriverBean retrievedBean = new DriverBean();
|
||||
retrievedBean.restore(retrievedJson);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -26,7 +26,6 @@
|
||||
import org.apache.sqoop.model.MJob;
|
||||
import org.apache.sqoop.model.MStringInput;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -53,7 +52,7 @@ public void testJobSerialization() throws ParseException {
|
||||
String jobJsonString = json.toJSONString();
|
||||
|
||||
// Retrieved transferred object
|
||||
JSONObject parsedJobJson = (JSONObject) JSONValue.parse(jobJsonString);
|
||||
JSONObject parsedJobJson = JSONUtils.parse(jobJsonString);
|
||||
JobBean parsedJobBean = new JobBean();
|
||||
parsedJobBean.restore(parsedJobJson);
|
||||
MJob target = parsedJobBean.getJobs().get(0);
|
||||
|
@ -28,7 +28,6 @@
|
||||
import org.apache.sqoop.model.MJob;
|
||||
import org.apache.sqoop.model.MStringInput;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -60,7 +59,7 @@ public void testJobsSerialization() throws ParseException {
|
||||
String jobJsonString = json.toJSONString();
|
||||
|
||||
// Retrieved transferred object
|
||||
JSONObject parsedJobsJson = (JSONObject) JSONValue.parse(jobJsonString);
|
||||
JSONObject parsedJobsJson = JSONUtils.parse(jobJsonString);
|
||||
JobsBean parsedJobsBean = new JobsBean();
|
||||
parsedJobsBean.restore(parsedJobsJson);
|
||||
MJob retrievedJob1 = parsedJobsBean.getJobs().get(0);
|
||||
|
@ -29,7 +29,6 @@
|
||||
import org.apache.sqoop.model.MStringInput;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestLinkBean {
|
||||
@ -62,7 +61,7 @@ public void testLinkSerialization() {
|
||||
String linkJsonString = json.toJSONString();
|
||||
|
||||
// Retrieved transferred object
|
||||
JSONObject parsedLinkJson = (JSONObject) JSONValue.parse(linkJsonString);
|
||||
JSONObject parsedLinkJson = JSONUtils.parse(linkJsonString);
|
||||
LinkBean retrievedBean = new LinkBean();
|
||||
retrievedBean.restore(parsedLinkJson);
|
||||
MLink retrievedLink = retrievedBean.getLinks().get(0);
|
||||
|
@ -30,7 +30,6 @@
|
||||
import org.apache.sqoop.model.MStringInput;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestLinksBean {
|
||||
@ -70,7 +69,7 @@ public void testLinksSerialization() {
|
||||
String linkJsonString = json.toJSONString();
|
||||
|
||||
// Retrieved transferred object
|
||||
JSONObject parsedLinkJson = (JSONObject) JSONValue.parse(linkJsonString);
|
||||
JSONObject parsedLinkJson = JSONUtils.parse(linkJsonString);
|
||||
LinksBean retrievedBean = new LinksBean();
|
||||
retrievedBean.restore(parsedLinkJson);
|
||||
MLink targetLink1 = retrievedBean.getLinks().get(0);
|
||||
|
@ -20,7 +20,6 @@
|
||||
import org.apache.sqoop.json.util.TestSchemaSerialization;
|
||||
import org.apache.sqoop.schema.Schema;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
/**
|
||||
* Run the same tests as TestSchemaSerialization, but using the SchamaBean
|
||||
@ -41,7 +40,7 @@ protected Schema transfer(Schema schema) {
|
||||
|
||||
String transferredString = extractJson.toJSONString();
|
||||
|
||||
JSONObject restoreJson = (JSONObject) JSONValue.parse(transferredString);
|
||||
JSONObject restoreJson = JSONUtils.parse(transferredString);
|
||||
SchemaBean restoreBean = new SchemaBean();
|
||||
restoreBean.restore(restoreJson);
|
||||
|
||||
|
@ -26,7 +26,6 @@
|
||||
import org.apache.sqoop.submission.counter.CounterGroup;
|
||||
import org.apache.sqoop.submission.counter.Counters;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -460,7 +459,7 @@ private MSubmission transfer(MSubmission submission) {
|
||||
|
||||
String string = json.toString();
|
||||
|
||||
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string);
|
||||
JSONObject retrievedJson = JSONUtils.parse(string);
|
||||
SubmissionsBean retrievedBean = new SubmissionsBean();
|
||||
retrievedBean.restore(retrievedJson);
|
||||
|
||||
@ -479,7 +478,7 @@ private List<MSubmission> transfer(List<MSubmission> submissions) {
|
||||
|
||||
String string = json.toString();
|
||||
|
||||
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string);
|
||||
JSONObject retrievedJson = JSONUtils.parse(string);
|
||||
SubmissionsBean retrievedBean = new SubmissionsBean();
|
||||
retrievedBean.restore(retrievedJson);
|
||||
|
||||
|
@ -20,7 +20,6 @@
|
||||
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.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@ -68,7 +67,7 @@ public Throwable transfer(Throwable source) {
|
||||
String string = json.toJSONString();
|
||||
|
||||
// Retrieved transferred object
|
||||
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string);
|
||||
JSONObject retrievedJson = JSONUtils.parse(string);
|
||||
ThrowableBean retrievedBean = new ThrowableBean();
|
||||
retrievedBean.restore(retrievedJson);
|
||||
return retrievedBean.getThrowable();
|
||||
|
@ -21,7 +21,6 @@
|
||||
import org.apache.sqoop.validation.Status;
|
||||
import org.apache.sqoop.validation.ConfigValidationResult;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.LinkedList;
|
||||
@ -115,7 +114,7 @@ private Long transfer(Long id) {
|
||||
|
||||
String string = json.toString();
|
||||
|
||||
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string);
|
||||
JSONObject retrievedJson = JSONUtils.parse(string);
|
||||
ValidationResultBean retrievedBean = new ValidationResultBean();
|
||||
retrievedBean.restore(retrievedJson);
|
||||
|
||||
@ -128,7 +127,7 @@ private ConfigValidationResult[] transfer(ConfigValidationResult [] results) {
|
||||
|
||||
String string = json.toString();
|
||||
|
||||
JSONObject retrievedJson = (JSONObject) JSONValue.parse(string);
|
||||
JSONObject retrievedJson = JSONUtils.parse(string);
|
||||
ValidationResultBean retrievedBean = new ValidationResultBean();
|
||||
retrievedBean.restore(retrievedJson);
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.sqoop.common.SqoopException;
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.apache.sqoop.model.MBooleanInput;
|
||||
import org.apache.sqoop.model.MConfig;
|
||||
import org.apache.sqoop.model.MConfigType;
|
||||
@ -35,7 +36,6 @@
|
||||
import org.apache.sqoop.model.MMapInput;
|
||||
import org.apache.sqoop.model.MStringInput;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -63,7 +63,7 @@ public void testAllDataTypes() {
|
||||
|
||||
// Exchange the data on string level
|
||||
String serializedJson = jsonObject.toJSONString();
|
||||
JSONObject retrievedJson = (JSONObject) JSONValue.parse(serializedJson);
|
||||
JSONObject retrievedJson = JSONUtils.parse(serializedJson);
|
||||
|
||||
// And retrieve back from JSON representation
|
||||
MConfig retrieved = ConfigInputSerialization.restoreConfig(retrievedJson);
|
||||
@ -90,7 +90,7 @@ public void testMapDataType() {
|
||||
String serializedJson = jsonObject.toJSONString();
|
||||
|
||||
// Deserialize
|
||||
JSONObject retrievedJson = (JSONObject) JSONValue.parse(serializedJson);
|
||||
JSONObject retrievedJson = JSONUtils.parse(serializedJson);
|
||||
MConfig retrieved = ConfigInputSerialization.restoreConfig(retrievedJson);
|
||||
assertEquals(map, retrieved.getMapInput("Map").getValue());
|
||||
}
|
||||
@ -111,7 +111,7 @@ public void testMapDataTypeException() {
|
||||
// Replace map value with a fake string to force exception
|
||||
String badSerializedJson = serializedJson.replace("{\"A\":\"B\"}", "\"nonsensical string\"");
|
||||
System.out.println(badSerializedJson);
|
||||
JSONObject retrievedJson = (JSONObject) JSONValue.parse(badSerializedJson);
|
||||
JSONObject retrievedJson = JSONUtils.parse(badSerializedJson);
|
||||
ConfigInputSerialization.restoreConfig(retrievedJson);
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.apache.sqoop.schema.NullSchema;
|
||||
import org.apache.sqoop.schema.Schema;
|
||||
import org.apache.sqoop.schema.type.Array;
|
||||
@ -40,7 +41,6 @@
|
||||
import org.apache.sqoop.schema.type.Time;
|
||||
import org.apache.sqoop.schema.type.Unknown;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -52,7 +52,7 @@ public class TestSchemaSerialization {
|
||||
public void testSchemaNull() {
|
||||
// a null schema is treated as a NullSchema
|
||||
JSONObject extractJson = SchemaSerialization.extractSchema(null);
|
||||
JSONObject restoreJson = (JSONObject) JSONValue.parse(extractJson.toJSONString());
|
||||
JSONObject restoreJson = JSONUtils.parse(extractJson.toJSONString());
|
||||
assertEquals(NullSchema.getInstance(), SchemaSerialization.restoreSchema(restoreJson));
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ private void transferAndAssert(Schema schema) {
|
||||
protected Schema transfer(Schema schema) {
|
||||
JSONObject extractJson = SchemaSerialization.extractSchema(schema);
|
||||
String transferredString = extractJson.toJSONString();
|
||||
JSONObject restoreJson = (JSONObject) JSONValue.parse(transferredString);
|
||||
JSONObject restoreJson = JSONUtils.parse(transferredString);
|
||||
return SchemaSerialization.restoreSchema(restoreJson);
|
||||
}
|
||||
}
|
||||
|
@ -24,12 +24,12 @@
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.apache.sqoop.common.Direction;
|
||||
import org.apache.sqoop.job.MRJobConstants;
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.apache.sqoop.json.util.SchemaSerialization;
|
||||
import org.apache.sqoop.model.ConfigUtils;
|
||||
import org.apache.sqoop.schema.Schema;
|
||||
import org.apache.sqoop.utils.ClassUtils;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
@ -228,7 +228,7 @@ private static Schema getSchemaFromBytes(byte[] bytes) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONObject jsonSchema = (JSONObject) JSONValue.parse(new String(bytes));
|
||||
JSONObject jsonSchema = JSONUtils.parse(new String(bytes));
|
||||
return SchemaSerialization.restoreSchema(jsonSchema);
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
import org.apache.sqoop.connector.spi.SqoopConnector;
|
||||
import org.apache.sqoop.driver.Driver;
|
||||
import org.apache.sqoop.driver.JobManager;
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.apache.sqoop.json.JobBean;
|
||||
import org.apache.sqoop.json.JobsBean;
|
||||
import org.apache.sqoop.json.JsonBean;
|
||||
@ -51,7 +52,6 @@
|
||||
import org.apache.sqoop.validation.ConfigValidationResult;
|
||||
import org.apache.sqoop.validation.Status;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
public class JobRequestHandler implements RequestHandler {
|
||||
|
||||
@ -156,7 +156,7 @@ private JsonBean createUpdateJob(RequestContext ctx, boolean create) {
|
||||
JobBean bean = new JobBean();
|
||||
|
||||
try {
|
||||
JSONObject json = (JSONObject) JSONValue.parse(ctx.getRequest().getReader());
|
||||
JSONObject json = JSONUtils.parse(ctx.getRequest().getReader());
|
||||
bean.restore(json);
|
||||
} catch (IOException e) {
|
||||
throw new SqoopException(ServerError.SERVER_0003, "Can't read request content", e);
|
||||
|
@ -27,6 +27,7 @@
|
||||
import org.apache.sqoop.common.SqoopException;
|
||||
import org.apache.sqoop.connector.ConnectorManager;
|
||||
import org.apache.sqoop.connector.spi.SqoopConnector;
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.apache.sqoop.json.JsonBean;
|
||||
import org.apache.sqoop.json.LinkBean;
|
||||
import org.apache.sqoop.json.LinksBean;
|
||||
@ -42,7 +43,6 @@
|
||||
import org.apache.sqoop.server.common.ServerError;
|
||||
import org.apache.sqoop.validation.ConfigValidationResult;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
public class LinkRequestHandler implements RequestHandler {
|
||||
|
||||
@ -110,7 +110,7 @@ private JsonBean createUpdateLink(RequestContext ctx, boolean create) {
|
||||
|
||||
LinkBean linkBean = new LinkBean();
|
||||
try {
|
||||
JSONObject postData = (JSONObject) JSONValue.parse(ctx.getRequest().getReader());
|
||||
JSONObject postData = JSONUtils.parse(ctx.getRequest().getReader());
|
||||
linkBean.restore(postData);
|
||||
} catch (IOException e) {
|
||||
throw new SqoopException(ServerError.SERVER_0003, "Can't read request content", e);
|
||||
|
@ -42,6 +42,7 @@
|
||||
import org.apache.sqoop.connector.spi.SqoopConnector;
|
||||
import org.apache.sqoop.driver.Driver;
|
||||
import org.apache.sqoop.driver.DriverUpgrader;
|
||||
import org.apache.sqoop.json.JSONUtils;
|
||||
import org.apache.sqoop.json.JobBean;
|
||||
import org.apache.sqoop.json.LinkBean;
|
||||
import org.apache.sqoop.json.SubmissionBean;
|
||||
@ -66,7 +67,6 @@
|
||||
import org.apache.sqoop.validation.Status;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
InputStream input = new FileInputStream(inputFileName);
|
||||
String jsonTxt = IOUtils.toString(input, Charsets.UTF_8);
|
||||
JSONObject json = (JSONObject) JSONValue.parse(jsonTxt);
|
||||
JSONObject json = JSONUtils.parse(jsonTxt);
|
||||
boolean res = load(json);
|
||||
input.close();
|
||||
return res;
|
||||
|
Loading…
Reference in New Issue
Block a user