Update after code review comments

- Let client specify the full content type and take default value if the content type
   is null
 - Fixes #7
This commit is contained in:
Giri Dandu 2015-03-25 12:06:34 -04:00
parent 9920b2acdd
commit 871edc668e
3 changed files with 32 additions and 5 deletions

View File

@ -19,7 +19,7 @@ class HookRequest {
private DateTime deliverAfter private DateTime deliverAfter
@JsonProperty @JsonProperty
private String contentTypeParam private String contentType
/** Constructor for Jackson */ /** Constructor for Jackson */
HookRequest() { } HookRequest() { }
@ -28,10 +28,10 @@ class HookRequest {
* Default constructor for creating a simple HookRequest with a URL and the * Default constructor for creating a simple HookRequest with a URL and the
* POST data to be delivered to that URL * POST data to be delivered to that URL
*/ */
HookRequest(String hookUrl, String hookData, String contentTypeParam) { HookRequest(String hookUrl, String hookData, String contentType) {
this.retries = 0 this.retries = 0
this.url = hookUrl this.url = hookUrl
this.postData = hookData this.postData = hookData
this.contentTypeParam = contentTypeParam this.contentType = contentType
} }
} }

View File

@ -13,6 +13,7 @@ import javax.ws.rs.ProcessingException
* request logic for Whoas * request logic for Whoas
*/ */
class Publisher { class Publisher {
private final String DEFAULT_CONTENT_TYPE = 'application/json'
/** Maximum number of failures we will retry on */ /** Maximum number of failures we will retry on */
private final int DEFAULT_MAX_RETRIES = 5 private final int DEFAULT_MAX_RETRIES = 5
@ -102,7 +103,7 @@ class Publisher {
return jerseyClient.target(request.url) return jerseyClient.target(request.url)
.request() .request()
.buildPost(Entity.entity(request.postData, .buildPost(Entity.entity(request.postData,
"application/vnd." + request.contentTypeParam + "+json")) request.contentType? request.contentType: DEFAULT_CONTENT_TYPE))
} }
} }

View File

@ -49,7 +49,33 @@ class PublisherSpec extends Specification {
given: given:
Invocation inv Invocation inv
HookRequest request = new HookRequest('http://example.com', HookRequest request = new HookRequest('http://example.com',
'magic post data!','appname.event1.v1') '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: when:
inv = publisher.buildInvocationFrom(request) inv = publisher.buildInvocationFrom(request)