Search in sources :

Example 16 with ParseException

use of org.json.simple.parser.ParseException in project OpenGrok by OpenGrok.

the class StatsMessageTest method testGetValidJson.

@Test
public void testGetValidJson() {
    testGet();
    Message m = new StatsMessage();
    m.setText("get");
    byte[] out = null;
    try {
        out = m.apply(env);
    } catch (Exception ex) {
        Assert.fail("Should not throw any exception");
    }
    JSONParser p = new JSONParser();
    Object o = null;
    try {
        o = p.parse(new String(out));
    } catch (ParseException ex) {
        Assert.fail("Should not throw any exception");
    }
    Assert.assertNotNull(o);
    Statistics stat = Statistics.from((JSONObject) o);
    Assert.assertTrue(stat instanceof Statistics);
    Assert.assertEquals(1, stat.getRequests());
    Assert.assertEquals(1, stat.getMinutes());
    Assert.assertEquals(0, stat.getRequestCategories().size());
    Assert.assertEquals(0, stat.getTiming().size());
}
Also used : JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) ParseException(org.json.simple.parser.ParseException) Statistics(org.opensolaris.opengrok.web.Statistics) ParseException(org.json.simple.parser.ParseException) Test(org.junit.Test)

Example 17 with ParseException

use of org.json.simple.parser.ParseException in project OpenGrok by OpenGrok.

the class WebappListener method contextInitialized.

/**
 * {@inheritDoc}
 */
@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
    ServletContext context = servletContextEvent.getServletContext();
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    String config = context.getInitParameter("CONFIGURATION");
    if (config == null) {
        LOGGER.severe("CONFIGURATION section missing in web.xml");
    } else {
        try {
            env.readConfiguration(new File(config));
        } catch (IOException ex) {
            LOGGER.log(Level.WARNING, "OpenGrok Configuration error. Failed to read config file: ", ex);
        }
    }
    /**
     * Create a new instance of authorization framework. If the code above
     * (reading the configuration) failed then the plugin directory is
     * possibly {@code null} causing the framework to allow every request.
     */
    env.setAuthorizationFramework(new AuthorizationFramework(env.getPluginDirectory(), env.getPluginStack()));
    env.getAuthorizationFramework().reload();
    String address = context.getInitParameter("ConfigAddress");
    if (address != null && address.length() > 0) {
        LOGGER.log(Level.CONFIG, "Will listen for configuration on [{0}]", address);
        String[] cfg = address.split(":");
        if (cfg.length == 2) {
            try {
                SocketAddress addr = new InetSocketAddress(InetAddress.getByName(cfg[0]), Integer.parseInt(cfg[1]));
                if (!RuntimeEnvironment.getInstance().startConfigurationListenerThread(addr)) {
                    LOGGER.log(Level.SEVERE, "OpenGrok: Failed to start configuration listener thread");
                }
            } catch (NumberFormatException | UnknownHostException ex) {
                LOGGER.log(Level.SEVERE, "OpenGrok: Failed to start configuration listener thread:", ex);
            }
        } else {
            LOGGER.log(Level.SEVERE, "Incorrect format for the configuration address: ");
            for (int i = 0; i < cfg.length; ++i) {
                LOGGER.log(Level.SEVERE, "[{0}]", cfg[i]);
            }
        }
    }
    try {
        RuntimeEnvironment.getInstance().loadStatistics();
    } catch (IOException ex) {
        LOGGER.log(Level.INFO, "Could not load statistics from a file.", ex);
    } catch (ParseException ex) {
        LOGGER.log(Level.SEVERE, "Could not parse statistics from a file.", ex);
    }
    if (env.getConfiguration().getPluginDirectory() != null && env.isAuthorizationWatchdog()) {
        RuntimeEnvironment.getInstance().startWatchDogService(new File(env.getConfiguration().getPluginDirectory()));
    }
    RuntimeEnvironment.getInstance().startExpirationTimer();
    try {
        RuntimeEnvironment.getInstance().loadStatistics();
    } catch (IOException ex) {
        LOGGER.log(Level.INFO, "Could not load statistics from a file.", ex);
    } catch (ParseException ex) {
        LOGGER.log(Level.SEVERE, "Could not parse statistics from a file.", ex);
    }
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) AuthorizationFramework(org.opensolaris.opengrok.authorization.AuthorizationFramework) ServletContext(javax.servlet.ServletContext) ParseException(org.json.simple.parser.ParseException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) File(java.io.File)

Example 18 with ParseException

use of org.json.simple.parser.ParseException in project scheduling by ow2-proactive.

the class JobKeyValueTransformer method transformVariablesToMap.

public Map<String, String> transformVariablesToMap(String jsonVariables) {
    Map<String, String> jobVariables = Maps.newHashMap();
    if (jsonVariables != null) {
        try {
            jobVariables = (JSONObject) new JSONParser().parse(jsonVariables);
            validateJSONVariables(jobVariables);
        } catch (ParseException | IllegalArgumentException e) {
            throw new CLIException(REASON_INVALID_ARGUMENTS, e.getMessage() + USAGE);
        }
    }
    return jobVariables;
}
Also used : CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Example 19 with ParseException

use of org.json.simple.parser.ParseException in project Rubicon by Rubicon-Bot.

the class MojangUtil method fromName.

public MinecraftPlayer fromName(String name) {
    HashMap<String, Date> history = new HashMap<>();
    try {
        JSONArray data = (JSONArray) new JSONParser().parse(fetchNameHistory(fetchUUID(name)));
        if (data.size() != 0) {
            data.remove(0);
            data.forEach(d -> {
                JSONObject object = (JSONObject) d;
                history.put(object.get("name").toString(), new Date(Long.parseLong(object.get("changedToAt").toString())));
            });
        }
    } catch (ParseException e) {
        Logger.error(e);
    }
    return new MinecraftPlayer(fetchUUID(name), fetchName(name), history, fetchFirstNamme(fetchUUID(name)));
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException) Date(java.util.Date)

Example 20 with ParseException

use of org.json.simple.parser.ParseException in project Rubicon by Rubicon-Bot.

the class MojangUtil method fromUUID.

public MinecraftPlayer fromUUID(String uuid) {
    try {
        JSONArray data = (JSONArray) new JSONParser().parse(fetchNameHistory(uuid));
        String name = ((JSONObject) data.get(data.size() - 1)).get("name").toString();
        return fromName(name);
    } catch (ParseException e) {
        Logger.error(e);
        return null;
    }
}
Also used : JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Aggregations

ParseException (org.json.simple.parser.ParseException)258 JSONObject (org.json.simple.JSONObject)191 JSONParser (org.json.simple.parser.JSONParser)185 JSONArray (org.json.simple.JSONArray)84 IOException (java.io.IOException)71 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)50 HashMap (java.util.HashMap)41 ArrayList (java.util.ArrayList)34 Map (java.util.Map)23 HashSet (java.util.HashSet)18 API (org.wso2.carbon.apimgt.api.model.API)18 BufferedReader (java.io.BufferedReader)13 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)13 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)13 List (java.util.List)12 File (java.io.File)11 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)11 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)11 InputStreamReader (java.io.InputStreamReader)10 URL (java.net.URL)10