-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lapis2): support url encoded form POST requests
This adds support for using LAPIS via plain HTML forms with `method="POST"` and content type `application/x-www-form-urlencoded` resolves #754
- Loading branch information
1 parent
ac1d719
commit f2f62b1
Showing
24 changed files
with
1,286 additions
and
705 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
lapis2/src/main/kotlin/org/genspectrum/lapis/controller/JacksonFormHttpMessageConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.genspectrum.lapis.controller | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import org.genspectrum.lapis.util.tryToGuessTheType | ||
import org.springframework.http.HttpInputMessage | ||
import org.springframework.http.HttpOutputMessage | ||
import org.springframework.http.MediaType | ||
import org.springframework.http.converter.AbstractHttpMessageConverter | ||
import org.springframework.http.converter.FormHttpMessageConverter | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class JacksonFormHttpMessageConverter( | ||
private val objectMapper: ObjectMapper, | ||
) : AbstractHttpMessageConverter<Any>(MediaType.APPLICATION_FORM_URLENCODED) { | ||
private val formHttpMessageConverter = FormHttpMessageConverter() | ||
|
||
override fun canWrite( | ||
clazz: Class<*>, | ||
mediaType: MediaType?, | ||
): Boolean { | ||
return false | ||
} | ||
|
||
override fun supports(clazz: Class<*>): Boolean { | ||
return true | ||
} | ||
|
||
override fun writeInternal( | ||
t: Any, | ||
outputMessage: HttpOutputMessage, | ||
) { | ||
throw NotImplementedError("This class should never need to write.") | ||
} | ||
|
||
override fun readInternal( | ||
clazz: Class<out Any>, | ||
inputMessage: HttpInputMessage, | ||
): Any { | ||
val multiValueMap = formHttpMessageConverter.read(null, inputMessage) | ||
|
||
val mapValues = multiValueMap.mapValues(::tryToGuessTheType) | ||
|
||
val json = objectMapper.writeValueAsString(mapValues) | ||
|
||
return objectMapper.readValue(json, clazz) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.