Skip to content

Commit cb042e3

Browse files
committed
more logs to debug issues in WB
1 parent 8eac786 commit cb042e3

3 files changed

Lines changed: 41 additions & 7 deletions

File tree

core/src/main/kotlin/org/evomaster/core/problem/rest/data/RestPath.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ class RestPath(path: String) {
329329
gene.getViewOfElements()
330330
.joinToString("&") { "$name=${encode(it.getValueAsRawString())}" }
331331
} else {
332-
val value = encode(gene!!.getValueAsRawString())
332+
val value = encode(gene.getValueAsRawString())
333333
"$name=$value"
334334
}
335335
}

core/src/main/kotlin/org/evomaster/core/problem/rest/service/fitness/AbstractRestFitness.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -883,17 +883,31 @@ abstract class AbstractRestFitness : HttpWsFitness<RestIndividual>() {
883883
}
884884

885885

886-
val builder = if (a.produces.isEmpty()) {
887-
log.debug("No 'produces' type defined for {}", path)
888-
client.target(fullUri).request("*/*")
886+
val builder = try {
887+
if (a.produces.isEmpty()) {
888+
log.debug("No 'produces' type defined for {}", path)
889+
client.target(fullUri).request("*/*")
889890

890-
} else {
891-
/*
891+
} else {
892+
/*
892893
TODO: This only considers the first in the list of produced responses
893894
This is fine for endpoints that only produce one type of response.
894895
Could be a problem in future
895896
*/
896-
client.target(fullUri).request(a.produces.first())
897+
client.target(fullUri).request(a.produces.first())
898+
}
899+
} catch (e: Exception) {
900+
/*
901+
FIXME we need to solve this issue somehow, as location values might be invalid...
902+
but i guess that should be done in resolveLocation
903+
*/
904+
throw RuntimeException("""
905+
Failed to build HTTP invocation.
906+
Resolved path: $path
907+
Location header: $locationHeader
908+
Resolved location: $fullUri
909+
Error: ${e.message}
910+
""".trimIndent(), e)
897911
}
898912

899913
handleHeaders(a, builder, cookies, tokens)

core/src/test/kotlin/org/evomaster/core/problem/rest/RestPathTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,33 @@ import org.evomaster.core.search.gene.collection.ArrayGene
1010
import org.evomaster.core.search.gene.wrapper.CustomMutationRateGene
1111
import org.evomaster.core.search.gene.numeric.IntegerGene
1212
import org.evomaster.core.search.gene.string.StringGene
13+
import org.glassfish.jersey.uri.internal.JerseyUriBuilder
1314
import org.junit.jupiter.api.Assertions.*
1415
import org.junit.jupiter.api.Test
1516
import org.junit.jupiter.params.ParameterizedTest
1617
import org.junit.jupiter.params.provider.ValueSource
18+
import java.net.URISyntaxException
19+
import org.junit.jupiter.api.assertThrows
1720

1821
internal class RestPathTest{
1922

23+
@Test
24+
fun testFamilieBaSakIssue(){
25+
26+
val x = "/api/satsendring/kjorsatsendring?EMextraParam123=42/Trigget satsendring for fagsakene []"
27+
28+
assertThrows<Exception>{JerseyUriBuilder.fromUri(x).build()}
29+
30+
val path = RestPath("/api/satsendring/kjorsatsendring")
31+
val q = QueryParam("EMextraParam123", StringGene("EMextraParam123", "42/Trigget satsendring for fagsakene []"))
32+
33+
val uri = path.resolve(listOf(q))
34+
35+
assertNotEquals(x, uri)
36+
37+
JerseyUriBuilder.fromUri(uri).build()
38+
}
39+
2040

2141
@Test
2242
fun testNameQualifier(){

0 commit comments

Comments
 (0)