Skip to content

Commit 0d2b0c5

Browse files
committed
Merge pull request #29 from laurilehmijoki/master
Add support for headers in notifications.
2 parents f158a37 + 3a77f4e commit 0d2b0c5

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## NEXT
5+
6+
### Added
7+
8+
* Support for [notification headers](https://app.zencoder.com/docs/api/encoding/notifications/notification-headers)
9+
410
## 0.0.1 - 2014-XX-XX
511
### Added
612
- Initial version

pom.xml

+12
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@
141141
<target>1.6</target>
142142
</configuration>
143143
</plugin>
144+
<plugin>
145+
<groupId>org.apache.maven.plugins</groupId>
146+
<artifactId>maven-source-plugin</artifactId>
147+
<executions>
148+
<execution>
149+
<id>attach-sources</id>
150+
<goals>
151+
<goal>jar</goal>
152+
</goals>
153+
</execution>
154+
</executions>
155+
</plugin>
144156
<plugin>
145157
<groupId>org.apache.maven.plugins</groupId>
146158
<artifactId>maven-surefire-plugin</artifactId>

src/main/java/de/bitzeche/video/transcoding/zencoder/job/ZencoderNotification.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@
2727

2828
import de.bitzeche.video.transcoding.zencoder.util.XmlUtility;
2929

30+
import java.util.Map;
31+
3032
public class ZencoderNotification {
3133

3234
private String notificationString;
3335
private String format;
36+
private Map<String, String> headers;
3437

3538
public ZencoderNotification(String notificationDestination) {
3639
this.notificationString = notificationDestination;
@@ -45,6 +48,16 @@ public Element createXML(Document document) {
4548
root.appendChild(nfNode);
4649
}
4750

51+
if (this.headers != null) {
52+
Node headersNode = document.createElement("headers");
53+
root.appendChild(headersNode);
54+
for (Map.Entry<String, String> headerEntry : headers.entrySet()) {
55+
Node header = document.createElement(headerEntry.getKey());
56+
header.setTextContent(headerEntry.getValue());
57+
headersNode.appendChild(header);
58+
}
59+
}
60+
4861
Node urlNode = document.createElement("url");
4962
urlNode.setTextContent(this.notificationString);
5063
root.appendChild(urlNode);
@@ -60,6 +73,17 @@ public void setFormat(String format) {
6073
this.format = format;
6174
}
6275

76+
/**
77+
* @param headers see https://app.zencoder.com/docs/api/encoding/notifications/notification-headers
78+
*/
79+
public void setHeaders(Map<String, String> headers) {
80+
this.headers = headers;
81+
}
82+
83+
public Map<String, String> getHeaders() {
84+
return headers;
85+
}
86+
6387
public String toString() {
6488
Element elem;
6589
Document document;
@@ -84,5 +108,4 @@ public String toString() {
84108
}
85109
return this.getClass().getSimpleName();
86110
}
87-
88111
}

src/test/java/de/bitzeche/video/transcoding/zencoder/test/ZencoderNotificationTest.java

+14
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import de.bitzeche.video.transcoding.zencoder.job.ZencoderNotification;
2525

26+
import java.util.HashMap;
27+
2628
public class ZencoderNotificationTest {
2729

2830
@Test
@@ -42,4 +44,16 @@ public void testWithOptions() throws ParserConfigurationException {
4244
// System.out.println(doc);
4345
Assert.assertEquals(doc, expected);
4446
}
47+
48+
@Test
49+
public void testWithHeaders() throws ParserConfigurationException {
50+
ZencoderNotification notif = new ZencoderNotification("[email protected]");
51+
notif.setHeaders(new HashMap<String, String>(){{
52+
put("cloudfront_url", "http://asdjaosidjas.cloudfront.net");
53+
}});
54+
String doc = StringUtil.stripSpacesAndLineBreaksFrom(notif.toString());
55+
String expected = "<?xmlversion=\"1.0\"encoding=\"UTF-8\"?><notification><headers><cloudfront_url>http://asdjaosidjas.cloudfront.net</cloudfront_url></headers><url>[email protected]</url></notification>";
56+
// System.out.println(doc);
57+
Assert.assertEquals(doc, expected);
58+
}
4559
}

0 commit comments

Comments
 (0)