19 package org.turro.http;
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25 import javax.servlet.http.HttpServletRequest;
26 import org.turro.string.Strings;
27 import org.apache.hc.client5.http.classic.methods.HttpPost;
28 import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
29 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
30 import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
31 import org.apache.hc.client5.http.impl.classic.HttpClients;
32 import org.apache.hc.core5.http.HttpEntity;
33 import org.apache.hc.core5.http.NameValuePair;
34 import org.apache.hc.core5.http.message.BasicNameValuePair;
35 import org.turro.action.Secrets;
43 private final String serverUrl;
44 private final HashMap<String, String> parameters;
47 this.serverUrl = serverUrl;
48 parameters =
new HashMap<>();
52 parameters.put(name, value);
56 if(serverUrl ==
null || parameters.isEmpty()) {
59 List<NameValuePair> nvps =
new ArrayList<>();
60 for(String key : parameters.keySet()) {
61 String value = parameters.get(key);
62 if(!Strings.isBlank(value)) {
63 nvps.add(
new BasicNameValuePair(key, value));
67 HttpPost httpPost =
new HttpPost(serverUrl);
68 httpPost.setEntity(
new UrlEncodedFormEntity(nvps));
69 try (CloseableHttpClient closeableClient = (CloseableHttpClient) HttpClients.createDefault()) {
70 try (CloseableHttpResponse closeableResponse = (CloseableHttpResponse) closeableClient.execute(httpPost)) {
71 HttpEntity resEntity = closeableResponse.getEntity();
77 public static boolean isValid(HttpServletRequest request) {
static String getSecret(String keys)
ElephantResponse doPost()
void addParameter(String name, String value)
ElephantPost(String serverUrl)
static boolean isValid(HttpServletRequest request)
static ElephantResponse getResponse(HttpEntity entity)