Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java's HttpURLConnection doesn't support REPORT/PROPFIND - what shall I do?

Tags:

java

caldav

HttpURLConnection does only support things like GET, POST and HEAD - but no REPORT/PROPFIND. I'm going to implement a CalDAV-Client but without theese operations (if I want to use them I get a ProtocolException) I have to write/deliver a complete and huge HTTP library with auth and so on.

"Overkill".

How do I send requests with PROPFIND and REPORT?

like image 882
mutter erde Avatar asked Aug 11 '10 14:08

mutter erde


2 Answers

I had similar problem on WebDav for PROPFIND method.

Solved the problem by implementing this solution: https://java.net/jira/browse/JERSEY-639

    try {
            httpURLConnection.setRequestMethod(method);
        } catch (final ProtocolException pe) {
            try {
                final Class<?> httpURLConnectionClass = httpURLConnection
                        .getClass();
                final Class<?> parentClass = httpURLConnectionClass
                        .getSuperclass();
                final Field methodField;
                // If the implementation class is an HTTPS URL Connection, we
                // need to go up one level higher in the heirarchy to modify the
                // 'method' field.
                if (parentClass == HttpsURLConnection.class) {
                    methodField = parentClass.getSuperclass().getDeclaredField(
                            "method");
                } else {
                    methodField = parentClass.getDeclaredField("method");
                }
                methodField.setAccessible(true);
                methodField.set(httpURLConnection, method);
            } catch (final Exception e) {
                throw new RuntimeException(e);

            }
     }
like image 65
roko Avatar answered Sep 19 '22 10:09

roko


You'd probably want to look for a WebDAV libary, not an HTTP library, for this one.

Maybe take a look at Apache Jackrabbit.

like image 39
Dean J Avatar answered Sep 18 '22 10:09

Dean J