Class Server


  • public class Server
    extends java.lang.Object
    Class representing the Cloud Office Print server to interact with. This class has a verbose mode.
    • Constructor Summary

      Constructors 
      Constructor Description
      Server​(java.lang.String url)
      Most basic constructor of the server.
      Server​(java.lang.String url, java.lang.String APIKey, Printer printer, Commands commands, com.google.gson.JsonObject loggingInfo, java.lang.String proxyIP, java.lang.Integer proxyPort)
      Use default values if you don't want to specify an argument.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getAPIKey()
      Only applicable for service users.
      Commands getCommands()  
      java.lang.String getCOPVersionOnServer()
      Sends a GET request to server-url/version.
      com.google.gson.JsonObject getJSON()  
      com.google.gson.JsonObject getLoggingInfo()
      When the Cloud Office Print server is started with --enable_printlog, it will create a file on the server called server_printjob.log.
      java.lang.String getMimeTypesSupported()
      Sends a GET request to server-url/supported_template_mimetypes.
      java.lang.String getOfficeToPdfVersion()
      Sends a GET request to server-url/officetopdf.
      java.lang.String getOutputMimeTypesSupported​(java.lang.String extension)
      Sends a GET request to server-url/supported_output_mimetypes?template=extension.
      java.lang.String getPassword()  
      java.lang.String getPrependMimeTypesSupported()
      Sends a GET request to server-url/supported_prepend_mimetypes.
      Printer getPrinter()
      Cloud Office Print supports to print directly to an IP Printer.
      java.lang.String getProxyIP()  
      java.lang.Integer getProxyPort()  
      java.lang.String getSofficeVersionServer()
      Sends a GET request to server-url/soffice.
      java.lang.String getUrl()  
      java.lang.String getUsername()  
      boolean isReachable()
      Sends a GET request to server-url/marco and checks if the answer is polo.
      boolean isVerbose()  
      java.lang.String readJson​(java.lang.String path)
      Function to read a local JSON file.
      java.lang.String sendGETRequest​(java.lang.String urlToJoin)
      Sends a GET request to the url.
      Response sendPOSTRequest​(com.google.gson.JsonObject postData)
      Sends a POST request with the given json file as body.
      void setAPIKey​(java.lang.String APIKey)
      Only applicable for service users.
      void setCommands​(Commands commands)  
      void setLoggingInfo​(com.google.gson.JsonObject loginInfo)
      When the Cloud Office Print server is started with --enable_printlog, it will create a file on the server called server_printjob.log.
      void setPassword​(java.lang.String password)  
      void setPrinter​(Printer printer)
      Cloud Office Print supports to print directly to an IP Printer.
      void setProxyIP​(java.lang.String proxyIP)  
      void setProxyPort​(java.lang.Integer proxyPort)  
      void setUrl​(java.lang.String url)  
      void setUsername​(java.lang.String username)  
      void setVerbose​(boolean verbose)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Server

        public Server​(java.lang.String url)
        Most basic constructor of the server. Can be populated more with the set functions.
        Parameters:
        url - of the Cloud Office Print server.
      • Server

        public Server​(java.lang.String url,
                      java.lang.String APIKey,
                      Printer printer,
                      Commands commands,
                      com.google.gson.JsonObject loggingInfo,
                      java.lang.String proxyIP,
                      java.lang.Integer proxyPort)
        Use default values if you don't want to specify an argument.
        Parameters:
        url - of the Cloud Office Print server
        APIKey - Only applicable for service users. The value of this key is the API key given by Cloud Office Print.
        printer - Cloud Office Print supports to print directly to an IP Printer. Printer object containing the required info for the Cloud Office Print server.
        commands - Commands object with commands for the Cloud Office Print server to run before or after the post processing.
        loggingInfo - When the Cloud Office Print server is started with --enable_printlog, it will create a file on the server called server_printjob.log. Jsonobject with the extra information you want to be logged in that file.
        proxyIP - IP of the optional proxy. Only HTTP proxies supported.
        proxyPort - Port of the optional proxy. Only HTTP proxies supported.
    • Method Detail

      • isVerbose

        public boolean isVerbose()
        Returns:
        Whether to include debug prints or not.
      • setVerbose

        public void setVerbose​(boolean verbose)
        Parameters:
        verbose - Whether to include debug prints or not.
      • getProxyIP

        public java.lang.String getProxyIP()
        Returns:
        IP address of the proxy used, null if not used.
      • setProxyIP

        public void setProxyIP​(java.lang.String proxyIP)
        Parameters:
        proxyIP - IP address of the proxy used, null if not used.
      • getProxyPort

        public java.lang.Integer getProxyPort()
        Returns:
        Port of the proxy used, null if not used.
      • setProxyPort

        public void setProxyPort​(java.lang.Integer proxyPort)
        Parameters:
        proxyPort - Port of the proxy used, null if not used.
      • getAPIKey

        public java.lang.String getAPIKey()
        Only applicable for service users.
        Returns:
        The value of this key is the API key given by Cloud Office Print.
      • setAPIKey

        public void setAPIKey​(java.lang.String APIKey)
        Only applicable for service users.
        Parameters:
        APIKey - given by Cloud Office Print.
      • getLoggingInfo

        public com.google.gson.JsonObject getLoggingInfo()
        When the Cloud Office Print server is started with --enable_printlog, it will create a file on the server called server_printjob.log.
        Returns:
        Jsonobject with the extra information you want to be logged in that file.
      • setLoggingInfo

        public void setLoggingInfo​(com.google.gson.JsonObject loginInfo)
        When the Cloud Office Print server is started with --enable_printlog, it will create a file on the server called server_printjob.log. You can add additional logging information next to the one Cloud Office Print is logging by default, by adding additional keys and values in the logging object.
        Parameters:
        loginInfo - Jsonobject with the information you want to be logged.
      • getUrl

        public java.lang.String getUrl()
        Returns:
        URL of the Cloud Office Print server.
      • setUrl

        public void setUrl​(java.lang.String url)
        Parameters:
        url - of the Cloud Office Print server.
      • getPrinter

        public Printer getPrinter()
        Cloud Office Print supports to print directly to an IP Printer.
        Returns:
        Printer object containing the required info for the Cloud Office Print server.
      • setPrinter

        public void setPrinter​(Printer printer)
        Cloud Office Print supports to print directly to an IP Printer.
        Parameters:
        printer - Printer object containing the required info for the Cloud Office Print server.
      • getCommands

        public Commands getCommands()
        Returns:
        Commands object with commands for the Cloud Office Print server to run before or after the post processing.
      • setCommands

        public void setCommands​(Commands commands)
        Parameters:
        commands - Commands object with commands for the Cloud Office Print server to run before or after the post processing.
      • getUsername

        public java.lang.String getUsername()
        Returns:
        Username for the proxy authentication.
      • setUsername

        public void setUsername​(java.lang.String username)
        Parameters:
        username - Username for the proxy authentication.
      • getPassword

        public java.lang.String getPassword()
        Returns:
        Password for the proxy authentication.
      • setPassword

        public void setPassword​(java.lang.String password)
        Parameters:
        password - Password for the proxy authentication.
      • getJSON

        public com.google.gson.JsonObject getJSON()
        Returns:
        JSONObject with the tags for the output for the Cloud Office Print server.
      • isReachable

        public boolean isReachable()
        Sends a GET request to server-url/marco and checks if the answer is polo.
        Returns:
        true if the server is reachable.
      • getSofficeVersionServer

        public java.lang.String getSofficeVersionServer()
        Sends a GET request to server-url/soffice.
        Returns:
        current version of Libreoffice installed on the server.
      • getOfficeToPdfVersion

        public java.lang.String getOfficeToPdfVersion()
        Sends a GET request to server-url/officetopdf.
        Returns:
        current version of OfficeToPdf installed on the server. (Only available if the server runs in Windows environment).
      • getMimeTypesSupported

        public java.lang.String getMimeTypesSupported()
        Sends a GET request to server-url/supported_template_mimetypes.
        Returns:
        json of the mime types of templates that Cloud Office Print supports.
      • getOutputMimeTypesSupported

        public java.lang.String getOutputMimeTypesSupported​(java.lang.String extension)
        Sends a GET request to server-url/supported_output_mimetypes?template=extension. Note: You will get empty json if the template extension isn't supported.
        Parameters:
        extension - Template extension.
        Returns:
        The supported output types for the given template extension.
      • getPrependMimeTypesSupported

        public java.lang.String getPrependMimeTypesSupported()
        Sends a GET request to server-url/supported_prepend_mimetypes.
        Returns:
        returns the supported prepend file mime types in JSON format.
      • getCOPVersionOnServer

        public java.lang.String getCOPVersionOnServer()
        Sends a GET request to server-url/version.
        Returns:
        returns the version of Cloud Office Print that is run on server.
      • sendGETRequest

        public java.lang.String sendGETRequest​(java.lang.String urlToJoin)
        Sends a GET request to the url.
        Parameters:
        urlToJoin - URL to send the GET request to.
        Returns:
        body of the response of the request.
      • sendPOSTRequest

        public Response sendPOSTRequest​(com.google.gson.JsonObject postData)
                                 throws java.lang.Exception
        Sends a POST request with the given json file as body.
        Parameters:
        postData - json to send to the server
        Returns:
        Response object containing the file extension and body (in bytes)
        Throws:
        COPException - when server response's code is not equal to 200.
        java.lang.Exception
      • readJson

        public java.lang.String readJson​(java.lang.String path)
                                  throws java.io.FileNotFoundException
        Function to read a local JSON file.
        Parameters:
        path - Local path of the file.
        Returns:
        String of the json.
        Throws:
        java.io.FileNotFoundException - If the file is not found.