Commit 80f3b060 authored by Ricki Hirner's avatar Ricki Hirner

Use java.util.logging instead of slf4j

parent fd19c653
......@@ -25,7 +25,6 @@ dependencies {
compile 'com.squareup.okhttp3:okhttp:3.1.2'
compile 'com.squareup.okhttp3:logging-interceptor:3.1.2'
provided 'org.projectlombok:lombok:1.16.6'
compile 'org.slf4j:slf4j-android:1.7.14'
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.1.2'
}
......@@ -52,7 +52,7 @@ public class DavResourceTest extends TestCase {
public void testOptions() throws InterruptedException, IOException, HttpException, DavException {
HttpUrl url = sampleUrl();
DavResource dav = new DavResource(null, httpClient, url);
DavResource dav = new DavResource(httpClient, url);
mockServer.enqueue(new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
......@@ -71,7 +71,7 @@ public class DavResourceTest extends TestCase {
public void testGet() throws InterruptedException, IOException, HttpException, DavException {
HttpUrl url = sampleUrl();
DavResource dav = new DavResource(null, httpClient, url);
DavResource dav = new DavResource(httpClient, url);
/* POSITIVE TEST CASES */
......@@ -124,7 +124,7 @@ public class DavResourceTest extends TestCase {
public void testPut() throws InterruptedException, IOException, HttpException, DavException {
HttpUrl url = sampleUrl();
DavResource dav = new DavResource(null, httpClient, url);
DavResource dav = new DavResource(httpClient, url);
/* POSITIVE TEST CASES */
......@@ -171,7 +171,7 @@ public class DavResourceTest extends TestCase {
public void testDelete() throws InterruptedException, IOException, HttpException {
HttpUrl url = sampleUrl();
DavResource dav = new DavResource(null, httpClient, url);
DavResource dav = new DavResource(httpClient, url);
/* POSITIVE TEST CASES */
......@@ -209,7 +209,7 @@ public class DavResourceTest extends TestCase {
public void testPropfindAndMultiStatus() throws IOException, HttpException, DavException {
HttpUrl url = sampleUrl();
DavResource dav = new DavResource(null, httpClient, url);
DavResource dav = new DavResource(httpClient, url);
/*** NEGATIVE TESTS ***/
......@@ -493,7 +493,7 @@ public class DavResourceTest extends TestCase {
public void testPropfindUpdateProperties() throws IOException, HttpException, DavException {
HttpUrl url = sampleUrl();
DavResource dav = new DavResource(null, httpClient, url);
DavResource dav = new DavResource(httpClient, url);
mockServer.enqueue(new MockResponse()
.setResponseCode(207)
......
......@@ -58,13 +58,13 @@ public class BasicDigestAuthenticator implements Authenticator {
Request request = response.request();
if (host != null && !request.url().host().equalsIgnoreCase(host)) {
Constants.log.warn("Not authenticating against " + host + " for security reasons!");
Constants.log.warning("Not authenticating against " + host + " for security reasons!");
return null;
}
// check whether this is the first authentication try with our credentials
Response priorResponse = response.priorResponse();
boolean triedBefore = priorResponse != null ? priorResponse.request().header(HEADER_AUTHORIZATION) != null : false;
boolean triedBefore = priorResponse != null && priorResponse.request().header(HEADER_AUTHORIZATION) != null;
HttpUtils.AuthScheme basicAuth = null, digestAuth = null;
for (HttpUtils.AuthScheme scheme : HttpUtils.parseWwwAuthenticate(response.headers(HEADER_AUTHENTICATE).toArray(new String[0])))
......@@ -81,7 +81,7 @@ public class BasicDigestAuthenticator implements Authenticator {
// credentials didn't work last time, and they won't work now -> stop here
return null;
Constants.log.debug("Adding Digest authorization request for {}", request.url());
Constants.log.fine("Adding Digest authorization request for " + request.url());
return authorizationRequest(request, digestAuth);
} else if (basicAuth != null) {
......@@ -89,12 +89,12 @@ public class BasicDigestAuthenticator implements Authenticator {
if (triedBefore) // credentials didn't work last time, and they won't work now -> stop here
return null;
Constants.log.debug("Adding Basic authorization header for {}", request.url());
Constants.log.fine("Adding Basic authorization header for " + request.url());
return request.newBuilder()
.header(HEADER_AUTHORIZATION, Credentials.basic(username, password))
.build();
} else
Constants.log.error("No supported authentication scheme");
Constants.log.severe("No supported authentication scheme");
// no supported auth scheme
return null;
......@@ -144,7 +144,7 @@ public class BasicDigestAuthenticator implements Authenticator {
a1 = username + ":" + realm + ":" + password;
else if (algorithm == Algorithm.MD5_SESSION)
a1 = h(username + ":" + realm + ":" + password) + ":" + nonce + ":" + clientNonce;
Constants.log.trace("A1=" + a1);
Constants.log.finer("A1=" + a1);
String a2 = null;
if (qop == Protection.Auth)
......@@ -154,15 +154,15 @@ public class BasicDigestAuthenticator implements Authenticator {
RequestBody body = request.body();
a2 = method + ":" + digestURI + ":" + (body != null ? h(body) : h(""));
} catch(IOException e) {
Constants.log.warn("Couldn't get entity-body for hash calculation");
Constants.log.warning("Couldn't get entity-body for hash calculation");
}
Constants.log.trace("A2=" + a2);
Constants.log.finer("A2=" + a2);
if (a1 != null && a2 != null)
response = kd(h(a1), nonce + ":" + ncValue + ":" + clientNonce + ":" + qop.name + ":" + h(a2));
} else {
Constants.log.trace("Using legacy Digest auth");
Constants.log.finer("Using legacy Digest auth");
// legacy (backwards compatibility with RFC 2069)
if (algorithm == Algorithm.MD5) {
......@@ -213,7 +213,7 @@ public class BasicDigestAuthenticator implements Authenticator {
else if (Algorithm.MD5_SESSION.name.equals(paramValue))
return Algorithm.MD5_SESSION;
else
Constants.log.warn("Ignoring unknown hash algorithm: " + paramValue);
Constants.log.warning("Ignoring unknown hash algorithm: " + paramValue);
return null;
}
}
......
package at.bitfire.dav4android;
import android.util.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.logging.Logger;
public class Constants {
public static final String LOG_TAG = "dav4android";
public static final Logger log = LoggerFactory.getLogger("dav4android");
public static final Logger log = Logger.getLogger("davdroid.dav4android");
}
......@@ -8,13 +8,6 @@
package at.bitfire.dav4android;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.slf4j.Logger;
import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
......@@ -23,6 +16,11 @@ import java.io.StringWriter;
import at.bitfire.dav4android.exception.DavException;
import at.bitfire.dav4android.exception.HttpException;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class DavAddressBook extends DavResource {
......@@ -30,8 +28,8 @@ public class DavAddressBook extends DavResource {
MIME_VCARD3_UTF8 = MediaType.parse("text/vcard;charset=utf-8"),
MIME_VCARD4 = MediaType.parse("text/vcard;version=4.0");
public DavAddressBook(Logger log, OkHttpClient httpClient, HttpUrl location) {
super(log, httpClient, location);
public DavAddressBook(OkHttpClient httpClient, HttpUrl location) {
super(httpClient, location);
}
public void addressbookQuery() throws IOException, HttpException, DavException {
......
......@@ -8,14 +8,6 @@
package at.bitfire.dav4android;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.slf4j.Logger;
import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
......@@ -23,14 +15,20 @@ import java.io.StringWriter;
import at.bitfire.dav4android.exception.DavException;
import at.bitfire.dav4android.exception.HttpException;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class DavCalendar extends DavResource {
public static final MediaType
MIME_ICALENDAR = MediaType.parse("text/calendar;charset=utf-8");
public DavCalendar(Logger log, OkHttpClient httpClient, HttpUrl location) {
super(log, httpClient, location);
public DavCalendar(OkHttpClient httpClient, HttpUrl location) {
super(httpClient, location);
}
public void calendarQuery(String component) throws IOException, HttpException, DavException {
......
......@@ -10,7 +10,6 @@ package at.bitfire.dav4android;
import android.text.TextUtils;
import org.slf4j.Logger;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
......@@ -23,6 +22,8 @@ import java.net.ProtocolException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import at.bitfire.dav4android.exception.ConflictException;
import at.bitfire.dav4android.exception.DavException;
......@@ -47,7 +48,6 @@ import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.internal.http.StatusLine;
import okio.BufferedSink;
public class DavResource {
......@@ -67,19 +67,23 @@ public class DavResource {
/**
* Creates a new DavResource which represents a WebDAV resource at the given location.
* @param log #{@link Logger} which will be used for logging, or null for default
* @param httpClient #{@link OkHttpClient} to access this object
* @param location location of the WebDAV resource
* @param log #{@link Logger} which will be used for logging, or null for default
*/
public DavResource(Logger log, OkHttpClient httpClient, HttpUrl location) {
this.log = log != null ? log : Constants.log;
public DavResource(@NonNull OkHttpClient httpClient, @NonNull HttpUrl location, @NonNull Logger log) {
this.log = log;
this.httpClient = httpClient;
this.location = location;
// Don't follow redirects (only useful for GET/POST).
// This means we have to handle 30x responses manually.
if (httpClient.followRedirects())
throw new IllegalArgumentException();
throw new IllegalArgumentException("httpClient must not follow redirects automatically");
}
public DavResource(@NonNull OkHttpClient httpClient, @NonNull HttpUrl location) {
this(httpClient, location, Constants.log);
}
......@@ -322,7 +326,7 @@ public class DavResource {
!"xml".equals(mediaType.subtype()))
throw new InvalidDavResponseException("Received non-XML 207 Multi-Status");
} else
log.warn("Received multi-status response without Content-Type, assuming XML");
log.warning("Received multi-status response without Content-Type, assuming XML");
}
void processRedirection(Response response) throws HttpException {
......@@ -333,7 +337,7 @@ public class DavResource {
target = location.resolve(href);
if (target != null) {
log.debug("Received redirection, new location=" + target);
log.fine("Received redirection, new location=" + target);
location = target;
} else
throw new HttpException("Received redirection without new location");
......@@ -425,7 +429,7 @@ public class DavResource {
try {
status = StatusLine.parse(parser.nextText());
} catch(ProtocolException e) {
log.warn("Invalid status line, treating as 500 Server Error");
log.warning("Invalid status line, treating as 500 Server Error");
status = new StatusLine(Protocol.HTTP_1_1, 500, "Invalid status line");
}
break;
......@@ -442,7 +446,7 @@ public class DavResource {
}
if (href == null) {
log.warn("Ignoring <response> without valid <href>");
log.warning("Ignoring <response> without valid <href>");
return;
}
......@@ -451,7 +455,7 @@ public class DavResource {
if (type != null && type.types.contains(ResourceType.COLLECTION))
href = UrlUtils.withTrailingSlash(href);
log.debug("Received <response> for " + href + ", status: " + status + ", properties: " + properties);
log.log(Level.FINE, "Received <response> for " + href, status != null ? status : properties);
if (status != null)
// treat an HTTP error of a single response (i.e. requested resource or a member) like an HTTP error of the requested resource
......@@ -485,7 +489,7 @@ public class DavResource {
}
if (sameBasePath)
members.add(target = new DavResource(log, httpClient, href));
members.add(target = new DavResource(httpClient, href, log));
}
}
......@@ -493,7 +497,7 @@ public class DavResource {
if (target != null)
target.properties.merge(properties, true);
else
log.warn("Received <response> not for self and not for member resource");
log.warning("Received <response> not for self and not for member resource");
}
private PropertyCollection parseMultiStatus_PropStat(XmlPullParser parser) throws IOException, XmlPullParserException {
......@@ -516,7 +520,7 @@ public class DavResource {
try {
status = StatusLine.parse(parser.nextText());
} catch(ProtocolException e) {
log.warn("Invalid status line, treating as 500 Server Error");
log.warning("Invalid status line, treating as 500 Server Error");
status = new StatusLine(Protocol.HTTP_1_1, 500, "Invalid status line");
}
}
......@@ -545,7 +549,7 @@ public class DavResource {
if (property != null)
prop.put(name, property);
else
log.debug("Ignoring unknown/unparseable property " + name);
log.fine("Ignoring unknown/unparseable property " + name);
}
eventType = parser.next();
}
......
......@@ -107,9 +107,9 @@ public class HttpUtils {
}
}
Constants.log.trace("Server authentication schemes: ");
Constants.log.finer("Server authentication schemes: ");
for (AuthScheme scheme : schemes)
Constants.log.trace(" - " + scheme);
Constants.log.finer(" - " + scheme);
return schemes;
}
......
......@@ -8,7 +8,6 @@
package at.bitfire.dav4android;
import android.provider.UserDictionary;
import android.text.TextUtils;
import lombok.RequiredArgsConstructor;
......
......@@ -10,13 +10,11 @@ package at.bitfire.dav4android;
import android.text.TextUtils;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.NonNull;
......@@ -127,10 +125,9 @@ public class PropertyCollection {
else {
List<String> s = new LinkedList<>();
Map<Property.Name, Property> properties = getMap();
for (Property.Name name : properties.keySet()) {
for (Property.Name name : properties.keySet())
s.add(name + ": " + properties.get(name));
}
return "[" + TextUtils.join(",\n", s) + "]";
return "[" + TextUtils.join(", ", s) + "]";
}
}
......
......@@ -13,9 +13,9 @@ public class PropertyRegistry {
static final PropertyRegistry DEFAULT = new PropertyRegistry();
private PropertyRegistry() {
Constants.log.debug("Registering DAV property factories:");
Constants.log.info("Registering DAV property factories");
for (PropertyFactory factory : ServiceLoader.load(PropertyFactory.class)) {
Constants.log.debug("Registering property factory for " + factory.getName());
Constants.log.info("Registering " + factory.getClass().getName() + " for " + factory.getName());
register(factory);
}
}
......
......@@ -2,12 +2,12 @@ package at.bitfire.dav4android;
import android.text.TextUtils;
import okhttp3.HttpUrl;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import okhttp3.HttpUrl;
public class UrlUtils {
public static boolean equals(HttpUrl url1, HttpUrl url2) {
......
......@@ -8,10 +8,10 @@
package at.bitfire.dav4android.exception;
import okhttp3.Response;
import java.net.HttpURLConnection;
import okhttp3.Response;
public class ConflictException extends HttpException {
public ConflictException(Response response) {
......
......@@ -8,10 +8,10 @@
package at.bitfire.dav4android.exception;
import okhttp3.Response;
import java.net.HttpURLConnection;
import okhttp3.Response;
public class NotFoundException extends HttpException {
public NotFoundException(Response response) {
......
......@@ -8,10 +8,10 @@
package at.bitfire.dav4android.exception;
import okhttp3.Response;
import java.net.HttpURLConnection;
import okhttp3.Response;
public class PreconditionFailedException extends HttpException {
public PreconditionFailedException(Response response) {
......
......@@ -8,14 +8,13 @@
package at.bitfire.dav4android.exception;
import okhttp3.Response;
import okhttp3.internal.http.HttpDate;
import java.net.HttpURLConnection;
import java.util.Calendar;
import java.util.Date;
import at.bitfire.dav4android.Constants;
import okhttp3.Response;
import okhttp3.internal.http.HttpDate;
public class ServiceUnavailableException extends HttpException {
......@@ -46,7 +45,7 @@ public class ServiceUnavailableException extends HttpException {
retryAfter = cal.getTime();
} catch (NumberFormatException e) {
Constants.log.warn("Received Retry-After which was not a HTTP-date nor delta-seconds");
Constants.log.warning("Received Retry-After which was not a HTTP-date nor delta-seconds");
}
}
}
......
......@@ -8,12 +8,11 @@
package at.bitfire.dav4android.property;
import android.util.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.logging.Level;
import at.bitfire.dav4android.Constants;
import at.bitfire.dav4android.Property;
......@@ -44,7 +43,7 @@ public class AddressData implements Property {
int eventType = parser.getEventType();
addressData.vCard = parser.nextText();
} catch(XmlPullParserException |IOException e) {
Log.e(Constants.LOG_TAG, "Couldn't parse <address-data>", e);
Constants.log.log(Level.SEVERE, "Couldn't parse <address-data>", e);
return null;
}
......
......@@ -8,15 +8,11 @@
package at.bitfire.dav4android.property;
import android.text.TextUtils;
import android.util.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import at.bitfire.dav4android.Constants;
import at.bitfire.dav4android.Property;
......@@ -52,7 +48,7 @@ public class AddressbookDescription implements Property {
eventType = parser.next();
}
} catch(XmlPullParserException|IOException e) {
Constants.log.error("Couldn't parse <addressbook-description>", e);
Constants.log.log(Level.SEVERE, "Couldn't parse <addressbook-description>", e);
return null;
}
......
......@@ -9,7 +9,6 @@
package at.bitfire.dav4android.property;
import android.text.TextUtils;
import android.util.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
......@@ -17,6 +16,7 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import at.bitfire.dav4android.Constants;
import at.bitfire.dav4android.Property;
......@@ -56,7 +56,7 @@ public class AddressbookHomeSet implements Property {
eventType = parser.next();
}
} catch(XmlPullParserException|IOException e) {
Constants.log.error("Couldn't parse <addressbook-home-set>", e);
Constants.log.log(Level.SEVERE, "Couldn't parse <addressbook-home-set>", e);
return null;
}
......
package at.bitfire.dav4android.property;
import android.util.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -42,7 +41,7 @@ public class CalendarColor implements Property {
eventType = parser.next();
}
} catch(XmlPullParserException|IOException e) {
Log.e(Constants.LOG_TAG, "Couldn't parse <calendar-color>", e);
Constants.log.log(Level.SEVERE, "Couldn't parse <calendar-color>", e);
return null;
}
......@@ -59,7 +58,7 @@ public class CalendarColor implements Property {
int color_alpha = m.group(2) != null ? (Integer.parseInt(m.group(2), 16) & 0xFF) : 0xFF;
color = (color_alpha << 24) | color_rgb;
} else
Constants.log.warn("Couldn't parse color " + davColor + ", ignoring");
Constants.log.warning("Couldn't parse color " + davColor + ", ignoring");
}
return color;
}
......
......@@ -8,12 +8,11 @@
package at.bitfire.dav4android.property;
import android.util.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.logging.Level;
import at.bitfire.dav4android.Constants;
import at.bitfire.dav4android.Property;
......@@ -45,7 +44,7 @@ public class CalendarData implements Property {
int eventType = parser.getEventType();
calendarData.iCalendar = parser.nextText();
} catch(XmlPullParserException|IOException e) {
Log.e(Constants.LOG_TAG, "Couldn't parse <calendar-data>", e);
Constants.log.log(Level.SEVERE, "Couldn't parse <calendar-data>", e);
return null;
}
......
......@@ -8,12 +8,11 @@
package at.bitfire.dav4android.property;
import android.util.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.logging.Level;
import at.bitfire.dav4android.Constants;
import at.bitfire.dav4android.Property;
......@@ -49,7 +48,7 @@ public class CalendarDescription implements Property {
eventType = parser.next();
}
} catch(XmlPullParserException|IOException e) {
Log.e(Constants.LOG_TAG, "Couldn't parse <calendar-description>", e);
Constants.log.log(Level.SEVERE, "Couldn't parse <calendar-description>", e);
return null;
}
......
......@@ -9,7 +9,6 @@
package at.bitfire.dav4android.property;
import android.text.TextUtils;
import android.util.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
......@@ -17,6 +16,7 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import at.bitfire.dav4android.Constants;
import at.bitfire.dav4android.Property;
......@@ -56,7 +56,7 @@ public class CalendarHomeSet implements Property {
eventType = parser.next();
}
} catch(XmlPullParserException|IOException e) {
Log.e(Constants.LOG_TAG, "Couldn't parse <calendar-home-set>", e);
Constants.log.log(Level.SEVERE, "Couldn't parse <calendar-home-set>", e);
return null;
}
......
......@@ -8,12 +8,11 @@
package at.bitfire.dav4android.property;
import android.util.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.logging.Level;
import at.bitfire.dav4android.Constants;