Java 类net.sf.json.JSON 实例源码

项目:jmeter-bzm-plugins    文件:BlazeMeterHttpUtils.java   
@Override
protected String extractErrorMessage(String response) {
    if (response != null && !response.isEmpty()) {
        try {
            JSON jsonResponse = JSONSerializer.toJSON(response, new JsonConfig());
            if (jsonResponse instanceof JSONObject) {
                JSONObject object = (JSONObject) jsonResponse;
                JSONObject errorObj = object.getJSONObject("error");
                if (errorObj.containsKey("message")) {
                    return errorObj.getString("message");
                }
            }
        } catch (JSONException ex) {
            log.debug("Cannot parse JSON error response: " + response);
        }
    }
    return response;
}
项目:sonar-quality-gates-plugin    文件:GlobalConfigurationServiceTest.java   
@Test
public void testInstantiateGlobalConfigData() {
    JSONObject json = new JSONObject();
    json.put("listOfGlobalConfigData", JSONArray.fromObject("[{\"name\":\"Sonar\",\"url\":\"http://localhost:9000\",\"account\":\"admin\",\"password\":\"admin\"}]"));
    JSON globalDataConfig = (JSON) json.opt("listOfGlobalConfigData");
    doNothing().when(spyGlobalConfigurationService).initGlobalDataConfig(globalDataConfig);
    assertEquals(listOfGlobalConfigData, spyGlobalConfigurationService.instantiateGlobalConfigData(json));
}
项目:phoenix.interface.framework    文件:SimpleHttpClient.java   
public String executeJsonPost(String url, JSON jsonObj) throws ParseException, IOException
{
    if(url.startsWith("/"))
    {
        url = host + url;
    }

    HttpPost post = new HttpPost(url);

    StringEntity entity = new StringEntity(jsonObj.toString(), HTTP.UTF_8);
    entity.setContentType("application/json");

    post.setEntity(entity);

    return fetchReponseText(post);
}
项目:nbone    文件:JSONXOperUtils.java   
/**
 * 将xml中列表信息转化对象数组
 * 
 * @param xml
 * @param beanClass
 * @return
 */
public static Object[] xml2ArrayForObject(String xml, Class beanClass) {

    // 设置root为数组
    xml = setXmlRootAttrToArray(xml);
    XMLSerializer xmlSer = new XMLSerializer();
    JSON jsonArr = xmlSer.read(xml);
    Object[] objArr = new Object[jsonArr.size()];

    for (int i = 0; i < jsonArr.size(); i++) {
        objArr[i] = JSONObject.toBean(
                ((JSONArray) jsonArr).getJSONObject(i), beanClass);
    }

    return objArr;
}
项目:easyrec_major    文件:AbstractApiTest.java   
public JSONObject makeAPIRequest(String apiFunction, @Nullable MultivaluedMap<String, String> params) {
    ClientResponse clientResponse = makeAPIResource(apiFunction, params).get(ClientResponse.class);

    log.info(clientResponse.getLocation());

    String response = clientResponse.getEntity(String.class);

    System.out.println(response);
    log.info("response: " + response);

    if (!method.equals("json/")) {
        XMLSerializer xmlSerializer = new XMLSerializer();
        JSON json = xmlSerializer.read(response);

        System.out.println(json);

        return JSONObject.fromObject(json);
    } else
        return JSONObject.fromObject(response);
}
项目:Camel    文件:XmlJsonDataFormatTest.java   
@Test
public void testUnmarshalJSONObject() throws Exception {
    InputStream inStream = getClass().getResourceAsStream("testMessage1.json");
    String in = context.getTypeConverter().convertTo(String.class, inStream);
    JSON json = JSONSerializer.toJSON(in);

    MockEndpoint mockXML = getMockEndpoint("mock:xml");
    mockXML.expectedMessageCount(1);
    mockXML.message(0).body().isInstanceOf(String.class);

    Object marshalled = template.requestBody("direct:unmarshal", json);
    Document document = context.getTypeConverter().convertTo(Document.class, marshalled);
    assertEquals("The XML document has an unexpected root node", "o", document.getDocumentElement().getLocalName());

    mockXML.assertIsSatisfied();
}
项目:phabricator-jenkins-plugin    文件:UberallsClient.java   
public CodeCoverageMetrics getParentCoverage(String sha) {
    if (sha == null) {
        return null;
    }
    try {
        String coverageJSON = getCoverage(sha);
        JsonSlurper jsonParser = new JsonSlurper();
        JSON responseJSON = jsonParser.parseText(coverageJSON);
        if (responseJSON instanceof JSONNull) {
            return null;
        }
        JSONObject coverage = (JSONObject) responseJSON;

        return new CodeCoverageMetrics(
                ((Double) coverage.getDouble(PACKAGE_COVERAGE_KEY)).floatValue(),
                ((Double) coverage.getDouble(FILES_COVERAGE_KEY)).floatValue(),
                ((Double) coverage.getDouble(CLASSES_COVERAGE_KEY)).floatValue(),
                ((Double) coverage.getDouble(METHOD_COVERAGE_KEY)).floatValue(),
                ((Double) coverage.getDouble(LINE_COVERAGE_KEY)).floatValue(),
                ((Double) coverage.getDouble(CONDITIONAL_COVERAGE_KEY)).floatValue());
    } catch (Exception e) {
        e.printStackTrace(logger.getStream());
    }

    return null;
}
项目:BotLibre    文件:Http.java   
/**
 * Return the JSON data object from the URL.
 */
