本文整理汇总了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;
}
示例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";
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}