Massive package refactoring
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / dav / DavClient.java
index 5788a32b462e78dcbe6e25e6a53a392efc78c803..6fe2eb617cf0862c8ce62b121d4a3edd481153c1 100644 (file)
@@ -15,7 +15,9 @@ import java.util.Iterator;
 
 import javax.xml.namespace.QName;
 
-import org.argeo.util.http.HttpResponseStatus;
+import org.argeo.cms.http.HttpHeader;
+import org.argeo.cms.http.HttpMethod;
+import org.argeo.cms.http.HttpStatus;
 
 public class DavClient {
 
@@ -25,14 +27,14 @@ public class DavClient {
                httpClient = HttpClient.newBuilder() //
 //                             .sslContext(insecureContext()) //
                                .version(HttpClient.Version.HTTP_1_1) //
-//                             .authenticator(new Authenticator() {
-//
-//                                     @Override
-//                                     protected PasswordAuthentication getPasswordAuthentication() {
-//                                             return new PasswordAuthentication("root", "demo".toCharArray());
-//                                     }
-//
-//                             }) //
+                               .authenticator(new Authenticator() {
+
+                                       @Override
+                                       protected PasswordAuthentication getPasswordAuthentication() {
+                                               return new PasswordAuthentication("root", "demo".toCharArray());
+                                       }
+
+                               }) //
                                .build();
        }
 
@@ -56,8 +58,8 @@ public class DavClient {
                                                        """;
                        System.out.println(body);
                        HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)) //
-                                       .header("Depth", "1") //
-                                       .method(DavMethod.PROPPATCH.name(), BodyPublishers.ofString(body)) //
+                                       .header(HttpHeader.DEPTH.getHeaderName(), DavDepth.DEPTH_1.getValue()) //
+                                       .method(HttpMethod.PROPPATCH.name(), BodyPublishers.ofString(body)) //
                                        .build();
                        BodyHandler<String> bodyHandler = BodyHandlers.ofString();
                        HttpResponse<String> response = httpClient.send(request, bodyHandler);
@@ -76,8 +78,8 @@ public class DavClient {
                                          <D:propname/>
                                        </D:propfind>""";
                        HttpRequest request = HttpRequest.newBuilder().uri(uri) //
-                                       .header(DavHeader.DEPTH.getHeaderName(), DavDepth.DEPTH_1.getValue()) //
-                                       .method(DavMethod.PROPFIND.name(), BodyPublishers.ofString(body)) //
+                                       .header(HttpHeader.DEPTH.getHeaderName(), DavDepth.DEPTH_1.getValue()) //
+                                       .method(HttpMethod.PROPFIND.name(), BodyPublishers.ofString(body)) //
                                        .build();
 
                        HttpResponse<String> responseStr = httpClient.send(request, BodyHandlers.ofString());
@@ -95,14 +97,14 @@ public class DavClient {
        public boolean exists(URI uri) {
                try {
                        HttpRequest request = HttpRequest.newBuilder().uri(uri) //
-                                       .header(DavHeader.DEPTH.getHeaderName(), DavDepth.DEPTH_0.getValue()) //
-                                       .method(DavMethod.HEAD.name(), BodyPublishers.noBody()) //
+                                       .header(HttpHeader.DEPTH.getHeaderName(), DavDepth.DEPTH_0.getValue()) //
+                                       .method(HttpMethod.HEAD.name(), BodyPublishers.noBody()) //
                                        .build();
                        BodyHandler<String> bodyHandler = BodyHandlers.ofString();
                        HttpResponse<String> response = httpClient.send(request, bodyHandler);
                        System.out.println(response.body());
                        int responseStatusCode = response.statusCode();
-                       if (responseStatusCode == HttpResponseStatus.NOT_FOUND.getCode())
+                       if (responseStatusCode == HttpStatus.NOT_FOUND.getCode())
                                return false;
                        if (responseStatusCode >= 200 && responseStatusCode < 300)
                                return true;
@@ -122,8 +124,8 @@ public class DavClient {
                                          <D:allprop/>
                                        </D:propfind>""";
                        HttpRequest request = HttpRequest.newBuilder().uri(uri) //
-                                       .header(DavHeader.DEPTH.getHeaderName(), DavDepth.DEPTH_0.getValue()) //
-                                       .method(DavMethod.PROPFIND.name(), BodyPublishers.ofString(body)) //
+                                       .header(HttpHeader.DEPTH.getHeaderName(), DavDepth.DEPTH_0.getValue()) //
+                                       .method(HttpMethod.PROPFIND.name(), BodyPublishers.ofString(body)) //
                                        .build();
 
 //                     HttpResponse<String> responseStr = httpClient.send(request, BodyHandlers.ofString());
@@ -149,7 +151,7 @@ public class DavClient {
                while (responses.hasNext()) {
                        DavResponse response = responses.next();
                        System.out.println(response.getHref() + (response.isCollection() ? " (collection)" : ""));
-                       System.out.println("  " + response.getPropertyNames());
+                       //System.out.println("  " + response.getPropertyNames(HttpStatus.OK));
 
                }
 //             davClient.setProperty("http://localhost/unstable/a2/org.argeo.tp.sdk/org.opentest4j.1.2.jar",