public Vertex requestJSON(String url, String attribute, Map<String, String> headers, Network network) {
    log("GET JSON", Level.INFO, url, attribute);
    try {
        String json = Utils.httpGET(url, headers);
        log("JSON", Level.FINE, json);
        JSON root = (JSON)JSONSerializer.toJSON(json.trim());
        if (root == null) {
            return null;
        }
        Object value = root;
        if (attribute != null) {
            value = ((JSONObject)root).get(attribute);
            if (value == null) {
                return null;
            }
        }
        Vertex object = convertElement(value, network);
        return object;
    } catch (Exception exception) {
        log(exception);
        return null;
    }
}
项目:BotLibre    文件:Freebase.java   
/**
 * Process the mql query and convert the result to a JSON object.
 */
public JSON processQuery(String query) throws IOException {
    log("MQL", Level.FINEST, query);
    URL get = null;
    if (KEY.isEmpty()) {
        get = new URL(query);
    } else {
        get = new URL(query + "&key=" + KEY);
    }
    Reader reader = new InputStreamReader(get.openStream(), "UTF-8");
    StringWriter output = new StringWriter();
    int next = reader.read();
    while (next != -1) {
        output.write(next);
        next = reader.read();
    }
    String result = output.toString();
    log("JSON", Level.FINEST, result);
    return JSONSerializer.toJSON(result);
}
项目:BotLibre    文件:Google.java   
public String newAccessToken() {
    try {
        Map<String, String> params = new HashMap<String, String>();
        params.put("refresh_token", this.refreshToken);
        params.put("client_id", CLIENTID);
        params.put("client_secret", CLIENTSECRET);
        //params.put("redirect_uri", "urn:ietf:wg:oauth:2.0:oob");
        params.put("grant_type", "refresh_token");
        String json = Utils.httpPOST("https://accounts.google.com/o/oauth2/token", params);
        JSON root = (JSON)JSONSerializer.toJSON(json);
        if (!(root instanceof JSONObject)) {
            return null;
        }
        return ((JSONObject)root).getString("access_token");
    } catch (Exception exception) {
        log(exception);
        return null;
    }
}
项目:FHIR-Server    文件:JsonParserTest.java   
private void parseAndEncode(String name) throws IOException {
    String msg = IOUtils.toString(XmlParser.class.getResourceAsStream(name));
    ourLog.info(msg);

    IParser p = ourCtx.newJsonParser();
    Profile res = p.parseResource(Profile.class, msg);

    String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(res);
    ourLog.info(encoded);

    JSON expected = JSONSerializer.toJSON(msg.trim());
    JSON actual = JSONSerializer.toJSON(encoded.trim());

    String exp = expected.toString().replace("\\r\\n", "\\n"); // .replace("&sect;", "§");
    String act = actual.toString().replace("\\r\\n", "\\n");

    ourLog.info("Expected: {}", exp);
    ourLog.info("Actual  : {}", act);

    assertEquals(exp, act);
}
项目:FHIR-Server    文件:JsonParserTest.java   
private void parseAndEncode(String name) throws IOException {
    String msg = IOUtils.toString(XmlParser.class.getResourceAsStream(name));
    ourLog.info(msg);

    IParser p = ourCtx.newJsonParser();
    Profile res = p.parseResource(Profile.class, msg);

    String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(res);
    ourLog.info(encoded);

    JSON expected = JSONSerializer.toJSON(msg.trim());
    JSON actual = JSONSerializer.toJSON(encoded.trim());

    String exp = expected.toString().replace("\\r\\n", "\\n"); // .replace("&sect;", "§");
    String act = actual.toString().replace("\\r\\n", "\\n");

    ourLog.info("Expected: {}", exp);
    ourLog.info("Actual  : {}", act);

    assertEquals(exp, act);
}
项目:hapi-fhir    文件:JsonParserTest.java   
private void parseAndEncode(String name) throws IOException {
    String msg = IOUtils.toString(XmlParser.class.getResourceAsStream(name), StandardCharsets.UTF_8);
    // ourLog.info(msg);

    msg = msg.replace("\"div\": \"<div>", "\"div\":\"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">");

    IParser p = ourCtx.newJsonParser();
    Profile res = p.parseResource(Profile.class, msg);

    String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(res);
    // ourLog.info(encoded);

    JSON expected = JSONSerializer.toJSON(msg.trim());
    JSON actual = JSONSerializer.toJSON(encoded.trim());

    String exp = expected.toString().replace("\\r\\n", "\\n"); // .replace("&sect;", "§");
    String act = actual.toString().replace("\\r\\n", "\\n");

    ourLog.info("Expected: {}", exp);
    ourLog.info("Actual  : {}", act);

    assertEquals(exp, act);
}
项目:easyrec-PoC    文件:AbstractApiTest.java   
public JSONObject makeAPIRequest(String apiFunction, @Nullable MultivaluedMap<String, String> params) {
    ClientResponse clientResponse = makeAPIResource(apiFunction, params).get(ClientResponse.class);

    log.info(clientResponse.getLocation());

    String response = clientResponse.getEntity(String.class);

    System.out.println(response);
    log.info("response: " + response);

    if (!method.equals("json/")) {
        XMLSerializer xmlSerializer = new XMLSerializer();
        JSON json = xmlSerializer.read(response);

        System.out.println(json);

        return JSONObject.fromObject(json);
    } else
        return JSONObject.fromObject(response);
}
项目:pdi-plugin-parsejsonstring    文件:ParseJsonString.java   
private Object[] addRowData(Object[] r) throws KettleException
{
    // Parsing field
    final JSON json                 = JSONSerializer.toJSON(r[data.fieldPos].toString());
    final JXPathContext context     = JXPathContext.newContext(json);
    final String[] fieldNames       = meta.getFieldName();
    final RowMetaInterface rowMeta  = data.outputRowMeta;

    // Parsing each path into otuput rows
    for (int i = 0; i < fieldNames.length; i++) {
        final String fieldPath                   = meta.getXPath()[i];
        final String fieldName                   = meta.getFieldName()[i];
        final Object fieldValue                  = context.getValue(fieldPath);
        final Integer fieldIndex                 = rowMeta.indexOfValue(fieldNames[i]);
        final ValueMetaInterface valueMeta       = rowMeta.getValueMeta(fieldIndex);
        final DateFormat df                      = (valueMeta.getType() == ValueMetaInterface.TYPE_DATE) 
            ? new SimpleDateFormat(meta.getFieldFormat()[i])
            : null;

        // safely add the unique field at the end of the output row
        r = RowDataUtil.addValueData(r, fieldIndex, getRowDataValue(fieldName, valueMeta, valueMeta, fieldValue, df));
    }

    return r;
}
项目:easyrec    文件:AbstractApiTest.java   
public JSONObject makeAPIRequest(String apiFunction, @Nullable MultivaluedMap<String, String> params) {
    ClientResponse clientResponse = makeAPIResource(apiFunction, params).get(ClientResponse.class);

    log.info(clientResponse.getLocation());

    String response = clientResponse.getEntity(String.class);

    System.out.println(response);
    log.info("response: " + response);

    if (!method.equals("json/")) {
        XMLSerializer xmlSerializer = new XMLSerializer();
        JSON json = xmlSerializer.read(response);

        System.out.println(json);

        return JSONObject.fromObject(json);
    } else
        return JSONObject.fromObject(response);
}
项目:ccr-parameter-plugin    文件:CacheManager.java   
/**
 * Parses raw JSON data and returns the found strings.
 *
 * @param jsonName Name of attribute which is needed.
 * @param data Contains raw JSON data.
 * @return List of strings which were found by jsonName.
 */
private List<String> parseListFromData(String jsonName, String data) {
    final List<String> result = new ArrayList<String>();
    final JSON json = JSONSerializer.toJSON(data);
    final Object jsonObject = ((JSONObject)json).get(jsonName);

    if (JSONUtils.isArray(jsonObject)) {
        Collection<String> jsonPaths = JSONArray.toCollection((JSONArray)jsonObject, String.class);
        for (String jsonPath : jsonPaths) {
            result.add(trimJSONPath(jsonPath));
        }
    } else {
        result.add(trimJSONPath(String.valueOf(jsonObject)));
    }
    return result;
}
项目:ccr-parameter-plugin    文件:CCRUtils.java   
/**
 * Returns the value of a key from a given JSON String.
 *
 * @param key Key to search after.
 * @param jsonString Given JSON String, in which the key should be in.
 * @return The value of the key in the JSON string.
 */
public static ArrayList<String> getValueFromJSONString(String key, String jsonString) {
    final ArrayList<String> result = new ArrayList<String>();
    LOG.info("JSON STRING: " + jsonString);
    final JSON json = JSONSerializer.toJSON(jsonString);
    final Object jsonObject = ((JSONObject)json).get(key);

    if (JSONUtils.isArray(jsonObject)) {
        Collection<String> jsonPaths = JSONArray.toCollection((JSONArray)jsonObject, String.class);
        for (String jsonPath : jsonPaths) {
            result.add(trimJSONSlashes(jsonPath));
        }
    } else {
        if (!String.valueOf(jsonObject).equals("null")) {
            result.add(CCRUtils.trimJSONSlashes(String.valueOf(jsonObject)));
        }
    }
    return result;
}
项目:jira-client    文件:CustomFieldOption.java   
/**
 * Retrieves the given custom field option record.
 *
 * @param restclient REST client instance
 * @param id Internal JIRA ID of the custom field option
 *
 * @return a custom field option instance
 *
 * @throws JiraException when the retrieval fails
 */
public static CustomFieldOption get(RestClient restclient, String id)
    throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getBaseUri() + "customFieldOption/" + id);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve custom field option " + id, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new CustomFieldOption(restclient, (JSONObject)result);
}
项目:jira-client    文件:IssueType.java   
/**
 * Retrieves the given issue type record.
 *
 * @param restclient REST client instance
 * @param id Internal JIRA ID of the issue type
 *
 * @return an issue type instance
 *
 * @throws JiraException when the retrieval fails
 */
