List of usage examples for com.google.gson JsonObject JsonObject
JsonObject
From source file:at.gv.egovernment.moa.id.protocols.oauth20.json.OAuthJsonToken.java
License:EUPL
@Override public JsonObject getHeader() { JsonObject header = new JsonObject(); header.addProperty(ALGORITHM_HEADER, signer.getOAuthSignatureAlgorithm().getAlgorithm()); String keyId = getKeyId();/*ww w . ja v a 2 s . com*/ if (keyId != null) { header.addProperty(KEY_ID_HEADER, keyId); } return header; }
From source file:at.gv.egovernment.moa.id.protocols.oauth20.protocol.OAuth20TokenAction.java
License:EUPL
public SLOInformationInterface processRequest(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp, IAuthData authData) throws MOAIDException { OAuth20SessionObject auth20SessionObject = null; try {//w w w . j a v a2 s. c o m OAuth20TokenRequest oAuthRequest = (OAuth20TokenRequest) req; try { Logger.debug("Loaded OAuth20SessionObject from session: " + oAuthRequest.getCode()); auth20SessionObject = AssertionStorage.getInstance().get(oAuthRequest.getCode(), OAuth20SessionObject.class); } catch (MOADatabaseException e) { throw new OAuth20UnauthorizedClientException(); } // do checking for different grant types and code if (auth20SessionObject == null || !auth20SessionObject.getCode().equals(oAuthRequest.getCode())) { throw new OAuth20UnauthorizedClientException(); } else { Logger.debug("Loaded of OAuth20SessionObject was successful"); } // create response JsonObject jsonObject = new JsonObject(); OAuth20Util.addProperytiesToJsonObject(jsonObject, auth20SessionObject.getAuthDataSession()); String jsonResponse = jsonObject.toString(); Logger.debug("JSON Response: " + jsonResponse); // write respone to http response httpResp.setContentType("application/json"); httpResp.setStatus(HttpServletResponse.SC_OK); httpResp.getOutputStream().print(jsonResponse); httpResp.getOutputStream().close(); return null; } catch (Exception e) { Logger.error(e.getMessage(), e); throw new OAuth20ServerErrorException(); } finally { if (auth20SessionObject != null) { // destroy session for clean up Logger.debug("Going to destroy session: " + auth20SessionObject.getCode()); AssertionStorage.getInstance().remove(auth20SessionObject.getCode()); } } }
From source file:at.orz.arangodb.impl.InternalGraphDriverImpl.java
License:Apache License
public <T> EdgeEntity<T> createEdge(String database, String graphName, String key, String fromHandle, String toHandle, Object value, String label, Boolean waitForSync) throws ArangoException { JsonObject obj;//w w w . java 2s . c o m if (value == null) { obj = new JsonObject(); } else { JsonElement elem = EntityFactory.toJsonElement(value, false); if (elem.isJsonObject()) { obj = elem.getAsJsonObject(); } else { throw new IllegalArgumentException("value need object type(not support array, primitive, etc..)."); } } obj.addProperty("_key", key); obj.addProperty("_from", fromHandle); obj.addProperty("_to", toHandle); obj.addProperty("$label", label); validateCollectionName(graphName); HttpResponseEntity res = httpManager.doPost( createEndpointUrl(baseUrl, database, "/_api/graph", StringUtils.encodeUrl(graphName), "/edge"), new MapBuilder().put("waitForSync", waitForSync).get(), EntityFactory.toJsonString(obj)); return createEntity(res, EdgeEntity.class, value == null ? null : value.getClass()); }
From source file:at.quelltextlich.phabricator.conduit.raw.ConduitModule.java
License:Apache License
/** * Runs the API's 'conduit.ping' method/*from www. ja v a 2 s .com*/ */ public PingResult ping() throws ConduitException { final JsonElement callResult = connection.call("conduit.ping"); final JsonObject callResultWrapper = new JsonObject(); callResultWrapper.add("hostname", callResult); final PingResult result = gson.fromJson(callResultWrapper, PingResult.class); return result; }
From source file:at.storm.bolt.JsonBolt.java
License:Apache License
public void execute(Tuple tuple, BasicOutputCollector collector) { String jsonString = tuple.getStringByField("jsonString"); TupleStatistic tupleStatistic = (TupleStatistic) tuple.getValueByField("tupleStatistic"); JsonObject jsonObject = (JsonObject) jsonParser.parse(jsonString); if (m_logging) { LOG.info("JSON: " + jsonObject.toString()); }// ww w. j av a 2 s . co m tupleStatistic.setRealStart(jsonObject.get("timestamp").getAsLong()); String message = jsonObject.get("msg").getAsString(); if (!LanguageDetection.isEnglish(message)) { JsonObject score = new JsonObject(); score.addProperty("score", 0); jsonObject.add("sentiment", score); collector.emit(TO_REDIS_PUBLISH_STREAM, new JsonBoltData(jsonObject, tupleStatistic)); } else { collector.emit(PIPELINE_STREAM, new JsonBoltData(jsonObject, tupleStatistic)); } }
From source file:at.storm.bolt.SVMBolt.java
License:Apache License
public void execute(Tuple tuple) { FeatureGenerationBoltData featureGenerationValue = FeatureGenerationBoltData.getFromTuple(tuple); JsonObject jsonObject = featureGenerationValue.getJsonObject(); TupleStatistic tupleStatistic = featureGenerationValue.getTupleStatistic(); Map<Integer, Double> featureVector = featureGenerationValue.getFeatureVector(); // Create feature nodes svm_node[] testNodes = new svm_node[featureVector.size()]; int i = 0;/*w ww . ja va 2s . c o m*/ for (Map.Entry<Integer, Double> feature : featureVector.entrySet()) { svm_node node = new svm_node(); node.index = feature.getKey(); node.value = feature.getValue(); testNodes[i] = node; i++; } double predictedClass = svm.svm_predict(m_model, testNodes); JsonObject score = new JsonObject(); score.addProperty("score", convertRating(predictedClass)); jsonObject.add("sentiment", score); if (m_logging) { LOG.info("SVM all done log: " + jsonObject.toString()); } collector.emit(tuple, new SVMBoltData(jsonObject, tupleStatistic)); collector.ack(tuple); }
From source file:at.tugraz.kmi.medokyservice.fca.db.DataObject.java
License:Open Source License
/** * Returns a JSON string representation of the object using the * {@link JSONMapper}/*w w w. j av a2 s. co m*/ * * @return a JSON string representation of the object */ @Override public String toString() { try { return JSONMapper.getInstance().toJson(this); } catch (Exception e) { JsonObject js = new JsonObject(); js.addProperty("id", id); js.addProperty("name", name); js.addProperty("description", description); return js.toString(); } }
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
private static JsonObject prepare(DataObject o) { JsonObject jso = new JsonObject(); jso.addProperty(ID, o.getId());//from w w w . j a v a2 s . c o m jso.addProperty(NAME, o.getName()); jso.addProperty(DESCRIPTION, o.getDescription()); return jso; }
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
private JsonElement users2JSON() { BlockingDeque<User> users = Database.getInstance().getAll(User.class); JsonObject block = new JsonObject(); for (User u : users) { JsonObject jso = prepare(u);// w w w. j a v a 2s. co m jso.addProperty(E_UID, u.getExternalUid()); block.add(Long.toString(u.getId()), jso); } return block; }
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
private JsonElement learningObjects2JSON() { BlockingDeque<LearningObject> lobjects = Database.getInstance().getAll(LearningObject.class); JsonObject block = new JsonObject(); for (LearningObject o : lobjects) { JsonObject jso = prepare(o);// ww w. j av a 2s . c o m jso.addProperty(DATA, o.getData()); jso.addProperty(OWNER, o.getOwner().getId()); block.add(Long.toString(o.getId()), jso); } return block; }