Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f53ae9e9 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

Make sure DavException is Serializable

parent 83bad4d4
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@

package at.bitfire.dav4android

import java.io.Serializable

/**
 * A WebDAV property.
 *
@@ -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)
+10 −11
Original line number Diff line number Diff line
@@ -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
@@ -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
@@ -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()
+26 −0
Original line number Diff line number Diff line
@@ -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 {

@@ -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)
     */