public static IssueType get(RestClient restclient, String id)
    throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getBaseUri() + "issuetype/" + id);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve issue type " + id, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new IssueType(restclient, (JSONObject)result);
}
项目:jira-client    文件:Security.java   
/**
 * Retrieves the given security record.
 *
 * @param restclient REST client instance
 * @param id Internal JIRA ID of the security
 *
 * @return a security instance
 *
 * @throws JiraException when the retrieval fails
 */
public static Security get(RestClient restclient, String id)
    throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getBaseUri() + "securitylevel/" + id);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve security " + id, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new Security(restclient, (JSONObject)result);
}
项目:jira-client    文件:WorkLog.java   
/**
 * Retrieves the given work log record.
 *
 * @param restclient REST client instance
 * @param issue Internal JIRA ID of the associated issue
 * @param id Internal JIRA ID of the work log
 *
 * @return a work log instance
 *
 * @throws JiraException when the retrieval fails
 */
public static WorkLog get(RestClient restclient, String issue, String id)
    throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getBaseUri() + "issue/" + issue + "/worklog/" + id);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve work log " + id + " on issue " + issue, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new WorkLog(restclient, (JSONObject)result);
}
项目:jira-client    文件:Filter.java   
public static Filter get(final RestClient restclient, final String id) throws JiraException {
    JSON result = null;

    try {
        URI uri = restclient.buildURI(getBaseUri() + "filter/" + id);
        result = restclient.get(uri);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve filter with id " + id, ex);
    }

    if (!(result instanceof JSONObject)) {
        throw new JiraException("JSON payload is malformed");
    }

    return new Filter(restclient, (JSONObject) result);
}
项目:jira-client    文件:Resolution.java   
/**
 * Retrieves the given resolution record.
 *
 * @param restclient REST client instance
 * @param id Internal JIRA ID of the resolution
 *
 * @return a resolution instance
 *
 * @throws JiraException when the retrieval fails
 */
