use of org.json.simple.parser.ParseException in project tika by apache.
the class DL4JInceptionV3Net method initialize.
@Override
public void initialize(Map<String, Param> params) throws TikaConfigException {
//STEP 1: resolve weights file, download if necessary
if (modelWeightsPath.startsWith("http://") || modelWeightsPath.startsWith("https://")) {
LOG.debug("Config instructed to download the weights file, doing so.");
try {
modelWeightsPath = cachedDownload(cacheDir, URI.create(modelWeightsPath)).getAbsolutePath();
} catch (IOException e) {
throw new TikaConfigException(e.getMessage(), e);
}
} else {
File modelFile = retrieveFile(modelWeightsPath);
if (!modelFile.exists()) {
LOG.error("modelWeights does not exist at :: {}", modelWeightsPath);
return;
}
modelWeightsPath = modelFile.getAbsolutePath();
}
//STEP 2: resolve model JSON
File modelJsonFile = retrieveFile(modelJsonPath);
if (modelJsonFile == null || !modelJsonFile.exists()) {
LOG.error("Could not locate file {}", modelJsonPath);
return;
}
modelJsonPath = modelJsonFile.getAbsolutePath();
//STEP 3: Load labels map
try (InputStream stream = retrieveResource(labelFile)) {
this.labelMap = loadClassIndex(stream);
} catch (IOException | ParseException e) {
LOG.error("Could not load labels map", e);
return;
}
//STEP 4: initialize the graph
try {
this.imageLoader = new NativeImageLoader(imgHeight, imgWidth, imgChannels);
LOG.info("Going to load Inception network...");
long st = System.currentTimeMillis();
this.graph = KerasModelImport.importKerasModelAndWeights(modelJsonPath, modelWeightsPath, false);
long time = System.currentTimeMillis() - st;
LOG.info("Loaded the Inception model. Time taken={}ms", time);
} catch (IOException | InvalidKerasConfigurationException | UnsupportedKerasConfigurationException e) {
throw new TikaConfigException(e.getMessage(), e);
}
}
use of org.json.simple.parser.ParseException in project elastic-core-maven by OrdinaryDude.
the class PeerServlet method process.
/**
* Process the peer request
*
* @param peer Peer
* @param inputReader Input reader
* @return JSON response
*/
private JSONStreamAware process(PeerImpl peer, Reader inputReader) {
//
if (peer.isBlacklisted()) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("error", Errors.BLACKLISTED);
jsonObject.put("cause", peer.getBlacklistingCause());
return jsonObject;
}
Peers.addPeer(peer);
//
try (CountingInputReader cr = new CountingInputReader(inputReader, Peers.MAX_REQUEST_SIZE)) {
JSONObject request = (JSONObject) JSONValue.parseWithException(cr);
peer.updateDownloadedVolume(cr.getCount());
if (request.get("protocol") == null || ((Number) request.get("protocol")).intValue() != 1) {
Logger.logDebugMessage("Unsupported protocol " + request.get("protocol"));
return UNSUPPORTED_PROTOCOL;
}
PeerRequestHandler peerRequestHandler = peerRequestHandlers.get((String) request.get("requestType"));
if (peerRequestHandler == null) {
return UNSUPPORTED_REQUEST_TYPE;
}
if (peer.getState() == Peer.State.DISCONNECTED) {
peer.setState(Peer.State.CONNECTED);
}
if (peer.getVersion() == null && !"getInfo".equals(request.get("requestType"))) {
return SEQUENCE_ERROR;
}
if (!peer.isInbound()) {
if (Peers.hasTooManyInboundPeers()) {
return MAX_INBOUND_CONNECTIONS;
}
Peers.notifyListeners(peer, Peers.Event.ADD_INBOUND);
}
peer.setLastInboundRequest(Nxt.getEpochTime());
if (peerRequestHandler.rejectWhileDownloading()) {
if (blockchainProcessor.isDownloading()) {
return DOWNLOADING;
}
if (Constants.isLightClient) {
return LIGHT_CLIENT;
}
}
return peerRequestHandler.processRequest(request, peer);
} catch (RuntimeException | ParseException | IOException e) {
Logger.logDebugMessage("Error processing POST request: " + e.toString());
peer.blacklist(e);
return error(e);
}
}
use of org.json.simple.parser.ParseException in project elastic-core-maven by OrdinaryDude.
the class ParameterParser method parseTransaction.
public static Transaction.Builder parseTransaction(String transactionJSON, String transactionBytes, String prunableAttachmentJSON) throws ParameterException {
if (transactionBytes == null && transactionJSON == null) {
throw new ParameterException(MISSING_TRANSACTION_BYTES_OR_JSON);
}
if (transactionBytes != null && transactionJSON != null) {
throw new ParameterException(either("transactionBytes", "transactionJSON"));
}
if (prunableAttachmentJSON != null && transactionBytes == null) {
throw new ParameterException(JSONResponses.missing("transactionBytes"));
}
if (transactionJSON != null) {
try {
JSONObject json = (JSONObject) JSONValue.parseWithException(transactionJSON);
return Nxt.newTransactionBuilder(json);
} catch (NxtException.ValidationException | RuntimeException | ParseException e) {
Logger.logDebugMessage(e.getMessage(), e);
JSONObject response = new JSONObject();
JSONData.putException(response, e, "Incorrect transactionJSON");
throw new ParameterException(response);
}
} else {
try {
byte[] bytes = Convert.parseHexString(transactionBytes);
JSONObject prunableAttachments = prunableAttachmentJSON == null ? null : (JSONObject) JSONValue.parseWithException(prunableAttachmentJSON);
return Nxt.newTransactionBuilder(bytes, prunableAttachments);
} catch (NxtException.ValidationException | RuntimeException | ParseException e) {
Logger.logDebugMessage(e.getMessage(), e);
JSONObject response = new JSONObject();
JSONData.putException(response, e, "Incorrect transactionBytes");
throw new ParameterException(response);
}
}
}
use of org.json.simple.parser.ParseException in project stocator by SparkTC.
the class PasswordScopeAccessProvider method authenticate.
/**
* Authentication logic
*
* @return Access JOSS access object
*/
@Override
public Access authenticate() {
try {
JSONObject user = new JSONObject();
user.put("id", mUserId);
user.put("password", mPassword);
JSONObject password = new JSONObject();
password.put("user", user);
JSONArray methods = new JSONArray();
methods.add("password");
JSONObject identity = new JSONObject();
identity.put("methods", methods);
identity.put("password", password);
JSONObject project = new JSONObject();
project.put("id", mProjectId);
JSONObject scope = new JSONObject();
scope.put("project", project);
JSONObject auth = new JSONObject();
auth.put("identity", identity);
auth.put("scope", scope);
JSONObject requestBody = new JSONObject();
requestBody.put("auth", auth);
HttpURLConnection connection = (HttpURLConnection) new URL(mAuthUrl).openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json");
OutputStream output = connection.getOutputStream();
output.write(requestBody.toString().getBytes());
HttpStatusChecker.verifyCode(STATUS_CHECKERS, connection.getResponseCode());
final String res;
try (final BufferedReader bufReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
res = bufReader.readLine();
}
JSONParser parser = new JSONParser();
JSONObject jsonResponse = (JSONObject) parser.parse(res);
String token = connection.getHeaderField("X-Subject-Token");
PasswordScopeAccess access = new PasswordScopeAccess(jsonResponse, token, mPrefferedRegion);
connection.disconnect();
return access;
} catch (IOException | ParseException e) {
LOG.error(e.getMessage());
throw new CommandException("Unable to execute the HTTP call or to convert the HTTP Response", e);
}
}
use of org.json.simple.parser.ParseException in project metron by apache.
the class JoinBoltTest method parseMessages.
@Before
public void parseMessages() {
JSONParser parser = new JSONParser();
try {
joinedMessage = (JSONObject) parser.parse(joinedMessageString);
} catch (ParseException e) {
e.printStackTrace();
}
joinBolt = new StandAloneJoinBolt("zookeeperUrl");
joinBolt.setCuratorFramework(client);
joinBolt.setZKCache(cache);
}
Aggregations