use of flexjson.JSONSerializer in project openhab1-addons by openhab.
the class SenseService method store.
/**
* @{inheritDoc}
*/
@Override
public void store(Item item, String alias) {
if (initialized) {
JSONSerializer serializer = new JSONSerializer().transform(new SenseEventTransformer(), SenseEventBean.class);
String serializedBean = serializer.serialize(new SenseEventBean(alias, item.getState().toString()));
String serviceUrl = url + apiKey;
String response = HttpUtil.executeUrl("POST", serviceUrl, IOUtils.toInputStream(serializedBean), "application/json", 5000);
logger.debug("Stored item '{}' as '{}' in Sen.se and received response: {} ", new String[] { item.getName(), alias, response });
}
}
use of flexjson.JSONSerializer in project openhab1-addons by openhab.
the class CosmService method store.
/**
* @{inheritDoc}
*/
public void store(Item item, String alias) {
if (initialized) {
try {
String serviceUrl = url;
if (alias == null) {
alias = item.getName();
}
serviceUrl += "/" + alias;
URL url = new URL(serviceUrl);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestMethod("PUT");
httpCon.setRequestProperty("Content-type", "application/json");
httpCon.setRequestProperty("X-ApiKey", apiKey);
OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());
JSONSerializer serializer = new JSONSerializer().transform(new CosmEventTransformer(), CosmEventBean.class);
String serializedBean = serializer.serialize(new CosmEventBean(alias, item.getState().toString()));
out.write(serializedBean);
out.flush();
logger.debug("Stored item '{}' as '{}' in Cosm and received response: {} ", new String[] { item.getName(), alias, httpCon.getResponseMessage() });
out.close();
} catch (Exception e) {
logger.warn("Connection error");
}
}
}
use of flexjson.JSONSerializer in project esup-papercut by EsupPortail.
the class PayBoxResourceController method getStats.
@RequestMapping(value = "/statsPapercut")
public void getStats(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletRequestBindingException {
HttpSession session = request.getSession();
String sharedSessionId = request.getParameter("sharedSessionId");
if (sharedSessionId != null) {
EsupPapercutSessionObject objectShared = (EsupPapercutSessionObject) session.getAttribute(sharedSessionId);
String requeteNbTransactions = objectShared.getRequeteNbTransactions();
String requeteMontantTransactions = objectShared.getRequeteMontantTransactions();
String requeteCumulTransactions = objectShared.getRequeteCumulTransactions();
String requeteCumulMontants = objectShared.getRequeteCumulMontants();
if (objectShared.isIsAdmin()) {
String flexJsonString = "Aucune statistique à récupérer";
try {
JSONSerializer serializer = new JSONSerializer();
flexJsonString = serializer.deepSerialize(statsService.getStatsPapercut(requeteNbTransactions, requeteMontantTransactions, requeteCumulTransactions, requeteCumulMontants));
} catch (Exception e) {
log.warn("Impossible de récupérer les statistiques", e);
}
InputStream jsonStream = IOUtils.toInputStream(flexJsonString, "utf-8");
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
FileCopyUtils.copy(jsonStream, response.getOutputStream());
}
}
}
Aggregations