public static Resolution get(RestClient restclient, String id)
    throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getBaseUri() + "resolution/" + id);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve resolution " + id, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new Resolution(restclient, (JSONObject)result);
}
项目:jira-client    文件:Version.java   
/**
 * Executes the create action.
 * @return the created Version
 *
 * @throws JiraException when the create fails
 */
public Version execute() throws JiraException {
    JSON result = null;

    try {
        result = restclient.post(getRestUri(null), req);
    } catch (Exception ex) {
        throw new JiraException("Failed to create version", ex);
    }

    if (!(result instanceof JSONObject) || !((JSONObject) result).containsKey("id")
            || !(((JSONObject) result).get("id") instanceof String)) {
        throw new JiraException("Unexpected result on create version");
    }

    return new Version(restclient, (JSONObject) result);
}
项目:jira-client    文件:Version.java   
/**
 * Retrieves the given version record.
 *
 * @param restclient REST client instance
 * @param id         Internal JIRA ID of the version
 * @return a version instance
 * @throws JiraException when the retrieval fails
 */
public static Version get(RestClient restclient, String id)
        throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getBaseUri() + "version/" + id);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve version " + id, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new Version(restclient, (JSONObject) result);
}
项目:jira-client    文件:LinkType.java   
/**
 * Retrieves the given issue link type record.
 *
 * @param restclient REST client instance
 * @param id Internal JIRA ID of the issue link type
 *
 * @return a issue link type instance
 *
 * @throws JiraException when the retrieval fails
 */
