-
Notifications
You must be signed in to change notification settings - Fork 1
/
HttpClient.java
39 lines (30 loc) · 1.61 KB
/
HttpClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package lk.avix.http.client;
import lk.avix.http.util.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wso2.transport.http.netty.contract.HttpClientConnector;
import org.wso2.transport.http.netty.contract.HttpWsConnectorFactory;
import org.wso2.transport.http.netty.contract.config.SenderConfiguration;
import org.wso2.transport.http.netty.contractimpl.DefaultHttpWsConnectorFactory;
import java.util.HashMap;
import static org.wso2.transport.http.netty.contract.Constants.TEXT_PLAIN;
/**
* An HTTP client which implemented using wso2 http-transport.
*/
public class HttpClient {
private static final Logger LOG = LoggerFactory.getLogger(HttpClient.class);
public void doStart(float httpVersion, String scheme, String serverHost, int serverPort,
String serverPath, String truststorePath, String truststorePass) {
HttpWsConnectorFactory factory = new DefaultHttpWsConnectorFactory();
SenderConfiguration senderConfiguration =
HttpUtil.getSenderConfiguration(httpVersion, scheme, truststorePath, truststorePass);
HttpClientConnector httpClientConnector =
factory.createHttpClientConnector(new HashMap<>(), senderConfiguration);
String payload = "Test value!";
HashMap<String, String> headerMap = new HashMap<>();
headerMap.put("Content-Type", TEXT_PLAIN);
String response = HttpUtil.sendPostRequest(httpClientConnector, scheme, serverHost, serverPort, serverPath,
payload, headerMap);
LOG.info("Response: {}", response);
}
}