@Test @Ignore public void testSend() { try { NotificationStrategy ns = new HttpNotificationStrategy(); List<Argument> arguments = new ArrayList<Argument>(); Argument arg = null; arg = new Argument("url", null, "http: arguments.add(arg); arg = new Argument("post-NodeID", null, "1", false); arguments.add(arg); arg = new Argument("result-match", null, "(?s).*OK\\s+([0-9]+).*", false); arguments.add(arg); arg = new Argument("post-message", null, "-tm", false); arguments.add(arg); arg = new Argument("-tm", null, "text message for unit testing", false); arguments.add(arg); arg = new Argument("sql", null, "UPDATE alarms SET tticketID=${1} WHERE lastEventID = 1", false); arguments.add(arg); ns.send(arguments); } catch (Throwable e) { e.printStackTrace(); fail("Caught Exception:"); } }
public int send(List<Argument> arguments) { m_arguments = arguments; String url = getUrl(); if (url == null) { log().warn("send: url argument is null, HttpNotification requires a URL"); return 1; } DefaultHttpClient client = new DefaultHttpClient(); HttpUriRequest method = null; List<NameValuePair> posts = getPostArguments(); if (posts == null) { method = new HttpGet(url); log().info("send: No \"post-\" arguments..., continuing with an HTTP GET using URL: "+url); } else { log().info("send: Found \"post-\" arguments..., continuing with an HTTP POST using URL: "+url); for (final NameValuePair post : posts) { log().debug("send: post argument: "+post.getName() +" = "+post.getValue()); } method = new HttpPost(url); try { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(posts, "UTF-8"); ((HttpPost)method).setEntity(entity); } catch (UnsupportedEncodingException e) { } } String contents = null; int statusCode = -1; try { HttpResponse response = client.execute(method); statusCode = response.getStatusLine().getStatusCode(); contents = EntityUtils.toString(response.getEntity()); log().info("send: Contents is: "+contents); } catch (IOException e) { log().error("send: IO problem with HTTP post/response: "+e); throw new RuntimeException("Problem with HTTP post: "+e.getMessage()); } finally { } doSql(contents); return statusCode; }
HttpNotificationStrategy implements NotificationStrategy { public int send(List<Argument> arguments) { m_arguments = arguments; String url = getUrl(); if (url == null) { log().warn("send: url argument is null, HttpNotification requires a URL"); return 1; } DefaultHttpClient client = new DefaultHttpClient(); HttpUriRequest method = null; List<NameValuePair> posts = getPostArguments(); if (posts == null) { method = new HttpGet(url); log().info("send: No \"post-\" arguments..., continuing with an HTTP GET using URL: "+url); } else { log().info("send: Found \"post-\" arguments..., continuing with an HTTP POST using URL: "+url); for (final NameValuePair post : posts) { log().debug("send: post argument: "+post.getName() +" = "+post.getValue()); } method = new HttpPost(url); try { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(posts, "UTF-8"); ((HttpPost)method).setEntity(entity); } catch (UnsupportedEncodingException e) { } } String contents = null; int statusCode = -1; try { HttpResponse response = client.execute(method); statusCode = response.getStatusLine().getStatusCode(); contents = EntityUtils.toString(response.getEntity()); log().info("send: Contents is: "+contents); } catch (IOException e) { log().error("send: IO problem with HTTP post/response: "+e); throw new RuntimeException("Problem with HTTP post: "+e.getMessage()); } finally { } doSql(contents); return statusCode; } }
HttpNotificationStrategy implements NotificationStrategy { public int send(List<Argument> arguments) { m_arguments = arguments; String url = getUrl(); if (url == null) { log().warn("send: url argument is null, HttpNotification requires a URL"); return 1; } DefaultHttpClient client = new DefaultHttpClient(); HttpUriRequest method = null; List<NameValuePair> posts = getPostArguments(); if (posts == null) { method = new HttpGet(url); log().info("send: No \"post-\" arguments..., continuing with an HTTP GET using URL: "+url); } else { log().info("send: Found \"post-\" arguments..., continuing with an HTTP POST using URL: "+url); for (final NameValuePair post : posts) { log().debug("send: post argument: "+post.getName() +" = "+post.getValue()); } method = new HttpPost(url); try { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(posts, "UTF-8"); ((HttpPost)method).setEntity(entity); } catch (UnsupportedEncodingException e) { } } String contents = null; int statusCode = -1; try { HttpResponse response = client.execute(method); statusCode = response.getStatusLine().getStatusCode(); contents = EntityUtils.toString(response.getEntity()); log().info("send: Contents is: "+contents); } catch (IOException e) { log().error("send: IO problem with HTTP post/response: "+e); throw new RuntimeException("Problem with HTTP post: "+e.getMessage()); } finally { } doSql(contents); return statusCode; }  }
HttpNotificationStrategy implements NotificationStrategy { public int send(List<Argument> arguments) { m_arguments = arguments; String url = getUrl(); if (url == null) { log().warn("send: url argument is null, HttpNotification requires a URL"); return 1; } DefaultHttpClient client = new DefaultHttpClient(); HttpUriRequest method = null; List<NameValuePair> posts = getPostArguments(); if (posts == null) { method = new HttpGet(url); log().info("send: No \"post-\" arguments..., continuing with an HTTP GET using URL: "+url); } else { log().info("send: Found \"post-\" arguments..., continuing with an HTTP POST using URL: "+url); for (final NameValuePair post : posts) { log().debug("send: post argument: "+post.getName() +" = "+post.getValue()); } method = new HttpPost(url); try { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(posts, "UTF-8"); ((HttpPost)method).setEntity(entity); } catch (UnsupportedEncodingException e) { } } String contents = null; int statusCode = -1; try { HttpResponse response = client.execute(method); statusCode = response.getStatusLine().getStatusCode(); contents = EntityUtils.toString(response.getEntity()); log().info("send: Contents is: "+contents); } catch (IOException e) { log().error("send: IO problem with HTTP post/response: "+e); throw new RuntimeException("Problem with HTTP post: "+e.getMessage()); } finally { } doSql(contents); return statusCode; }  int send(List<Argument> arguments); }
HttpNotificationStrategy implements NotificationStrategy { public int send(List<Argument> arguments) { m_arguments = arguments; String url = getUrl(); if (url == null) { log().warn("send: url argument is null, HttpNotification requires a URL"); return 1; } DefaultHttpClient client = new DefaultHttpClient(); HttpUriRequest method = null; List<NameValuePair> posts = getPostArguments(); if (posts == null) { method = new HttpGet(url); log().info("send: No \"post-\" arguments..., continuing with an HTTP GET using URL: "+url); } else { log().info("send: Found \"post-\" arguments..., continuing with an HTTP POST using URL: "+url); for (final NameValuePair post : posts) { log().debug("send: post argument: "+post.getName() +" = "+post.getValue()); } method = new HttpPost(url); try { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(posts, "UTF-8"); ((HttpPost)method).setEntity(entity); } catch (UnsupportedEncodingException e) { } } String contents = null; int statusCode = -1; try { HttpResponse response = client.execute(method); statusCode = response.getStatusLine().getStatusCode(); contents = EntityUtils.toString(response.getEntity()); log().info("send: Contents is: "+contents); } catch (IOException e) { log().error("send: IO problem with HTTP post/response: "+e); throw new RuntimeException("Problem with HTTP post: "+e.getMessage()); } finally { } doSql(contents); return statusCode; }  int send(List<Argument> arguments);  }