diff --git a/src/main/groovy/com/github/lookout/whoas/HookRequest.groovy b/src/main/groovy/com/github/lookout/whoas/HookRequest.groovy index 0a6d6b8..850b750 100644 --- a/src/main/groovy/com/github/lookout/whoas/HookRequest.groovy +++ b/src/main/groovy/com/github/lookout/whoas/HookRequest.groovy @@ -19,7 +19,7 @@ class HookRequest { private DateTime deliverAfter @JsonProperty - private String contentTypeParam + private String contentType /** Constructor for Jackson */ HookRequest() { } @@ -28,10 +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, String contentTypeParam) { + HookRequest(String hookUrl, String hookData, String contentType) { this.retries = 0 this.url = hookUrl this.postData = hookData - this.contentTypeParam = contentTypeParam + this.contentType = contentType } } diff --git a/src/main/groovy/com/github/lookout/whoas/Publisher.groovy b/src/main/groovy/com/github/lookout/whoas/Publisher.groovy index 216d3b5..5a3b6ef 100644 --- a/src/main/groovy/com/github/lookout/whoas/Publisher.groovy +++ b/src/main/groovy/com/github/lookout/whoas/Publisher.groovy @@ -13,6 +13,7 @@ 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 @@ -102,7 +103,7 @@ class Publisher { return jerseyClient.target(request.url) .request() .buildPost(Entity.entity(request.postData, - "application/vnd." + request.contentTypeParam + "+json")) + request.contentType? request.contentType: DEFAULT_CONTENT_TYPE)) } } diff --git a/src/test/groovy/com/github/lookout/whoas/PublisherSpec.groovy b/src/test/groovy/com/github/lookout/whoas/PublisherSpec.groovy index d0cf1fe..d7d505d 100644 --- a/src/test/groovy/com/github/lookout/whoas/PublisherSpec.groovy +++ b/src/test/groovy/com/github/lookout/whoas/PublisherSpec.groovy @@ -49,7 +49,33 @@ class PublisherSpec extends Specification { given: Invocation inv 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: inv = publisher.buildInvocationFrom(request)