@Test public void testGetMessageStatus() { System.out.println("getMessageStatus"); GatewayResponseImpl response = new GatewayResponseImpl(); response.setGatewayMessageId("testId"); String result = instance.getMessageStatus(response); assertNotNull(result); }
public String getMessageStatus(GatewayResponse response) { try { postData = "api_id=" + URLEncoder.encode(apiId, "UTF-8"); postData += "&user=" + URLEncoder.encode(user, "UTF-8"); postData += "&password=" + URLEncoder.encode(password, "UTF-8"); postData += "&apimsgid=" + URLEncoder.encode(response.getGatewayMessageId(), "UTF-8"); } catch (UnsupportedEncodingException ex) { logger.fatal("Error constructing request: parameter encoding failed", ex); throw new RuntimeException("Error constructing message"); } URL url; URLConnection conn; try { url = new URL(baseUrl + "querymsg"); conn = url.openConnection(); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); } catch (MalformedURLException ex) { logger.fatal("Error initializing Clikatell Gateway: invalid url", ex); throw new RuntimeException("Invalid gatewat URL"); } catch (IOException ex) { logger.fatal("Error iitializing Clickatell Gateway: unable to open URL connection", ex); throw new RuntimeException("Could not connect to gateway"); } BufferedReader in; String data = ""; String gatewayResponse = ""; try { conn.setDoOutput(true); OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(postData); out.flush(); in = new BufferedReader(new InputStreamReader(conn.getInputStream())); while((data = in.readLine()) != null) gatewayResponse += data + "\n"; out.close(); in.close(); } catch (IOException ex) { logger.fatal("Error processing gateway request", ex); throw new RuntimeException("Unable to communicate with gateway"); } return gatewayResponse; }
ClickatellGatewayManagerImpl implements GatewayManager { public String getMessageStatus(GatewayResponse response) { try { postData = "api_id=" + URLEncoder.encode(apiId, "UTF-8"); postData += "&user=" + URLEncoder.encode(user, "UTF-8"); postData += "&password=" + URLEncoder.encode(password, "UTF-8"); postData += "&apimsgid=" + URLEncoder.encode(response.getGatewayMessageId(), "UTF-8"); } catch (UnsupportedEncodingException ex) { logger.fatal("Error constructing request: parameter encoding failed", ex); throw new RuntimeException("Error constructing message"); } URL url; URLConnection conn; try { url = new URL(baseUrl + "querymsg"); conn = url.openConnection(); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); } catch (MalformedURLException ex) { logger.fatal("Error initializing Clikatell Gateway: invalid url", ex); throw new RuntimeException("Invalid gatewat URL"); } catch (IOException ex) { logger.fatal("Error iitializing Clickatell Gateway: unable to open URL connection", ex); throw new RuntimeException("Could not connect to gateway"); } BufferedReader in; String data = ""; String gatewayResponse = ""; try { conn.setDoOutput(true); OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(postData); out.flush(); in = new BufferedReader(new InputStreamReader(conn.getInputStream())); while((data = in.readLine()) != null) gatewayResponse += data + "\n"; out.close(); in.close(); } catch (IOException ex) { logger.fatal("Error processing gateway request", ex); throw new RuntimeException("Unable to communicate with gateway"); } return gatewayResponse; } }
ClickatellGatewayManagerImpl implements GatewayManager { public String getMessageStatus(GatewayResponse response) { try { postData = "api_id=" + URLEncoder.encode(apiId, "UTF-8"); postData += "&user=" + URLEncoder.encode(user, "UTF-8"); postData += "&password=" + URLEncoder.encode(password, "UTF-8"); postData += "&apimsgid=" + URLEncoder.encode(response.getGatewayMessageId(), "UTF-8"); } catch (UnsupportedEncodingException ex) { logger.fatal("Error constructing request: parameter encoding failed", ex); throw new RuntimeException("Error constructing message"); } URL url; URLConnection conn; try { url = new URL(baseUrl + "querymsg"); conn = url.openConnection(); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); } catch (MalformedURLException ex) { logger.fatal("Error initializing Clikatell Gateway: invalid url", ex); throw new RuntimeException("Invalid gatewat URL"); } catch (IOException ex) { logger.fatal("Error iitializing Clickatell Gateway: unable to open URL connection", ex); throw new RuntimeException("Could not connect to gateway"); } BufferedReader in; String data = ""; String gatewayResponse = ""; try { conn.setDoOutput(true); OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(postData); out.flush(); in = new BufferedReader(new InputStreamReader(conn.getInputStream())); while((data = in.readLine()) != null) gatewayResponse += data + "\n"; out.close(); in.close(); } catch (IOException ex) { logger.fatal("Error processing gateway request", ex); throw new RuntimeException("Unable to communicate with gateway"); } return gatewayResponse; } ClickatellGatewayManagerImpl(); }
ClickatellGatewayManagerImpl implements GatewayManager { public String getMessageStatus(GatewayResponse response) { try { postData = "api_id=" + URLEncoder.encode(apiId, "UTF-8"); postData += "&user=" + URLEncoder.encode(user, "UTF-8"); postData += "&password=" + URLEncoder.encode(password, "UTF-8"); postData += "&apimsgid=" + URLEncoder.encode(response.getGatewayMessageId(), "UTF-8"); } catch (UnsupportedEncodingException ex) { logger.fatal("Error constructing request: parameter encoding failed", ex); throw new RuntimeException("Error constructing message"); } URL url; URLConnection conn; try { url = new URL(baseUrl + "querymsg"); conn = url.openConnection(); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); } catch (MalformedURLException ex) { logger.fatal("Error initializing Clikatell Gateway: invalid url", ex); throw new RuntimeException("Invalid gatewat URL"); } catch (IOException ex) { logger.fatal("Error iitializing Clickatell Gateway: unable to open URL connection", ex); throw new RuntimeException("Could not connect to gateway"); } BufferedReader in; String data = ""; String gatewayResponse = ""; try { conn.setDoOutput(true); OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(postData); out.flush(); in = new BufferedReader(new InputStreamReader(conn.getInputStream())); while((data = in.readLine()) != null) gatewayResponse += data + "\n"; out.close(); in.close(); } catch (IOException ex) { logger.fatal("Error processing gateway request", ex); throw new RuntimeException("Unable to communicate with gateway"); } return gatewayResponse; } ClickatellGatewayManagerImpl(); Set<GatewayResponse> sendMessage(GatewayRequest messageDetails); String getMessageStatus(GatewayResponse response); MStatus mapMessageStatus(GatewayResponse response); GatewayMessageHandler getMessageHandler(); void setMessageHandler(GatewayMessageHandler messageHandler); String getApiId(); void setApiId(String apiId); String getUser(); void setUser(String user); String getPassword(); void setPassword(String password); String getSender(); void setSender(String sender); String getDeliveryAcknowledge(); void setDeliveryAcknowledge(String deliveryAcknowledge); String getCallback(); void setCallback(String callback); void setBaseUrl(String baseUrl); }
ClickatellGatewayManagerImpl implements GatewayManager { public String getMessageStatus(GatewayResponse response) { try { postData = "api_id=" + URLEncoder.encode(apiId, "UTF-8"); postData += "&user=" + URLEncoder.encode(user, "UTF-8"); postData += "&password=" + URLEncoder.encode(password, "UTF-8"); postData += "&apimsgid=" + URLEncoder.encode(response.getGatewayMessageId(), "UTF-8"); } catch (UnsupportedEncodingException ex) { logger.fatal("Error constructing request: parameter encoding failed", ex); throw new RuntimeException("Error constructing message"); } URL url; URLConnection conn; try { url = new URL(baseUrl + "querymsg"); conn = url.openConnection(); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); } catch (MalformedURLException ex) { logger.fatal("Error initializing Clikatell Gateway: invalid url", ex); throw new RuntimeException("Invalid gatewat URL"); } catch (IOException ex) { logger.fatal("Error iitializing Clickatell Gateway: unable to open URL connection", ex); throw new RuntimeException("Could not connect to gateway"); } BufferedReader in; String data = ""; String gatewayResponse = ""; try { conn.setDoOutput(true); OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); out.write(postData); out.flush(); in = new BufferedReader(new InputStreamReader(conn.getInputStream())); while((data = in.readLine()) != null) gatewayResponse += data + "\n"; out.close(); in.close(); } catch (IOException ex) { logger.fatal("Error processing gateway request", ex); throw new RuntimeException("Unable to communicate with gateway"); } return gatewayResponse; } ClickatellGatewayManagerImpl(); Set<GatewayResponse> sendMessage(GatewayRequest messageDetails); String getMessageStatus(GatewayResponse response); MStatus mapMessageStatus(GatewayResponse response); GatewayMessageHandler getMessageHandler(); void setMessageHandler(GatewayMessageHandler messageHandler); String getApiId(); void setApiId(String apiId); String getUser(); void setUser(String user); String getPassword(); void setPassword(String password); String getSender(); void setSender(String sender); String getDeliveryAcknowledge(); void setDeliveryAcknowledge(String deliveryAcknowledge); String getCallback(); void setCallback(String callback); void setBaseUrl(String baseUrl);  }