Skip to content

Commit

Permalink
Adding helper classes to consume Twistage import API and ingesting si…
Browse files Browse the repository at this point in the history
…gnature
  • Loading branch information
AnanyaBanerjee01 committed Sep 8, 2021
1 parent 388e4d8 commit cc83eab
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public String getNotification() {

@PostMapping
public ResponseEntity<String> onRecordingCompleted(@RequestBody String requestBody, @RequestHeader(value = WebHookConstants.HOST) String host, @RequestHeader(value = WebHookConstants.USER_AGENT) String userAgent, @RequestHeader(value = WebHookConstants.AUTHORIZATION) String authToken) {
log.info("#### Incoming Webhook Notification from Zoom API ##### {}", requestBody);
ObjectMapper mapper = new ObjectMapper();
log.debug("#### Incoming Webhook Notification from Zoom API ##### {}", requestBody);
log.debug("#### Request Header Information ##### Host :: User Agent :: {} {} ", host, userAgent);

try {
Expand All @@ -38,12 +37,16 @@ public ResponseEntity<String> onRecordingCompleted(@RequestBody String requestBo
return new ResponseEntity<>(requestBody, HttpStatus.FORBIDDEN);
}
//Convert JSON object to Java POJO
ObjectMapper mapper = new ObjectMapper();
RecordingCompletedSchema recordingObject = mapper.readValue(requestBody, RecordingCompletedSchema.class);
log.debug("Converted Json Payload to Object");

// Validate if the event notification is for Recording Completed event subscribed
if (recordingObject.getEvent().equals(WebHookConstants.RECORDING_COMPLETED)) {
log.debug("Recording Completed Event Payload {} ::", recordingObject);
String contributor = "admin";
String library = "XXXX";
String licenseKey = "XXXX";

}

Expand Down
61 changes: 61 additions & 0 deletions src/main/java/com/hyland/webhook/helper/AuthenticationHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.hyland.webhook.helper;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class AuthenticationHelper {

private AuthenticationHelper(){
}

protected static String getViewSignature(String licenseKey) {
return fetch ("https://indiaservice.twistage.com/api/view_key?licenseKey=" +
licenseKey).trim();
}

protected static String getIngestSignature(String licenseKey, String contributor, String library) {
return fetch ("https://indiaservice.twistage.com/api/ingest_key?licenseKey=" +
licenseKey + "&contributor=" + contributor + "&library_id=" + library).trim();
}

protected static String fetch(String url) {
try {
Object content = createUrl(url).getContent();
if (content instanceof String) {
return (String) content;
} else if (content instanceof InputStream) {
return getInputStreamContents((InputStream) content);
} else {
throw new RuntimeException ("Unexpected content returned from URL: " +
content.toString());
}
} catch (IOException e) {
throw new RuntimeException (e);
}
}

protected static URL createUrl(String url) {
try {
return new URL(url);
} catch (MalformedURLException e) {
throw new RuntimeException (e);
}
}

protected static String getInputStreamContents(InputStream inputStream) throws IOException {
StringBuilder contents = new StringBuilder();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) {
String line = null;
while ((line = bufferedReader.readLine()) != null) {
contents.append(line);
contents.append(System.getProperty("line.separator"));
}
}
return contents.toString();
}

}
46 changes: 46 additions & 0 deletions src/main/java/com/hyland/webhook/helper/ImportHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.hyland.webhook.helper;

import java.io.*;
import java.net.HttpURLConnection;

import static com.hyland.webhook.helper.AuthenticationHelper.*;

public class ImportHelper {

protected String upload (String licenseKey, String contributor, String library,
String pathOfXmlFile)
throws IOException {

String xml = getInputStreamContents (new FileInputStream(new File (pathOfXmlFile)));

String auth = getIngestSignature(licenseKey, contributor, library);

String url = "https://indiaservice.twistage.com/videos/create_many?signature=" + auth;

InputStream inputStream = new ByteArrayInputStream(xml.getBytes());

HttpURLConnection conn = (HttpURLConnection) createUrl(url).openConnection();

conn.setDoInput (true);
conn.setDoOutput (true);
conn.setUseCaches (false);

conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "text/xml");

BufferedInputStream bufferedInput = new BufferedInputStream(inputStream);
BufferedOutputStream bufferedOutput = new BufferedOutputStream(conn.getOutputStream());

int nextByte;
while ((nextByte = bufferedInput.read ()) != -1) {
bufferedOutput.write (nextByte);
}

bufferedOutput.flush ();
bufferedOutput.close ();

// read the server's response
return getInputStreamContents (conn.getInputStream());
}

}
3 changes: 2 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
zoom.verification.token=pZwChq6bS5KstopcfycnDA
logging.level.org.springframework.security: DEBUG
logging.level.org.springframework.security= DEBUG
twistage.api.licenseKey=2f5752b1a0d1a

0 comments on commit cc83eab

Please sign in to comment.