当前位置: 首页>>代码示例>>Java>>正文


Java JsonException类代码示例

本文整理汇总了Java中com.ibm.commons.util.io.json.JsonException的典型用法代码示例。如果您正苦于以下问题:Java JsonException类的具体用法?Java JsonException怎么用?Java JsonException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JsonException类属于com.ibm.commons.util.io.json包,在下文中一共展示了JsonException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: put

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
/**
 * Send PUT request with authorization header
 * @param url - The url of the POST request
 * @param auth - String for authorization header
 * @param putData - The body of the PUT
 */
public Response put(String url, String auth, JsonJavaObject putData) throws URISyntaxException, IOException, JsonException {
	URI normUri = new URI(url).normalize();
	Request putRequest = Request.Put(normUri);
	
	//Add auth header
	if(StringUtil.isNotEmpty(auth)) {
		putRequest.addHeader("Authorization", auth);
	}
	
	//Add put data
	String putDataString = JsonGenerator.toJson(JsonJavaFactory.instanceEx, putData);
	if(putData != null) {
		putRequest = putRequest.bodyString(putDataString, ContentType.APPLICATION_JSON);
	}
	
	Response response = executor.execute(putRequest);
	return response;
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:25,代码来源:RestUtil.java

示例2: initDefaultDatabase

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
/**
 * Create the database, a view and one document
 */
public String initDefaultDatabase() throws ClientProtocolException, IOException, URISyntaxException, JsonException{
	int dbCreation = createDefaultDatabase();

	if(dbCreation == 201 || dbCreation == 202 || dbCreation == 412) {
		int viewCreation = createDefaultView();
		if(viewCreation == 201 || viewCreation == 409) {
			List<JsonJavaObject> rows = getView("booklist", "documents", "all");
			
			if(null == rows || rows.size() < 2) {
				//XSPContext context = XSPContext.getXSPContext(FacesContext.getCurrentInstance());
				//String filePath = context.getUrl().getAddress().replace("cloudant.xsp", "") + "catcherintherye.jpg";
				//String contentType = "image/jpeg";
				insertDoc("booklist", "Catcher in the Rye", "J.D. Salinger", false);
			}
			return "success";
		}
	}else if(dbCreation == 403){
		return "invalid database name";
	}
	return "unknown error";
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:25,代码来源:Cloudant.java

示例3: getVisualRecog

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
public ArrayList<String[]> getVisualRecog(String imageUrl) throws JsonException, URISyntaxException, IOException {
	String apiKey = bluemixUtil.getApiKey();
	
	String getUrl = bluemixUtil.getBaseUrl().replace("https:", "http:") + CLASSIFY_API + "?url=" + imageUrl + "&api_key=" + apiKey + "&version=" + VERSION;
	Response response = rest.get(getUrl);
	
	//Convert the response into JSON data
	String content = EntityUtils.toString(response.returnResponse().getEntity());
	JsonJavaObject jsonData = rest.parse(content);
	
	//Retrieve the list of highest matching classifiers and associated confidences
	ArrayList<String[]> tags = getSuggestedTags(jsonData);
	if(tags != null && tags.size() > 0) {
		return tags;
	}
	return null;
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:18,代码来源:ImageRecognition.java

示例4: post

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
/**
 * Send POST request with authorization header and additional headers
 * @param url - The url of the POST request
 * @param auth - String for authorization header
 * @param headers - Hashmap of headers to add to the request
 * @param postData - The body of the POST
 * @return the Response to the POST request
 */
public Response post(String url, String auth, HashMap<String, String> headers, JsonJavaObject postData) throws JsonException, IOException, URISyntaxException {
	URI normUri = new URI(url).normalize();
	Request postRequest = Request.Post(normUri);
	
	//Add all headers
	if(StringUtil.isNotEmpty(auth)) {
		postRequest.addHeader("Authorization", auth);
	}
	if(headers != null && headers.size() > 0){
		for (Map.Entry<String, String> entry : headers.entrySet()) {
			postRequest.addHeader(entry.getKey(), entry.getValue());
		}
	}

	String postDataString = JsonGenerator.toJson(JsonJavaFactory.instanceEx, postData);
	Response response = executor.execute(postRequest.bodyString(postDataString, ContentType.APPLICATION_JSON));
	return response;
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:27,代码来源:RestUtil.java

示例5: createDocument

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
protected void createDocument(RestViewNavigator viewNav, RestDocumentNavigator docNav, JsonJavaObject items) throws ServiceException, JsonException, IOException {
    if(!queryNewDocument()) {
        throw new ServiceException(null, msgErrorCreatingDocument());
    }
    docNav.createDocument();
    Document doc = docNav.getDocument();
    postNewDocument(doc);
    try {
        updateFields(viewNav, docNav, items);
        String form = getParameters().getFormName();
        if (StringUtil.isNotEmpty(form)) {
            docNav.replaceItemValue(ITEM_FORM, form);
        }           
        if (getParameters().isComputeWithForm()) {
            docNav.computeWithForm();
        }
        if(!querySaveDocument(doc)) {
            throw new ServiceException(null, msgErrorCreatingDocument());
        }
        docNav.save();
        postSaveDocument(doc);
        getHttpResponse().setStatus(RSRC_CREATED.httpStatusCode);
    } finally {
        docNav.recycle(); 
    }
}
 
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:27,代码来源:RestViewItemFileService.java

示例6: updateDocument

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
protected void updateDocument(RestViewNavigator viewNav, RestDocumentNavigator docNav, String id, JsonJavaObject items) throws ServiceException, JsonException, IOException {
    if(!queryOpenDocument(id)) {
        throw new ServiceException(null, msgErrorUpdatingData());
    }
    docNav.openDocument(id);
    Document doc = docNav.getDocument();
    postOpenDocument(doc);
    try {
        updateFields(viewNav, docNav, items);
        if (getParameters().isComputeWithForm()) {
            docNav.computeWithForm();
        }           
        if(!querySaveDocument(doc)) {
            throw new ServiceException(null, msgErrorUpdatingData());
        }
        docNav.save();
        postSaveDocument(doc);
    } finally {
        docNav.recycle();
    }
}
 
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:22,代码来源:RestViewItemFileService.java

示例7: updateDocument

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
protected void updateDocument(RestViewNavigator viewNav, RestDocumentNavigator docNav, String id, JsonJavaObject items) throws ServiceException, JsonException, IOException {
    if(!queryOpenDocument(id)) {
        throw new ServiceException(null, msgErrorUpdatingData());
    }
    docNav.openDocument(id);
    Document doc = docNav.getDocument();
    postOpenDocument(doc);
    JsonViewEntryCollectionContent content = factory.createViewEntryCollectionContent(view, this);
    content.updateFields(viewNav, docNav, items);
    if (getParameters().isComputeWithForm()) {
        docNav.computeWithForm();
    }           
    if(!querySaveDocument(doc)) {
        throw new ServiceException(null, msgErrorUpdatingData());
    }
    docNav.save();
    postSaveDocument(doc);
}
 
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:19,代码来源:RestViewJsonService.java

示例8: CouchbaseViewEntry

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
protected CouchbaseViewEntry(final ViewRow row) throws JsonException {
	String bbox = null;
	String geometry = null;
	try {
		bbox = row.getBbox();
		geometry = row.getGeometry();
	} catch (UnsupportedOperationException uoe) {
	}
	bbox_ = bbox;
	geometry_ = geometry;
	id_ = row.getId();
	key_ = row.getKey();
	value_ = row.getValue();

	Object docObject = row.getDocument();
	if (docObject != null) {
		String json = (String) docObject;
		JsonJavaObject doc = (JsonJavaObject) JsonParser.fromJson(JsonJavaFactory.instanceEx, json);
		data_ = Collections.unmodifiableMap(new HashMap<String, Object>(doc));
	} else {
		data_ = null;
	}
}
 
开发者ID:jesse-gallagher,项目名称:Couchbase-Data-for-XPages,代码行数:24,代码来源:CouchbaseView.java

示例9: CouchbaseViewEntry

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected CouchbaseViewEntry(final ViewRow row) throws JsonException {
	String bbox = null;
	String geometry = null;
	try {
		bbox = row.getBbox();
		geometry = row.getGeometry();
	} catch (UnsupportedOperationException uoe) {
	}
	bbox_ = bbox;
	geometry_ = geometry;
	id_ = row.getId();
	key_ = row.getKey();
	value_ = row.getValue();

	Object docObject = row.getDocument();
	if (docObject != null) {
		String json = (String) docObject;
		JsonJavaObject doc = (JsonJavaObject) JsonParser.fromJson(JsonJavaFactory.instanceEx, json);
		data_ = Collections.unmodifiableMap(new HashMap<String, Object>((Map<String, Object>) doc));
	} else {
		data_ = null;
	}
}
 
开发者ID:jesse-gallagher,项目名称:Couchbase-Data-for-XPages,代码行数:25,代码来源:CouchbaseView.java

示例10: iterateArrayValues

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Iterator<Object> iterateArrayValues(Object paramObject) throws JsonException {
	// System.out.println("TEMP DEBUG iterating array values from a " +
	// paramObject.getClass().getName());
	// if (paramObject.getClass().isArray()) {
	// Object[] a = ((Object[]) paramObject);
	// System.out.println("TEMP DEBUG array is length: " + a.length);
	// }
	if (paramObject instanceof List) {
		return super.iterateArrayValues(paramObject);
	} else if (paramObject instanceof Collection) {
		return ((Collection) paramObject).iterator();
	}
	return super.iterateArrayValues(paramObject);
}
 
开发者ID:OpenNTF,项目名称:org.openntf.domino,代码行数:17,代码来源:JsonGraphFactory.java

示例11: outException

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
public void outException(Throwable throwable) throws IOException, JsonException {
	Map<String, Object> result = new LinkedHashMap<String, Object>();
	result.put("currentUsername",
			org.openntf.domino.utils.Factory.getSession(SessionType.CURRENT).getEffectiveUserName());
	result.put("exceptionType", throwable.getClass().getSimpleName());
	result.put("message", throwable.getMessage());
	StackTraceElement[] trace = throwable.getStackTrace();
	StringBuilder sb = new StringBuilder();
	int elemCount = 0;
	for (StackTraceElement elem : trace) {
		if (++elemCount > 15) {
			sb.append("...more");
			break;
		}
		sb.append("  at ");
		sb.append(elem.getClassName());
		sb.append("." + elem.getMethodName());
		sb.append("(" + elem.getFileName() + ":" + elem.getLineNumber() + ")");
		sb.append(System.getProperty("line.separator"));
	}
	result.put("stacktrace", sb.toString());
	if (throwable.getCause() != null) {
		result.put("causedby", throwable.getCause());
	}
	outObject(result);
}
 
开发者ID:OpenNTF,项目名称:org.openntf.domino,代码行数:27,代码来源:JsonGraphWriter.java

示例12: insertDoc

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
public void insertDoc(String dbName, String title, String author, boolean read, String filePath, String contentType) throws ClientProtocolException, URISyntaxException, IOException, JsonException{
	JsonJavaObject postData = new JsonJavaObject();
	postData.put("title", title);
	postData.put("author", author);
	postData.put("read", read);

	String postUrl = bluemixUtil.getBaseUrl() + "/" + dbName;
	
	if(StringUtil.isNotEmpty(filePath) && StringUtil.isNotEmpty(contentType)) {
		JsonJavaObject imageAttachment = createAttachmentData(filePath, contentType);
		postData.put("_attachments", imageAttachment);
	}
	
	rest.post(postUrl, bluemixUtil.getAuthorizationHeader(), postData);
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:16,代码来源:Cloudant.java

示例13: updateDoc

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
public void updateDoc(String dbName, String id, String title, String author, boolean read, String revision) throws ClientProtocolException, URISyntaxException, IOException, JsonException{
	JsonJavaObject postData = new JsonJavaObject();
	postData.put("_id", id);
	postData.put("title", title);
	postData.put("_rev", revision);
	postData.put("author", author);
	postData.put("read", read);
	
	String postUrl = bluemixUtil.getBaseUrl() + "/" + dbName;
	rest.post(postUrl, bluemixUtil.getAuthorizationHeader(), postData);
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:12,代码来源:Cloudant.java

示例14: deleteDoc

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
public void deleteDoc(String dbName, String id, String revision) throws ClientProtocolException, URISyntaxException, IOException, JsonException{
	JsonJavaObject postData = new JsonJavaObject();
	postData.put("_id", id);
	postData.put("_rev", revision);
	postData.put("_deleted", true);
	
	String postUrl = bluemixUtil.getBaseUrl() + "/" + dbName;
	rest.post(postUrl, bluemixUtil.getAuthorizationHeader(), postData);
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:10,代码来源:Cloudant.java

示例15: createDefaultView

import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
private int createDefaultView() throws ClientProtocolException, URISyntaxException, IOException, JsonException {
	String putUrl = bluemixUtil.getBaseUrl() + "/booklist/_design/documents";
	JsonJavaObject putData = new JsonJavaObject();
	JsonJavaObject viewsData = new JsonJavaObject();
	JsonJavaObject allViewData = new JsonJavaObject();
	
	allViewData.put("map", "function(doc){emit(doc);}");
	viewsData.put("all", allViewData);
	putData.put("_id", "_design/documents");
	putData.put("views", viewsData);
	
	Response response = rest.put(putUrl, bluemixUtil.getAuthorizationHeader(), putData);
	int responseStatus = response.returnResponse().getStatusLine().getStatusCode();
	return responseStatus;
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:16,代码来源:Cloudant.java


注:本文中的com.ibm.commons.util.io.json.JsonException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。