private InputStream connect(String urlPath, String requestMethod, Object data) {
        
        if (!isInitialized()) {
            Logger.getLogger(Communicator.class.getName()).log(Level.SEVERE, "Communicator has not been initialized.");
        }
        
        Object result = null;
        try {
            // Build URL
            URL url = new URL(protocol, host, port, urlPath);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestMethod(requestMethod);

            connection.connect();
            
            // Serialize parameters
            if (requestMethod.equalsIgnoreCase("POST")) {
                try (BufferedOutputStream out = new BufferedOutputStream(connection.getOutputStream())) {
                    xstream.toXML(data, out);
                }
            }
            if (!requestMethod.equalsIgnoreCase("POST") && !requestMethod.equalsIgnoreCase("GET")) {
                return null;
            }
            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
                return in;
            }
            else {
                Logger.getLogger(Communicator.class.getName()).log(
                        Level.WARNING, String.format("Request failed with response code %d", connection.getResponseCode()));
            }
        }
        catch (IOException ex) {
            Logger.getLogger(Communicator.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }