Merge pull request #24 from GiriDandu/issue-7-hook-request-should-allow-support-for-content-type

Allow whoas clients to specify the content type param for each hook request
This commit is contained in:
R. Tyler Croy 2015-03-25 10:56:09 -07:00
commit b4e84f04f5
4 changed files with 35 additions and 7 deletions

View File

@ -18,6 +18,9 @@ class HookRequest {
@JsonProperty
private DateTime deliverAfter
@JsonProperty
private String contentType
/** 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 contentType) {
this.retries = 0
this.url = hookUrl
this.postData = hookData
this.contentType = contentType
}
}

View File

@ -21,12 +21,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 +103,7 @@ class Publisher {
return jerseyClient.target(request.url)
.request()
.buildPost(Entity.entity(request.postData,
this.contentType))
request.contentType? request.contentType: DEFAULT_CONTENT_TYPE))
}
}

View File

@ -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,33 @@ class PublisherSpec extends Specification {
given:
Invocation inv
HookRequest request = new HookRequest('http://example.com',
'magic post data!')
'magic post data!','application/vnd.appname.event1.v1+json')
when:
inv = publisher.buildInvocationFrom(request)
then:
inv instanceof Invocation
}
def "buildInvocationFrom() should create a valid Jersey Invocation when content type is null"() {
given:
Invocation inv
HookRequest request = new HookRequest('http://example.com',
'magic post data!', null)
when:
inv = publisher.buildInvocationFrom(request)
then:
inv instanceof Invocation
}
def "buildInvocationFrom() should create a valid Jersey Invocation when content type is empty"() {
given:
Invocation inv
HookRequest request = new HookRequest('http://example.com',
'magic post data!', '')
when:
inv = publisher.buildInvocationFrom(request)

View File

@ -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!