本文整理汇总了Java中com.ibm.commons.util.io.json.JsonException类的典型用法代码示例。如果您正苦于以下问题:Java JsonException类的具体用法?Java JsonException怎么用?Java JsonException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonException类属于com.ibm.commons.util.io.json包,在下文中一共展示了JsonException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: getSpeech
import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
/**
* Send POST request to Watson TextToSpeech service
*
* @param text - The text to turn into speech
* @param voice - The chosen voice to use for the speech (e.g."US Male", "French Female" etc.)
* @return Response containing the returned audio file
*/
public Response getSpeech(String text, String voice) throws URISyntaxException, ClientProtocolException, IOException, JsonException {
//Build the POST data
JsonJavaObject postData = new JsonJavaObject();
postData.put("text", text);
//Send the POST request
String postUrl = bluemixUtil.getBaseUrl() + "/v1/synthesize?voice=" + voice +"&accept=audio/ogg;codecs=opus";
Response response = rest.post(postUrl, bluemixUtil.getAuthorizationHeader(), postData);
return response;
}
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:19,代码来源:TextToSpeech.java
示例17: getTranslation
import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
/**
* Send a POST request to the Watson service to translate some text
*
* @param text - The text to be translated
* @param origin - The origin language of the text
* @param target - The target translation language
* @return String of the translated text
* @throws JsonException
*/
public String getTranslation(String text, String origin, String target) throws URISyntaxException, IOException, JsonException {
//Build the POST data
JsonJavaObject postData = new JsonJavaObject();
postData.put("text", text);
//Send the POST request
String postUrl = bluemixUtil.getBaseUrl() + "/v2/translate?model_id=" + origin + "-" + target +"&source=" + origin + "&target=" + target;
String responseStr = rest.post(postUrl, bluemixUtil.getAuthorizationHeader(), postData).returnContent().asString();
//Decode the result
String response = URLDecoder.decode(responseStr, "UTF-8");
return response;
}
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:23,代码来源:LanguageTranslation.java
示例18: getDojoAttributesAsJson
import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
public static String getDojoAttributesAsJson(FacesContext context, UIComponent component, JsonJavaObject json) throws IOException {
try {
return JsonGenerator.toJson(JsonJavaFactory.instance,json,true);
} catch(JsonException ex) {
IOException e = new IOException();
e.initCause(ex);
throw e;
}
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:10,代码来源:DojoRendererUtil.java
示例19: writeItemAsMime
import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
protected void writeItemAsMime(JsonWriter jsonWriter, Item item, String propName) throws IOException, NotesException, ServiceException {
MimeEntityHelper helper = null;
String itemName = item.getName();
jsonWriter.startProperty(propName);
jsonWriter.startObject();
writeProperty(jsonWriter, ATTR_TYPE, TYPE_MULTIPART);
jsonWriter.startProperty(ATTR_CONTENT);
try {
List<JsonMimeEntityAdapter> adapters = new ArrayList<JsonMimeEntityAdapter>();
helper = new MimeEntityHelper(document, itemName);
MIMEEntity entity = helper.getFirstMimeEntity(true);
if ( entity != null ) {
JsonMimeEntityAdapter.addEntityAdapter(adapters, entity);
}
jsonWriter.outLiteral(adapters);
}
catch (JsonException e) {
throw new ServiceException(e);
}
finally {
if ( helper != null ) {
helper.recycle();
}
jsonWriter.endProperty();
jsonWriter.endObject();
jsonWriter.endProperty();
}
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:29,代码来源:JsonDocumentContent.java
示例20: updateField
import com.ibm.commons.util.io.json.JsonException; //导入依赖的package包/类
protected void updateField(Form form, String itemName, Object value)
throws NotesException, ServiceException {
if (value instanceof JsonJavaObject) {
String type = (String)((JsonJavaObject)value).get(ATTR_TYPE);
if (type == null) {
// Backward compatible with earlier version we may want to change.
//updateRichText(itemName, value);
}
else if (type.equalsIgnoreCase(TYPE_DATETIME)) {
Object data = ((JsonJavaObject)value).get(ATTR_DATA);
if (data instanceof List) {
updateDateTimeList(itemName, (List<?>)data);
}
else {
updateDateTime(itemName, data);
}
}
else if (type.equalsIgnoreCase(TYPE_RICHTEXT)) {
updateRichText(itemName, (JsonJavaObject)value);
}
else if (type.equalsIgnoreCase(TYPE_MULTIPART)) {
try {
updateMimePart(itemName, (JsonJavaObject)value);
}
catch (JsonException e) {
throw new ServiceException(e);
}
}
}
else if (value instanceof List) {
//Vector<?> vector = new Vector((List)value);
//document.replaceItemValue(itemName, vector);
replaceItemValueList(form, itemName, (List<?>)value);
}
else {
//document.replaceItemValue(itemName, value);
replaceItemValue(form, itemName, value);
}
}
开发者ID:OpenNTF,项目名称:XPagesExtensionLibrary,代码行数:40,代码来源:JsonDocumentContent.java
注:本文中的com.ibm.commons.util.io.json.JsonException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论