public void run()

in collector/soap/src/main/java/org/apache/karaf/decanter/collector/soap/SoapCollector.java [83:137]


    public void run() {
        Map<String, Object> data = new HashMap<>();
        data.put("soap.request", soapRequest);
        data.put("url", url);
        data.put("type", "soap");

        // custom fields
        Enumeration<String> keys = config.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            data.put(key, config.get(key));
        }

        try {
            PropertiesPreparator.prepare(data, config);
        } catch (Exception e) {
            LOGGER.warn("Can't prepare properties", e);
        }

        HttpURLConnection connection = null;
        try {
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setRequestProperty("Content-Type", "text/xml");
            connection.setRequestProperty("Accept", "text/xml");
            Instant startTime = Instant.now();
            try (OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream())) {
                Instant responseTime = Instant.now().minusMillis(startTime.toEpochMilli());
                writer.write(soapRequest);
                writer.flush();
                data.put("http.response.code", connection.getResponseCode());
                data.put("http.response.message", connection.getResponseMessage());
                data.put("http.response.time", responseTime.toEpochMilli());
                try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
                    StringBuilder buffer = new StringBuilder();
                    String line;
                    while ((line = reader.readLine()) != null) {
                        buffer.append(line).append("\n");
                    }
                    data.put("soap.response", buffer.toString());
                }
            }
        } catch (Exception e) {
            LOGGER.warn("Can't request SOAP service", e);
            data.put("error", e.getClass().getName() + ": " + e.getMessage());
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }

        dispatcher.postEvent(new Event(topic, data));
    }