public static LinkType get(RestClient restclient, String id)
    throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getBaseUri() + "issueLinkType/" + id);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve issue link type " + id, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new LinkType(restclient, (JSONObject)result);
}
项目:jira-client    文件:Component.java   
/**
 * Executes the create action.
 * @return the created component
 *
 * @throws JiraException when the create fails
 */
public Component execute() throws JiraException {
    JSON result = null;

    try {
        result = restclient.post(getRestUri(null), req);
    } catch (Exception ex) {
        throw new JiraException("Failed to create issue", ex);
    }

    if (!(result instanceof JSONObject) || !((JSONObject) result).containsKey("id")
            || !(((JSONObject) result).get("id") instanceof String)) {
        throw new JiraException("Unexpected result on create component");
    }

    return new Component(restclient, (JSONObject) result);
}
项目:jira-client    文件:Component.java   
/**
 * Retrieves the given component record.
 *
 * @param restclient REST client instance
 * @param id Internal JIRA ID of the component
 *
 * @return a component instance
 *
 * @throws JiraException when the retrieval fails
 */
public static Component get(RestClient restclient, String id)
    throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getRestUri(id));
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve component " + id, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new Component(restclient, (JSONObject)result);
}
项目:jira-client    文件:IssueLink.java   
/**
 * Retrieves the given issue link record.
 *
 * @param restclient REST client instance
 * @param id Internal JIRA ID of the issue link
 *
 * @return a issue link instance
 *
 * @throws JiraException when the retrieval fails
 */
public static IssueLink get(RestClient restclient, String id)
    throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getBaseUri() + "issueLink/" + id);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve issue link " + id, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new IssueLink(restclient, (JSONObject)result);
}
项目:jira-client    文件:AgileResource.java   
/**
 * Retrieves all boards visible to the session user.
 *
 * @param restclient REST client instance
 * @param type       The type of the object to deserialize.
 * @param url        The URL to call.
 * @param listName   The name of the list of items in the JSON response.
 * @return a list of boards
 * @throws JiraException when the retrieval fails
 */
static <T extends AgileResource> List<T> list(
        RestClient restclient, Class<T> type, String url, String listName) throws JiraException {

    JSON result;
    try {
        result = restclient.get(url);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve a list of " + type.getSimpleName() + " : " + url, ex);
    }

    return getResourceArray(
            type,
            result,
            restclient,
            listName
    );
}
项目:jira-client    文件:AgileResource.java   
/**
 * Retrieves all boards visible to the session user.
 *
 * @param restclient REST client instance
 * @return a list of boards
 * @throws JiraException when the retrieval fails
 */
static <T extends AgileResource> T get(RestClient restclient, Class<T> type, String url) throws JiraException {

    JSON result;
    try {
        result = restclient.get(url);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve " + type.getSimpleName() + " : " + url, ex);
    }

    return getResource(
            type,
            result,
            restclient
    );
}
项目:jira-client    文件:Votes.java   
/**
 * Retrieves the given votes record.
 *
 * @param restclient REST client instance
 * @param issue Internal JIRA ID of the issue
 *
 * @return a votes instance
 *
 * @throws JiraException when the retrieval fails
 */
