public final void handleNewMessages(final FermatMessage fermatMessage) { try { final Gson gson = new Gson(); final String jsonMessage = fermatMessage.getContent(); final NetworkServiceMessage networkServiceMessage = gson.fromJson(jsonMessage, NetworkServiceMessage.class); switch (networkServiceMessage.getMessageType()) { case INFORMATION: // update the request to processing receive state with the given action. final InformationMessage informationMessage = gson.fromJson(jsonMessage, InformationMessage.class); receiveInformationMessage(informationMessage); System.out.println( " CPR NS - Information Message Received: " + informationMessage.toString()); break; case REQUEST: // create the request in processing receive state. final RequestMessage requestMessage = gson.fromJson(jsonMessage, RequestMessage.class); receiveCryptoPaymentRequest(requestMessage); System.out.println(" CPR NS - Request Message Received: " + requestMessage.toString()); break; } } catch (Exception e) { reportUnexpectedException(e); } }
/** * I indicate to the Agent the action that it must take: - Protocol State: PROCESSING_RECEIVE. - * Action : REQUEST . */ private void receiveCryptoPaymentRequest(RequestMessage requestMessage) throws CantReceiveRequestException { try { RequestProtocolState protocolState = RequestProtocolState.PENDING_ACTION; RequestAction action = RequestAction.REQUEST; RequestType direction = RequestType.RECEIVED; cryptoPaymentRequestNetworkServiceDao.createCryptoPaymentRequest( requestMessage.getRequestId(), requestMessage.getActorPublicKey(), // the actor receiving, is the identity now. requestMessage.getActorType(), // the actor receiving, is the identity now. requestMessage .getIdentityPublicKey(), // the identity who sent the request, is the actor now. requestMessage.getIdentityType(), // the identity who sent the request, is the actor now. requestMessage.getCryptoAddress(), requestMessage.getDescription(), requestMessage.getAmount(), requestMessage.getStartTimeStamp(), direction, action, protocolState, requestMessage.getNetworkType(), requestMessage.getReferenceWallet(), 0); } catch (CantCreateCryptoPaymentRequestException e) { // i inform to error manager the error. reportUnexpectedException(e); throw new CantReceiveRequestException(e, "", "Error in Crypto Payment Request NS Dao."); } catch (Exception e) { reportUnexpectedException(e); throw new CantReceiveRequestException(e, "", "Unhandled Exception."); } }