@Test public void shouldSetMessageStatusToSentWhenResponseMessageHasOk() { Set<GatewayResponse> responses = messageHandler.parseMessageResponse(gatewayRequest, "Status: Sent\nOK: " + recipientNumber); assertNotNull(responses); assertEquals(1, responses.size()); Iterator<GatewayResponse> iterator = responses.iterator(); GatewayResponse sentResponse = iterator.next(); assertEquals(MStatus.SENT, sentResponse.getMessageStatus()); assertEquals(recipientNumber, sentResponse.getRecipientNumber()); }
public Set<GatewayResponse> parseMessageResponse(GatewayRequest message, String gatewayResponse) { logger.debug("Parsing message gateway response"); logger.debug(gatewayResponse); if(message == null) return null; if(gatewayResponse.isEmpty()) return null; Set<GatewayResponse> responses = new HashSet<GatewayResponse>(); String[] responseLines = gatewayResponse.trim().split("\n"); for(String line : responseLines){ if(line.trim().isEmpty()) continue; String[] responseParts = line.split(" "); if (responseParts[0].trim().equals("Status:")) continue; GatewayResponse response = getCoreManager().createGatewayResponse(); response.setRequestId(message.getRequestId()); response.setGatewayRequest(message); response.setDateCreated(new Date()); if(responseParts[0].equalsIgnoreCase("OK:")){ handleResponseOk(message, responseParts, response); } else if(responseParts[0].equalsIgnoreCase("ERROR:")){ logger.error("Gateway returned error: " + gatewayResponse); handleResponseError(message, responseParts, response); } else{ response.setResponseText(line.trim()); response.setMessageStatus(MStatus.RETRY); } responses.add(response); } logger.debug(responses); return responses; }
RancardGatewayMessageHandlerImpl implements GatewayMessageHandler { public Set<GatewayResponse> parseMessageResponse(GatewayRequest message, String gatewayResponse) { logger.debug("Parsing message gateway response"); logger.debug(gatewayResponse); if(message == null) return null; if(gatewayResponse.isEmpty()) return null; Set<GatewayResponse> responses = new HashSet<GatewayResponse>(); String[] responseLines = gatewayResponse.trim().split("\n"); for(String line : responseLines){ if(line.trim().isEmpty()) continue; String[] responseParts = line.split(" "); if (responseParts[0].trim().equals("Status:")) continue; GatewayResponse response = getCoreManager().createGatewayResponse(); response.setRequestId(message.getRequestId()); response.setGatewayRequest(message); response.setDateCreated(new Date()); if(responseParts[0].equalsIgnoreCase("OK:")){ handleResponseOk(message, responseParts, response); } else if(responseParts[0].equalsIgnoreCase("ERROR:")){ logger.error("Gateway returned error: " + gatewayResponse); handleResponseError(message, responseParts, response); } else{ response.setResponseText(line.trim()); response.setMessageStatus(MStatus.RETRY); } responses.add(response); } logger.debug(responses); return responses; } }
RancardGatewayMessageHandlerImpl implements GatewayMessageHandler { public Set<GatewayResponse> parseMessageResponse(GatewayRequest message, String gatewayResponse) { logger.debug("Parsing message gateway response"); logger.debug(gatewayResponse); if(message == null) return null; if(gatewayResponse.isEmpty()) return null; Set<GatewayResponse> responses = new HashSet<GatewayResponse>(); String[] responseLines = gatewayResponse.trim().split("\n"); for(String line : responseLines){ if(line.trim().isEmpty()) continue; String[] responseParts = line.split(" "); if (responseParts[0].trim().equals("Status:")) continue; GatewayResponse response = getCoreManager().createGatewayResponse(); response.setRequestId(message.getRequestId()); response.setGatewayRequest(message); response.setDateCreated(new Date()); if(responseParts[0].equalsIgnoreCase("OK:")){ handleResponseOk(message, responseParts, response); } else if(responseParts[0].equalsIgnoreCase("ERROR:")){ logger.error("Gateway returned error: " + gatewayResponse); handleResponseError(message, responseParts, response); } else{ response.setResponseText(line.trim()); response.setMessageStatus(MStatus.RETRY); } responses.add(response); } logger.debug(responses); return responses; }  }
RancardGatewayMessageHandlerImpl implements GatewayMessageHandler { public Set<GatewayResponse> parseMessageResponse(GatewayRequest message, String gatewayResponse) { logger.debug("Parsing message gateway response"); logger.debug(gatewayResponse); if(message == null) return null; if(gatewayResponse.isEmpty()) return null; Set<GatewayResponse> responses = new HashSet<GatewayResponse>(); String[] responseLines = gatewayResponse.trim().split("\n"); for(String line : responseLines){ if(line.trim().isEmpty()) continue; String[] responseParts = line.split(" "); if (responseParts[0].trim().equals("Status:")) continue; GatewayResponse response = getCoreManager().createGatewayResponse(); response.setRequestId(message.getRequestId()); response.setGatewayRequest(message); response.setDateCreated(new Date()); if(responseParts[0].equalsIgnoreCase("OK:")){ handleResponseOk(message, responseParts, response); } else if(responseParts[0].equalsIgnoreCase("ERROR:")){ logger.error("Gateway returned error: " + gatewayResponse); handleResponseError(message, responseParts, response); } else{ response.setResponseText(line.trim()); response.setMessageStatus(MStatus.RETRY); } responses.add(response); } logger.debug(responses); return responses; }  Set<GatewayResponse> parseMessageResponse(GatewayRequest message, String gatewayResponse); MStatus parseMessageStatus(String gatewayResponse); MStatus lookupStatus(String code); MStatus lookupResponse(String code); CoreManager getCoreManager(); void setCoreManager(CoreManager coreManager); Map<MStatus, String> getCodeStatusMap(); void setCodeStatusMap(Map<MStatus, String> codeStatusMap); Map<MStatus, String> getCodeResponseMap(); void setCodeResponseMap(Map<MStatus, String> codeResponseMap); void setOkMessageStatus(MStatus okMessageStatus); }
RancardGatewayMessageHandlerImpl implements GatewayMessageHandler { public Set<GatewayResponse> parseMessageResponse(GatewayRequest message, String gatewayResponse) { logger.debug("Parsing message gateway response"); logger.debug(gatewayResponse); if(message == null) return null; if(gatewayResponse.isEmpty()) return null; Set<GatewayResponse> responses = new HashSet<GatewayResponse>(); String[] responseLines = gatewayResponse.trim().split("\n"); for(String line : responseLines){ if(line.trim().isEmpty()) continue; String[] responseParts = line.split(" "); if (responseParts[0].trim().equals("Status:")) continue; GatewayResponse response = getCoreManager().createGatewayResponse(); response.setRequestId(message.getRequestId()); response.setGatewayRequest(message); response.setDateCreated(new Date()); if(responseParts[0].equalsIgnoreCase("OK:")){ handleResponseOk(message, responseParts, response); } else if(responseParts[0].equalsIgnoreCase("ERROR:")){ logger.error("Gateway returned error: " + gatewayResponse); handleResponseError(message, responseParts, response); } else{ response.setResponseText(line.trim()); response.setMessageStatus(MStatus.RETRY); } responses.add(response); } logger.debug(responses); return responses; }  Set<GatewayResponse> parseMessageResponse(GatewayRequest message, String gatewayResponse); MStatus parseMessageStatus(String gatewayResponse); MStatus lookupStatus(String code); MStatus lookupResponse(String code); CoreManager getCoreManager(); void setCoreManager(CoreManager coreManager); Map<MStatus, String> getCodeStatusMap(); void setCodeStatusMap(Map<MStatus, String> codeStatusMap); Map<MStatus, String> getCodeResponseMap(); void setCodeResponseMap(Map<MStatus, String> codeResponseMap); void setOkMessageStatus(MStatus okMessageStatus);  }