```xml <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.13</version> </dependency> ``` ```java HttpClient httpClient = HttpClientBuilder.create().build(); ``` ```java HttpGet httpGet = new HttpGet("https://api.example.com/resource"); httpGet.addHeader("Authorization", "Bearer YOUR_ACCESS_TOKEN"); ``` ```java HttpResponse response = httpClient.execute(httpGet); int statusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); String responseBody = EntityUtils.toString(entity); ``` ```java JSONObject jsonResponse = new JSONObject(responseBody); String data = jsonResponse.getString("data"); ``` ```java import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import org.json.JSONObject; public class RESTApiClient { public static void main(String[] args) { try { HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet httpGet = new HttpGet("https://api.example.com/resource"); httpGet.addHeader("Authorization", "Bearer YOUR_ACCESS_TOKEN"); HttpResponse response = httpClient.execute(httpGet); int statusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); String responseBody = EntityUtils.toString(entity); if (statusCode == 200) { JSONObject jsonResponse = new JSONObject(responseBody); String data = jsonResponse.getString("data"); System.out.println("Response data: " + data); } else { System.out.println("Error: " + responseBody); } } catch (Exception e) { e.printStackTrace(); } } } ```

```xml <dependencies> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.10</version> </dependency> </dependencies> ``` ```java import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.HttpClientBuilder; import java.io.File; import java.io.IOException; public class FileUploader { public static void main(String[] args) { HttpClient httpClient = HttpClientBuilder.create().build(); HttpPost httpPost = new HttpPost(url); File file = new File("path/to/file.txt"); HttpEntity entity = MultipartEntityBuilder.create() .addBinaryBody("file", file, ContentType.DEFAULT_BINARY, file.getName()) .build(); httpPost.setEntity(entity); try { HttpResponse response = httpClient.execute(httpPost); if (response.getStatusLine().getStatusCode() == 200) { } else { } } catch (IOException e) { e.printStackTrace(); } } } ``` ```java import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class FileDownloader { public static void main(String[] args) { HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet httpGet = new HttpGet(url); try { HttpResponse response = httpClient.execute(httpGet); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(entity); InputStream inputStream = bufferedEntity.getContent(); OutputStream outputStream = new FileOutputStream("path/to/save/file.txt"); int bytesRead; byte[] buffer = new byte[1024]; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } outputStream.close(); inputStream.close(); EntityUtils.consume(entity); } else { } } catch (IOException e) { e.printStackTrace(); } } } ```

```xml <dependency> <groupId>org.appmon4j</groupId> <artifactId>appmon4j-core</artifactId> <version>1.0.0</version> </dependency> ``` ```java import org.appmon4j.core.AbstractMonitor; import org.appmon4j.core.MonitorData; public class CustomMonitor extends AbstractMonitor { private static CustomMonitor instance; public static CustomMonitor getInstance() { if (instance == null) { instance = new CustomMonitor(); } return instance; } protected CustomMonitor() { super("CustomMonitor"); } @Override public MonitorData collectData() { MonitorData data = new MonitorData(); data.put("metric1", getMetric1Value()); data.put("metric2", getMetric2Value()); return data; } private String getMetric1Value() { return "metric1Value"; } private String getMetric2Value() { return "metric2Value"; } } ``` ```yaml monitors: - name: CustomMonitor thresholds: metric1: [">", 100] metric2: ["<", 50] actions: - name: EmailAction to: [admin@example.com] subject: "Alert: Metrics threshold exceeded" Metric1 value: {{metric1}} Metric2 value: {{metric2}} ``` ```java import org.appmon4j.core.AppMon4j; import org.appmon4j.core.actions.EmailActionFactory; import org.appmon4j.core.monitor.MonitorFactory; public class Application { public static void main(String[] args) { AppMon4j.initialize(); AppMon4j.addMonitor(MonitorFactory.createMonitor(CustomMonitor.class)); AppMon4j.addAction(EmailActionFactory.createAction("EmailAction")); AppMon4j.start(); AppMon4j.stop(); } } ```