Skip to content

Commit 2126fd0

Browse files
Add support for notification headers
1 parent f158a37 commit 2126fd0

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

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

+21-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,14 @@ public void setFormat(String format) {
6073
this.format = format;
6174
}
6275

76+
public void setHeaders(Map<String, String> headers) {
77+
this.headers = headers;
78+
}
79+
80+
public Map<String, String> getHeaders() {
81+
return headers;
82+
}
83+
6384
public String toString() {
6485
Element elem;
6586
Document document;
@@ -84,5 +105,4 @@ public String toString() {
84105
}
85106
return this.getClass().getSimpleName();
86107
}
87-
88108
}

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)