-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from sinch/DEVEXP-546-Voice-E2E
Voice E2E
- Loading branch information
Showing
12 changed files
with
882 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
client/src/test/java/com/sinch/sdk/e2e/domains/WebhooksHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.sinch.sdk.e2e.domains; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
public class WebhooksHelper { | ||
|
||
public static <T> Response<T> callURL(URL url, Function<String, T> parseEvent) | ||
throws IOException { | ||
|
||
HttpURLConnection con = (HttpURLConnection) url.openConnection(); | ||
con.setRequestMethod("GET"); | ||
|
||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
|
||
byte[] buffer = new byte[1024]; | ||
int bytesRead; | ||
try (InputStream inputStream = con.getInputStream()) { | ||
while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
} | ||
} | ||
|
||
Response<T> response = new Response<>(); | ||
response.headers = transformHeaders(con.getHeaderFields()); | ||
response.rawPayload = byteArrayOutputStream.toString("UTF-8"); | ||
response.event = parseEvent.apply(response.rawPayload); | ||
return response; | ||
} | ||
|
||
static Map<String, String> transformHeaders(Map<String, List<String>> headers) { | ||
if (null == headers) { | ||
return null; | ||
} | ||
HashMap<String, String> newMap = new HashMap<>(); | ||
headers.forEach((key, value) -> newMap.put(key, String.join(";", value))); | ||
return newMap; | ||
} | ||
|
||
public static class Response<T> { | ||
public Map<String, String> headers; | ||
public String rawPayload; | ||
public T event; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.