Interface InternetAccess

  • All Known Implementing Classes:
    StandardInternetAccess, TeaInternetAccess

    public interface InternetAccess
    Interface for the platform-specific mechanism used to access the internet. To prevent blocking the application, HTTP requests are sent asynchronous and a callback function is invoked once the response has been received.

    Note that only a limited subset of HTTP requests is supported, as not all features to customize requests are supported on all platforms. Moreover, the response is always returned as plain text. Parsing or mapping the response, for example from JSON to Java classes, tends to rely on reflection which is not available on some platforms. Applications must therefore parse the response manually.

    Requests sent using this class will add the X-Requested-With: MultimediaLib header. This can be used by the server to identify requests originating from MultimediaLib applications.

    In addition to regular HTTP requests, this class also supports web socket connections. However, unlike regular HTTP requests this may not be supported on all platforms.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      WebSocketConnection connectWebSocket​(java.lang.String uri)
      Connects to the web socket located at the specified URI.
      nl.colorize.util.Promise<java.lang.String> get​(java.lang.String url, nl.colorize.util.http.Headers headers)
      Sends a HTTP GET request to the specified URL.
      boolean isWebSocketSupported()  
      nl.colorize.util.Promise<java.lang.String> post​(java.lang.String url, nl.colorize.util.http.Headers headers, nl.colorize.util.http.PostData body)
      Sends a HTTP POST request to the specified URL.
    • Method Detail

      • get

        nl.colorize.util.Promise<java.lang.String> get​(java.lang.String url,
                                                       nl.colorize.util.http.Headers headers)
        Sends a HTTP GET request to the specified URL.
        Returns:
        A Promise that can be used to process the response once it has been received.
      • post

        nl.colorize.util.Promise<java.lang.String> post​(java.lang.String url,
                                                        nl.colorize.util.http.Headers headers,
                                                        nl.colorize.util.http.PostData body)
        Sends a HTTP POST request to the specified URL. The request body will be encoded using the application/x-www-form-urlencoded content type.
        Returns:
        A Promise that can be used to process the response once it has been received.
      • isWebSocketSupported

        boolean isWebSocketSupported()
      • connectWebSocket

        WebSocketConnection connectWebSocket​(java.lang.String uri)
        Connects to the web socket located at the specified URI. Note that some platforms may only allow the secure web socket protocol (i.e. "wss://").
        Throws:
        java.lang.UnsupportedOperationException - if the platform does not support web sockets.