Loading src/main/java/at/bitfire/dav4android/Property.kt +3 −1 Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ package at.bitfire.dav4android import java.io.Serializable /** * A WebDAV property. * Loading @@ -17,7 +19,7 @@ interface Property { class Name( val namespace: String, val name: String ) { ): Serializable { override fun equals(other: Any?): Boolean { return if (other is Name) Loading src/main/java/at/bitfire/dav4android/exception/DavException.kt +10 −11 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ import at.bitfire.dav4android.Constants import at.bitfire.dav4android.Property import at.bitfire.dav4android.XmlUtils import okhttp3.MediaType import okhttp3.Request import okhttp3.Response import okio.Buffer import org.xmlpull.v1.XmlPullParser Loading Loading @@ -46,16 +45,16 @@ open class DavException @JvmOverloads constructor( } var request: Request? = null private set var requestBody: String? = null private set var request: String? = null /** * Associated HTTP [Response]. Do not access [Response.body] because it will be closed. * Use [responseBody] instead. * Body excerpt of [request] (up to [MAX_EXCERPT_SIZE] characters). Only available * if the HTTP request body was textual content and could be read again. */ val response: Response? var requestBody: String? = null private set val response: String? /** * Body excerpt of [response] (up to [MAX_EXCERPT_SIZE] characters). Only available Loading @@ -73,12 +72,12 @@ open class DavException @JvmOverloads constructor( init { if (httpResponse != null) { response = httpResponse response = httpResponse.toString() try { request = httpResponse.request() request = httpResponse.request().toString() request?.body()?.let { body -> httpResponse.request().body()?.let { body -> body.contentType()?.let { if (isPlainText(it)) { val buffer = Buffer() Loading src/test/java/at/bitfire/dav4android/exception/DavExceptionTest.kt +26 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,10 @@ import org.junit.After import org.junit.Assert.* import org.junit.Before import org.junit.Test import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.io.ObjectInputStream import java.io.ObjectOutputStream class DavExceptionTest { Loading Loading @@ -83,6 +87,28 @@ class DavExceptionTest { } } fun testSerialization() { val url = sampleUrl() val dav = DavResource(httpClient, url) mockServer.enqueue(MockResponse() .setResponseCode(500) .setBody("12345")) try { dav.propfind(0, ResourceType.NAME).close() fail("Expected DavException") } catch (e: DavException) { val baos = ByteArrayOutputStream() val oos = ObjectOutputStream(baos) oos.writeObject(e) val ois = ObjectInputStream(ByteArrayInputStream(baos.toByteArray())) val e2 = ois.readObject() as HttpException assertEquals(500, e2.code) assertTrue(e2.responseBody!!.contains("12345")) } } /** * Test precondition XML element (sample from RFC 4918 16) */ Loading Loading
src/main/java/at/bitfire/dav4android/Property.kt +3 −1 Original line number Diff line number Diff line Loading @@ -6,6 +6,8 @@ package at.bitfire.dav4android import java.io.Serializable /** * A WebDAV property. * Loading @@ -17,7 +19,7 @@ interface Property { class Name( val namespace: String, val name: String ) { ): Serializable { override fun equals(other: Any?): Boolean { return if (other is Name) Loading
src/main/java/at/bitfire/dav4android/exception/DavException.kt +10 −11 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ import at.bitfire.dav4android.Constants import at.bitfire.dav4android.Property import at.bitfire.dav4android.XmlUtils import okhttp3.MediaType import okhttp3.Request import okhttp3.Response import okio.Buffer import org.xmlpull.v1.XmlPullParser Loading Loading @@ -46,16 +45,16 @@ open class DavException @JvmOverloads constructor( } var request: Request? = null private set var requestBody: String? = null private set var request: String? = null /** * Associated HTTP [Response]. Do not access [Response.body] because it will be closed. * Use [responseBody] instead. * Body excerpt of [request] (up to [MAX_EXCERPT_SIZE] characters). Only available * if the HTTP request body was textual content and could be read again. */ val response: Response? var requestBody: String? = null private set val response: String? /** * Body excerpt of [response] (up to [MAX_EXCERPT_SIZE] characters). Only available Loading @@ -73,12 +72,12 @@ open class DavException @JvmOverloads constructor( init { if (httpResponse != null) { response = httpResponse response = httpResponse.toString() try { request = httpResponse.request() request = httpResponse.request().toString() request?.body()?.let { body -> httpResponse.request().body()?.let { body -> body.contentType()?.let { if (isPlainText(it)) { val buffer = Buffer() Loading
src/test/java/at/bitfire/dav4android/exception/DavExceptionTest.kt +26 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,10 @@ import org.junit.After import org.junit.Assert.* import org.junit.Before import org.junit.Test import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.io.ObjectInputStream import java.io.ObjectOutputStream class DavExceptionTest { Loading Loading @@ -83,6 +87,28 @@ class DavExceptionTest { } } fun testSerialization() { val url = sampleUrl() val dav = DavResource(httpClient, url) mockServer.enqueue(MockResponse() .setResponseCode(500) .setBody("12345")) try { dav.propfind(0, ResourceType.NAME).close() fail("Expected DavException") } catch (e: DavException) { val baos = ByteArrayOutputStream() val oos = ObjectOutputStream(baos) oos.writeObject(e) val ois = ObjectInputStream(ByteArrayInputStream(baos.toByteArray())) val e2 = ois.readObject() as HttpException assertEquals(500, e2.code) assertTrue(e2.responseBody!!.contains("12345")) } } /** * Test precondition XML element (sample from RFC 4918 16) */ Loading