List of usage examples for com.google.gson JsonObject getAsJsonPrimitive
public JsonPrimitive getAsJsonPrimitive(String memberName)
From source file:com.mailrest.maildal.secur.AccountWebToken.java
License:Apache License
@Override public void readJson(JsonObject jsonObject) { this.accountId = jsonObject.getAsJsonPrimitive(ACCOUNT_ID_FIELD).getAsString(); this.userId = jsonObject.getAsJsonPrimitive(USER_ID_FIELD).getAsString(); this.permission = UserPermission.fromCode(jsonObject.getAsJsonPrimitive(PERMISSION_FIELD).getAsString()); }
From source file:com.mailrest.maildal.secur.CallbackWebToken.java
License:Apache License
@Override public void readJson(JsonObject jsonObject) { this.accountId = jsonObject.getAsJsonPrimitive(ACCOUNT_ID_FIELD).getAsString(); this.userId = jsonObject.getAsJsonPrimitive(USER_ID_FIELD).getAsString(); this.action = CallbackAction.fromCode(jsonObject.getAsJsonPrimitive(ACTION_FIELD).getAsString()); }
From source file:com.mailrest.maildal.secur.DefaultTokenManager.java
License:Apache License
@Override public T fromJwt(String jwt) { if (jwt == null || jwt.isEmpty()) { throw new IllegalArgumentException("empty token"); }/*from w ww .j av a2 s . c o m*/ JsonToken jsonToken; try { jsonToken = parser.verifyAndDeserialize(jwt); } catch (IllegalStateException | JsonParseException | SignatureException e) { throw new InvalidTokenException("wrong token format", e); } JsonObject payload = jsonToken.getPayloadAsJsonObject(); // System.out.println(payload); String issuer = payload.getAsJsonPrimitive("iss").getAsString(); if (!ISSUER.equals(issuer)) { throw new InvalidTokenException("invalid issuer"); } Instant currentTime = new Instant(System.currentTimeMillis()); Instant issuedTime = jsonToken.getIssuedAt(); Instant expiresTime = jsonToken.getExpiration(); if (issuedTime == null) { throw new InvalidTokenException("empty issuedTime"); } if (expiresTime == null) { throw new InvalidTokenException("empty expiresTime"); } if (currentTime.compareTo(issuedTime) >= 0 && currentTime.compareTo(expiresTime) <= 0) { T tokenObj = instance.newInstance(); tokenObj.readJson(payload); String error = tokenObj.verifyObj(); if (error != null) { throw new InvalidTokenException("token validation failed: " + error); } return tokenObj; } else { throw new InvalidTokenException("expired token"); } }
From source file:com.mailrest.maildal.secur.UnsubscribeWebToken.java
License:Apache License
@Override public void readJson(JsonObject jsonObject) { this.accountId = jsonObject.getAsJsonPrimitive(ACCOUNT_ID_FIELD).getAsString(); this.domainId = jsonObject.getAsJsonPrimitive(DOMAIN_ID_FIELD).getAsString(); this.emailId = jsonObject.getAsJsonPrimitive(EMAIL_ID_FIELD).getAsString(); }
From source file:com.microsoft.firstapp.AuthService.java
License:Apache License
/*** * Pulls the user ID and token out of a json object from the server * /*w ww . java2 s . c om*/ * @param jsonObject */ public void setUserAndSaveData(JsonObject jsonObject) { String userId = jsonObject.getAsJsonPrimitive("userId").getAsString(); String token = jsonObject.getAsJsonPrimitive("token").getAsString(); setUserData(userId, token); saveUserData(); }
From source file:com.nearce.gamechatter.WebSocketHandler.java
License:Mozilla Public License
private void process(InetSocketAddress address, String message) { JsonObject object = new JsonParser().parse(message).getAsJsonObject(); UUID identifier = UUID.fromString(object.getAsJsonPrimitive("user").getAsString()); String method = object.getAsJsonPrimitive("method").getAsString(); JsonObject params = object.getAsJsonObject("params"); switch (method) { case "join": join(address, identifier, params); break;/*from www . jav a 2 s . co m*/ case "leave": leave(address, params); break; case "send": sendMessage(address, params); break; case "psend": sendPrivateMessage(address, params); break; } }
From source file:com.nttdata.emea.nuoffice.CallHandler.java
License:Open Source License
private void startRecording(WebSocketSession session, JsonObject jsonMessage) throws IOException { JsonObject response = new JsonObject(); String user = jsonMessage.getAsJsonPrimitive("user").getAsString(); String responseMsg = "accepted"; pipeline.startDefaultRecording();/*ww w. j a v a2 s. com*/ response.addProperty("id", "startRecording"); response.addProperty("response", responseMsg); UserSession us = new UserSession(session, user); us.sendMessage(response); }
From source file:com.nttdata.emea.nuoffice.CallHandler.java
License:Open Source License
private void stopRecording(WebSocketSession session, JsonObject jsonMessage) throws IOException { try {/* w w w . j av a 2 s . c o m*/ log.debug("System library path = " + System.getProperty("java.library.path")); JsonObject response = new JsonObject(); String user = jsonMessage.getAsJsonPrimitive("user").getAsString(); pipeline.stopDefaultRecording(); String responseMsg = "accepted"; response.addProperty("id", "stopRecording"); response.addProperty("response", responseMsg); UserSession us = new UserSession(session, user); us.sendMessage(response); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.nttdata.emea.nuoffice.CallHandler.java
License:Open Source License
private void addPrint(WebSocketSession session, JsonObject jsonMessage) throws IOException { try {/*w ww. j a va 2s. co m*/ JsonObject response = new JsonObject(); String user = jsonMessage.getAsJsonPrimitive("user").getAsString(); String caller = jsonMessage.getAsJsonPrimitive("caller").getAsString(); long recordPeriod = DEFAULT_RECORD_PERIOD; try { recordPeriod = jsonMessage.getAsJsonPrimitive("recordPeriod").getAsLong(); } catch (Exception e) { } log.debug("Record period = " + recordPeriod); log.debug("Start print recording"); String recordId = pipeline.startRecording(); Thread.sleep(recordPeriod); log.debug("Stop print recording"); recordId = pipeline.stopRecording(); log.debug("System library path = " + System.getProperty("java.library.path")); log.info("Read file " + recordId + ".webm from media server"); new ScpFrom().read(new String[] { "chris@" + NuOfficePrototypeApplication.IP_ADRESS + ":" + DIR + recordId + ".webm", DIR + recordId + ".webm" }); String printId = caller + "_" + recordId; new Decoder().process(DIR + recordId + ".webm", DIR + printId + ".wav"); String responseMsg = "accepted"; response.addProperty("id", "addPrint"); response.addProperty("recordId", recordId); response.addProperty("printId", printId); response.addProperty("response", responseMsg); UserSession us = new UserSession(session, user); us.sendMessage(response); recognitoService.addPrint(printId, "c:/tmp/" + printId + ".wav"); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.nttdata.emea.nuoffice.CallHandler.java
License:Open Source License
private void verifySample(WebSocketSession session, JsonObject jsonMessage) throws IOException { try {//from w w w.j a va 2s. c o m JsonObject response = new JsonObject(); String user = jsonMessage.getAsJsonPrimitive("user").getAsString(); long recordPeriod = DEFAULT_SAMPLE_PERIOD; try { recordPeriod = jsonMessage.getAsJsonPrimitive("recordPeriod").getAsLong(); } catch (Exception e) { } String result = null; String recordId = null; int count = 0; do { log.debug("Record period = " + recordPeriod); log.debug("Start sample recording"); recordId = pipeline.startRecording(); Thread.sleep(recordPeriod); log.debug("Stop sample recording"); recordId = pipeline.stopRecording(); log.debug("System library path = " + System.getProperty("java.library.path")); log.info("Read file " + recordId + ".webm from media server"); new ScpFrom().read(new String[] { "chris@localhost:/tmp/" + recordId + ".webm", "c:/tmp/" + recordId + ".webm" }); new Decoder().process("c:/tmp/" + recordId + ".webm", "c:/tmp/" + recordId + ".wav"); result = recognitoService.verifySample(new File("c:/tmp/" + recordId + ".wav")); log.info(result + "identified as customer"); } while (result == null && count++ < 1); String responseMsg = result != null ? result.split("_")[0] : "unknown"; response.addProperty("id", "verifySample"); response.addProperty("recordId", recordId); response.addProperty("response", responseMsg); UserSession us = new UserSession(session, user); us.sendMessage(response); } catch (Exception e) { e.printStackTrace(); } }