mirror of https://github.com/reiseburo/whoas
Allow whoas clients to specify the content type param for each hook request
- Fixes #7
This commit is contained in:
parent
f5899bac39
commit
9920b2acdd
|
@ -18,6 +18,9 @@ class HookRequest {
|
|||
@JsonProperty
|
||||
private DateTime deliverAfter
|
||||
|
||||
@JsonProperty
|
||||
private String contentTypeParam
|
||||
|
||||
/** Constructor for Jackson */
|
||||
HookRequest() { }
|
||||
|
||||
|
@ -25,9 +28,10 @@ class HookRequest {
|
|||
* Default constructor for creating a simple HookRequest with a URL and the
|
||||
* POST data to be delivered to that URL
|
||||
*/
|
||||
HookRequest(String hookUrl, String hookData) {
|
||||
HookRequest(String hookUrl, String hookData, String contentTypeParam) {
|
||||
this.retries = 0
|
||||
this.url = hookUrl
|
||||
this.postData = hookData
|
||||
this.contentTypeParam = contentTypeParam
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import javax.ws.rs.ProcessingException
|
|||
* request logic for Whoas
|
||||
*/
|
||||
class Publisher {
|
||||
private final String DEFAULT_CONTENT_TYPE = 'application/json'
|
||||
/** Maximum number of failures we will retry on */
|
||||
private final int DEFAULT_MAX_RETRIES = 5
|
||||
|
||||
|
@ -21,12 +20,10 @@ class Publisher {
|
|||
private final int DEFAULT_BACKOFF_MAX_MILLIS = (10 * 1000)
|
||||
|
||||
private Client jerseyClient
|
||||
private String contentType
|
||||
private int maxRetries
|
||||
|
||||
Publisher() {
|
||||
this.jerseyClient = ClientBuilder.newClient()
|
||||
this.contentType = DEFAULT_CONTENT_TYPE
|
||||
this.maxRetries = DEFAULT_MAX_RETRIES
|
||||
}
|
||||
|
||||
|
@ -105,7 +102,7 @@ class Publisher {
|
|||
return jerseyClient.target(request.url)
|
||||
.request()
|
||||
.buildPost(Entity.entity(request.postData,
|
||||
this.contentType))
|
||||
"application/vnd." + request.contentTypeParam + "+json"))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class PublisherSpec extends Specification {
|
|||
def "publish() to a invalid host should fail"() {
|
||||
given:
|
||||
publisher = Spy(Publisher)
|
||||
HookRequest req = new HookRequest('http://spock.invalid', '')
|
||||
HookRequest req = new HookRequest('http://spock.invalid', '', '')
|
||||
/* stub out the original backoffSleep so we don't actually sleep our
|
||||
* tests */
|
||||
_ * publisher.backoffSleep(_) >> null
|
||||
|
@ -49,7 +49,7 @@ class PublisherSpec extends Specification {
|
|||
given:
|
||||
Invocation inv
|
||||
HookRequest request = new HookRequest('http://example.com',
|
||||
'magic post data!')
|
||||
'magic post data!','appname.event1.v1')
|
||||
|
||||
when:
|
||||
inv = publisher.buildInvocationFrom(request)
|
||||
|
|
|
@ -19,7 +19,7 @@ class SequentialHookRunnerSpec extends Specification {
|
|||
given:
|
||||
Publisher p = Mock(Publisher)
|
||||
SequentialHookRunner runner = new SequentialHookRunner(queue, p)
|
||||
HookRequest request = new HookRequest('http://spock.invalid', '{}')
|
||||
HookRequest request = new HookRequest('http://spock.invalid', '{}', '')
|
||||
1 * p.publish(request) >> {
|
||||
/* when the publisher is called, let's disable our runner's runloop
|
||||
* so we actually exit the test!
|
||||
|
|
Loading…
Reference in New Issue