1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.helper;
17
18 import java.nio.charset.StandardCharsets;
19
20 import org.codelibs.core.lang.StringUtil;
21 import org.codelibs.curl.Curl.Method;
22 import org.codelibs.curl.CurlRequest;
23 import org.codelibs.fess.mylasta.direction.FessConfig;
24 import org.codelibs.fess.util.ComponentUtil;
25 import org.codelibs.fess.util.ResourceUtil;
26
27 public class CurlHelper {
28
29 public CurlRequest get(final String path) {
30 return request(Method.GET, path).header("Content-Type", "application/json");
31 }
32
33 public CurlRequest post(final String path) {
34 return request(Method.POST, path).header("Content-Type", "application/json");
35 }
36
37 public CurlRequest put(final String path) {
38 return request(Method.PUT, path).header("Content-Type", "application/json");
39 }
40
41 public CurlRequest delete(final String path) {
42 return request(Method.DELETE, path).header("Content-Type", "application/json");
43 }
44
45 public CurlRequest request(final Method method, final String path) {
46 final CurlRequest request = new CurlRequest(method, ResourceUtil.getFesenHttpUrl() + path);
47 final FessConfig fessConfig = ComponentUtil.getFessConfig();
48 final String username = fessConfig.getFesenUsername();
49 final String password = fessConfig.getFesenPassword();
50 if (StringUtil.isNotBlank(username) && StringUtil.isNotBlank(password)) {
51 final String value = username + ":" + password;
52 final String basicAuth = "Basic " + java.util.Base64.getEncoder().encodeToString(value.getBytes(StandardCharsets.UTF_8));
53 request.header("Authorization", basicAuth);
54 }
55 return request;
56 }
57 }