public static Votes get(RestClient restclient, String issue)
    throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getBaseUri() + "issue/" + issue + "/votes");
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve votes for issue " + issue, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new Votes(restclient, (JSONObject)result);
}
项目:jira-client    文件:Priority.java   
/**
 * Retrieves the given priority record.
 *
 * @param restclient REST client instance
 * @param id Internal JIRA ID of the priority
 *
 * @return a priority instance
 *
 * @throws JiraException when the retrieval fails
 */
public static Priority get(RestClient restclient, String id)
    throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getBaseUri() + "priority/" + id);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve priority " + id, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new Priority(restclient, (JSONObject)result);
}
项目:jira-client    文件:Project.java   
/**
 * Retrieves the given project record.
 *
 * @param restclient REST client instance
 * @param key Project key
 *
 * @return a project instance
 *
 * @throws JiraException when the retrieval fails
 */
public static Project get(RestClient restclient, String key)
    throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getBaseUri() + "project/" + key);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve project " + key, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new Project(restclient, (JSONObject)result);
}
项目:jira-client    文件:Project.java   
public List<User> getAssignableUsers() throws JiraException {
    JSON result = null;

    try {           
        Map<String, String> queryParams = new HashMap<String, String>();
        queryParams.put("project", this.key);
        URI searchUri = restclient.buildURI(getBaseUri() + "user/assignable/search", queryParams);
        result = restclient.get(searchUri);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve assignable users", ex);
    }

    if (!(result instanceof JSONArray))
        throw new JiraException("JSON payload is malformed");

    return Field.getResourceArray(User.class, result, restclient);
}
项目:jira-client    文件:TokenCredentials.java   
public void initialize(RestClient client) throws JiraException {
    if (token==null) {
        try {
            JSONObject req = new JSONObject();
            req.put("username", username);
            req.put("password", password);
            JSON json = client.post(Resource.getAuthUri() + "session", req);
            if (json instanceof JSONObject) {
             JSONObject jso = (JSONObject) json;
             jso = (JSONObject) jso.get("session");
             cookieName = (String)jso.get("name");
             token = (String)jso.get("value");

            }
        } catch (Exception ex) {
            throw new JiraException("Failed to login", ex);
        }
    }
}
项目:jira-client    文件:ProjectCategory.java   
/**
 * Retrieves the given status record.
 *
 * @param restclient REST client instance
 * @param id Internal JIRA ID of the status
 *
 * @return a status instance
 *
 * @throws JiraException when the retrieval fails
 */
public static ProjectCategory get(RestClient restclient, String id)
        throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getBaseUri() + "projectCategory/" + id);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve status " + id, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new ProjectCategory(restclient, (JSONObject)result);
}
项目:jira-client    文件:Status.java   
/**
 * Retrieves the given status record.
 *
 * @param restclient REST client instance
 * @param id Internal JIRA ID of the status
 *
 * @return a status instance
 *
 * @throws JiraException when the retrieval fails
 */
public static Status get(RestClient restclient, String id)
    throws JiraException {

    JSON result = null;

    try {
        result = restclient.get(getBaseUri() + "status/" + id);
    } catch (Exception ex) {
        throw new JiraException("Failed to retrieve status " + id, ex);
    }

    if (!(result instanceof JSONObject))
        throw new JiraException("JSON payload is malformed");

    return new Status(restclient, (JSONObject)result);
}
项目:jira-client    文件:Issue.java   
/**
 * count issues with the given query.
 *
 * @param restclient REST client instance
 *
 * @param jql JQL statement
 *
 * @return the count
 *
 * @throws JiraException when the search fails
 */
public static int count(RestClient restclient, String jql) throws JiraException {
    final String j = jql;
    JSON result = null;
    try {
        Map<String, String> queryParams = new HashMap<String, String>();
        queryParams.put("jql", j);
        queryParams.put("maxResults", "1");
        URI searchUri = restclient.buildURI(getBaseUri() + "search", queryParams);
        result = restclient.get(searchUri);
    } catch (Exception ex) {
        throw new JiraException("Failed to search issues", ex);
    }

    if (!(result instanceof JSONObject)) {
        throw new JiraException("JSON payload is malformed");
    }
    Map map = (Map) result;
    return Field.getInteger(map.get("total"));
}