@Test public void noChannelTest() { CamelContext context = new DefaultCamelContext(); SlackMetaDataExtension extension = new SlackMetaDataExtension(context); Map<String, Object> properties = new HashMap<>(); properties.put("webhookurl", "token"); Optional<MetaDataExtension.MetaData> meta = extension.meta(properties); assertThat(meta).isEmpty(); }
@SuppressWarnings("unchecked") @Override public Optional<MetaData> meta(Map<String, Object> parameters) { final String token = ConnectorOptions.extractOption(parameters, "token"); if (token != null) { LOG.debug("Retrieving channels for connection to slack with token {}", token); HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost httpPost = new HttpPost("https: List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("token", token)); try { httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse response = client.execute(httpPost); String jsonString = readResponse(response); JSONParser parser = new JSONParser(); JSONObject c = (JSONObject) parser.parse(jsonString); List<Object> list = (List<Object>) c.get("channels"); Set<String> setChannels = new HashSet<String>(); Iterator<Object> it = list.iterator(); while (it.hasNext()) { Object object = it.next(); JSONObject singleChannel = (JSONObject) object; if (singleChannel.get("name") != null) { setChannels.add((String) singleChannel.get("name")); } } return Optional .of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain") .withAttribute(MetaData.JAVA_TYPE, String.class).withPayload(setChannels).build()); } catch (Exception e) { throw new IllegalStateException( "Get information about channels failed with token has failed.", e); } } else { return Optional.empty(); } }
SlackMetaDataExtension extends AbstractMetaDataExtension { @SuppressWarnings("unchecked") @Override public Optional<MetaData> meta(Map<String, Object> parameters) { final String token = ConnectorOptions.extractOption(parameters, "token"); if (token != null) { LOG.debug("Retrieving channels for connection to slack with token {}", token); HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost httpPost = new HttpPost("https: List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("token", token)); try { httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse response = client.execute(httpPost); String jsonString = readResponse(response); JSONParser parser = new JSONParser(); JSONObject c = (JSONObject) parser.parse(jsonString); List<Object> list = (List<Object>) c.get("channels"); Set<String> setChannels = new HashSet<String>(); Iterator<Object> it = list.iterator(); while (it.hasNext()) { Object object = it.next(); JSONObject singleChannel = (JSONObject) object; if (singleChannel.get("name") != null) { setChannels.add((String) singleChannel.get("name")); } } return Optional .of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain") .withAttribute(MetaData.JAVA_TYPE, String.class).withPayload(setChannels).build()); } catch (Exception e) { throw new IllegalStateException( "Get information about channels failed with token has failed.", e); } } else { return Optional.empty(); } } }
SlackMetaDataExtension extends AbstractMetaDataExtension { @SuppressWarnings("unchecked") @Override public Optional<MetaData> meta(Map<String, Object> parameters) { final String token = ConnectorOptions.extractOption(parameters, "token"); if (token != null) { LOG.debug("Retrieving channels for connection to slack with token {}", token); HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost httpPost = new HttpPost("https: List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("token", token)); try { httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse response = client.execute(httpPost); String jsonString = readResponse(response); JSONParser parser = new JSONParser(); JSONObject c = (JSONObject) parser.parse(jsonString); List<Object> list = (List<Object>) c.get("channels"); Set<String> setChannels = new HashSet<String>(); Iterator<Object> it = list.iterator(); while (it.hasNext()) { Object object = it.next(); JSONObject singleChannel = (JSONObject) object; if (singleChannel.get("name") != null) { setChannels.add((String) singleChannel.get("name")); } } return Optional .of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain") .withAttribute(MetaData.JAVA_TYPE, String.class).withPayload(setChannels).build()); } catch (Exception e) { throw new IllegalStateException( "Get information about channels failed with token has failed.", e); } } else { return Optional.empty(); } } SlackMetaDataExtension(CamelContext context); }
SlackMetaDataExtension extends AbstractMetaDataExtension { @SuppressWarnings("unchecked") @Override public Optional<MetaData> meta(Map<String, Object> parameters) { final String token = ConnectorOptions.extractOption(parameters, "token"); if (token != null) { LOG.debug("Retrieving channels for connection to slack with token {}", token); HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost httpPost = new HttpPost("https: List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("token", token)); try { httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse response = client.execute(httpPost); String jsonString = readResponse(response); JSONParser parser = new JSONParser(); JSONObject c = (JSONObject) parser.parse(jsonString); List<Object> list = (List<Object>) c.get("channels"); Set<String> setChannels = new HashSet<String>(); Iterator<Object> it = list.iterator(); while (it.hasNext()) { Object object = it.next(); JSONObject singleChannel = (JSONObject) object; if (singleChannel.get("name") != null) { setChannels.add((String) singleChannel.get("name")); } } return Optional .of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain") .withAttribute(MetaData.JAVA_TYPE, String.class).withPayload(setChannels).build()); } catch (Exception e) { throw new IllegalStateException( "Get information about channels failed with token has failed.", e); } } else { return Optional.empty(); } } SlackMetaDataExtension(CamelContext context); @SuppressWarnings("unchecked") @Override Optional<MetaData> meta(Map<String, Object> parameters); }
SlackMetaDataExtension extends AbstractMetaDataExtension { @SuppressWarnings("unchecked") @Override public Optional<MetaData> meta(Map<String, Object> parameters) { final String token = ConnectorOptions.extractOption(parameters, "token"); if (token != null) { LOG.debug("Retrieving channels for connection to slack with token {}", token); HttpClient client = HttpClientBuilder.create().useSystemProperties().build(); HttpPost httpPost = new HttpPost("https: List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("token", token)); try { httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse response = client.execute(httpPost); String jsonString = readResponse(response); JSONParser parser = new JSONParser(); JSONObject c = (JSONObject) parser.parse(jsonString); List<Object> list = (List<Object>) c.get("channels"); Set<String> setChannels = new HashSet<String>(); Iterator<Object> it = list.iterator(); while (it.hasNext()) { Object object = it.next(); JSONObject singleChannel = (JSONObject) object; if (singleChannel.get("name") != null) { setChannels.add((String) singleChannel.get("name")); } } return Optional .of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain") .withAttribute(MetaData.JAVA_TYPE, String.class).withPayload(setChannels).build()); } catch (Exception e) { throw new IllegalStateException( "Get information about channels failed with token has failed.", e); } } else { return Optional.empty(); } } SlackMetaDataExtension(CamelContext context); @SuppressWarnings("unchecked") @Override Optional<MetaData> meta(Map<String, Object> parameters);  }