com.isomorphic.rpc

## Class BuiltinRPC

- java.lang.Object
- - com.isomorphic.base.Base
  - - com.isomorphic.rpc.BuiltinRPC

- Direct Known Subclasses:
    BuiltinRPC

      public class BuiltinRPC
      extends Base

  This class implements a set of "built-in" RPC methods that are available to all applications as part of all standard SmartClient distributions. Most of these methods should not be callable from the client in a production setting. By default, all of these are enabled in the smartclientSDK and only the methods flagged as enabled in smartclientRuntime are enabled there by default.

  You can control which methods are enabled by listing the enabled methods under the server.properties attribute `RPCManager.enabledBuiltinMethods`.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static RPCResponse` | `appendToFile(java.lang.String path, java.lang.String data)` Appends the supplied contents to a file under webroot.
    `static RPCResponse` | `deleteFile(java.lang.String path)` Deletes an arbitrary file under webRoot.
    `static void` | `downloadClientContent(java.lang.String fileContents, java.lang.String fileName, java.lang.String mimeType, RPCManager rpc, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Accepts string content and streams it back as a file to the requester via content-disposition: attachment.
    `static void` | `downloadClientExport(java.util.List records, java.lang.String exportAs, java.lang.String fileName, java.lang.String exportDisplay, java.util.Map settings, javax.servlet.http.HttpServletResponse response, RPCManager rpc, RPCRequest request)` Accepts a List of formatted Record-data, exports it to the specified format and streams it back as a file with the specified fileName to the requester via content-disposition: attachment.
    `static void` | `downloadWSDL(java.lang.String url, java.lang.String format, java.lang.String fileName, RPCManager rpc, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Loads a WSDL file from the specified URL, optionally translates it to SmartClient-compatible JS format and streams the file back to the requester via content-disposition: attachment.
    `static void` | `downloadZip(java.util.Map settings, RPCManager rpc, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` This method is used by the Export Project feature in Visual Builder.
    `static RPCResponse` | `evalJava(java.lang.String javaCode, RequestContext context)` This method is used by the "Evaluate Java" section of the Developer Console (in the Results tab).
    `static java.util.Collection` | `getLogEntries(java.lang.String logName)` Returns the contents of the specified log4j log.
    `static java.util.List` | `getLogNames()` Returns the list of available log4j log names.
    `static RPCResponse` | `loadFile(java.lang.String path)` Returns the contents of any file under webRoot as a String.
    `static RPCResponse` | `loadSharedXML(java.lang.String type, java.lang.String ID)` Load a DS, UI, or APP file from the standard search path.
    `static RPCResponse` | `ping()` Convenience method for pinging the server to check whether it's alive.
    `static RPCResponse` | `saveFile(java.lang.String path, java.lang.String data)` Saves a file under webRoot with the supplied contents.
    `static RPCResponse` | `saveSharedXML(java.lang.String type, java.lang.String ID, java.lang.String contents)` Writes or overwrites a UI, DS or APP file with the provided contents.
    `static RPCResponse` | `uploadProgressCheck(javax.servlet.http.HttpSession session, java.lang.String formID)` Used by the FileUpload control to periodically check the progress of a file upload.
    `static RPCResponse` | `xmlToJS(java.lang.String xmlString, RPCRequest req)` Translates XML to JS in exactly the same fashion as done by the <isomorphicXML> JSP tag.

- - ### Method Detail

    - #### downloadWSDL

          public static void downloadWSDL(java.lang.String url,
                                          java.lang.String format,
                                          java.lang.String fileName,
                                          RPCManager rpc,
                                          javax.servlet.http.HttpServletRequest request,
                                          javax.servlet.http.HttpServletResponse response)
                                   throws java.lang.Exception

      Loads a WSDL file from the specified URL, optionally translates it to SmartClient-compatible JS format and streams the file back to the requester via content-disposition: attachment.

      This method is used by the Download feature of the WSDL tab in the Developer Console.

      Parameters:
        `url` - The URL from which to load the WSDL file. Can be relative or absolute.
        `format` - Set to 'xml' to stream the file without translation to JS or 'js' to get translated output.
        `fileName` - This method returns a stream with content-disposition: attachment. This argument specifies the default filename that will be shown to the user in the "save as" dialog that comes up in the browser.
      Throws:
        `java.lang.Exception`

    - #### downloadClientContent

          public static void downloadClientContent(java.lang.String fileContents,
                                                   java.lang.String fileName,
                                                   java.lang.String mimeType,
                                                   RPCManager rpc,
                                                   javax.servlet.http.HttpServletRequest request,
                                                   javax.servlet.http.HttpServletResponse response)
                                            throws java.lang.Exception

      Accepts string content and streams it back as a file to the requester via content-disposition: attachment.

      This method is used by the Download feature of the DataSourceList in Visual Builder.

      Parameters:
        `fileContents` - The string data to return in a file for saving.
        `fileName` - This method returns a stream with content-disposition: attachment. This argument specifies the default filename that will be shown to the user in the "save as" dialog that comes up in the browser.
        `mimeType` - The MIME type with which to save the fileContents
      Throws:
        `java.lang.Exception`

    - #### downloadZip

          public static void downloadZip(java.util.Map settings,
                                         RPCManager rpc,
                                         javax.servlet.http.HttpServletRequest request,
                                         javax.servlet.http.HttpServletResponse response)
                                  throws java.lang.Exception

      This method is used by the Export Project feature in Visual Builder.
      Parameters:
        `settings` - data to export
      Throws:
        `java.lang.Exception`

    - #### xmlToJS

          public static RPCResponse xmlToJS(java.lang.String xmlString,
                                            RPCRequest req)
                                     throws java.lang.Exception

      Translates XML to JS in exactly the same fashion as done by the <isomorphicXML> JSP tag.

      This method is enabled by default in smartclientRuntime

      Parameters:
        `xmlString` - String of XML to be translated to JS.
      Returns:
        The 'data' payload of the RPCResponse is a String containing the translated result. If an error occurs, status is set to STATUS_FAILURE and 'data' contains the error string.
      Throws:
        `java.lang.Exception`

    - #### ping

          public static RPCResponse ping()
                                  throws java.lang.Exception

      Convenience method for pinging the server to check whether it's alive.
      Returns:
        RPCResponse containing the number 1 as data
      Throws:
        `java.lang.Exception`

    - #### uploadProgressCheck

          public static RPCResponse uploadProgressCheck(javax.servlet.http.HttpSession session,
                                                        java.lang.String formID)
                                                 throws java.lang.Exception

      Used by the FileUpload control to periodically check the progress of a file upload.

      This method is enabled by default in smartclientRuntime

      Parameters:
        `formID` - The ID of the form uploading the file.
      Returns:
        The 'data' payload of the RPCResponse is a Map that contains two attributes: bytesSoFar and totalBytes. If an error occurs, status is set to STATUS_FAILURE and 'data' contains the error string.
      Throws:
        `java.lang.Exception`

    - #### deleteFile

          public static RPCResponse deleteFile(java.lang.String path)
                                        throws java.lang.Exception

      Deletes an arbitrary file under webRoot.

      This method is used by the Visual Builder tool.

      Parameters:
        `path` - file to delete, must be relative to webRoot.
      Returns:
        an RPCResponse with STATUS_SUCCESS if successful, STATUS_FAILURE with 'data' set to the error string otherwise.
      Throws:
        `java.lang.Exception`

    - #### saveFile

          public static RPCResponse saveFile(java.lang.String path,
                                             java.lang.String data)
                                      throws java.lang.Exception

      Saves a file under webRoot with the supplied contents.

      This method is used by the Visual Builder tool.

      You can use SKUploadSaveFile datasource for the purpose of saving files. This datasource uses saveFile method so be sure it is enabled in RPCManager.enabledBuiltinMethods property. You can upload files using the datasource with the help of add operation.

      Parameters:
        `path` - location of new file, must be relative to webRoot
        `data` - contents of new file
      Returns:
        an RPCResponse with STATUS_SUCCESS if successful, STATUS_FAILURE with 'data' set to the error string otherwise.
      Throws:
        `java.lang.Exception`

    - #### appendToFile

          public static RPCResponse appendToFile(java.lang.String path,
                                                 java.lang.String data)
                                          throws java.lang.Exception

      Appends the supplied contents to a file under webroot. If the file does not exist, this method is the same as saveFile.
      Parameters:
        `path` - location of file, must be relative to webRoot
        `data` - text to append to file
      Returns:
        an RPCResponse with STATUS_SUCCESS if successful, STATUS_FAILURE with 'data' set to the error string otherwise.
      Throws:
        `java.lang.Exception`

    - #### loadFile

          public static RPCResponse loadFile(java.lang.String path)
                                      throws java.lang.Exception

      Returns the contents of any file under webRoot as a String.

      This method is used by the Visual Builder tool.

      Parameters:
        `path` - location of file to load
      Returns:
        'data' payload of RPCResponse contains the contents of the file. If an error occurs, status is set to STATUS_FAILURE and 'data' contains the error string.
      Throws:
        `java.lang.Exception`

    - #### evalJava

          public static RPCResponse evalJava(java.lang.String javaCode,
                                             RequestContext context)
                                      throws java.lang.Exception

      This method is used by the "Evaluate Java" section of the Developer Console (in the Results tab). It takes java code and writes it to a temporary JSP, sandwiched by the contents of /shared/jsp/evalJavaHeader.jsp and /shared/jsp/evalJavaFooter.jsp. Then the resulting JSP is loaded via an internal container request. The output of that request is sent back to the browser in the 'data' payload of the RPCResponse.
      Parameters:
        `javaCode` - Arbitrary JSP content, java sections must be enclosed in standard Java escape tags (<% %>).
      Returns:
        'data' payload of RPCResponse contains the result of executing the specified code via the JSP parser. If an error occurs, status is set to STATUS_FAILURE and 'data' contains the error string.
      Throws:
        `java.lang.Exception`

    - #### loadSharedXML

          public static RPCResponse loadSharedXML(java.lang.String type,
                                                  java.lang.String ID)
                                           throws java.lang.Exception

      Load a DS, UI, or APP file from the standard search path. Returns the source XML and translated JS by default.

      This method is used by the Visual Builder tool.

      Parameters:
        `type` - UI or DS or APP
        `ID` - the ID of the file to load
      Returns:
        The 'data' payload of the RPCResponse contains a Map that contains the 'type' as passed in, the 'ID' as passed in, 'xml' with the XML version of the file, 'js' with the JS version of the file (as translated from XML). If an error occurs, the Map contains an 'error' property that contains the error string.
      Throws:
        `java.lang.Exception`

    - #### saveSharedXML

          public static RPCResponse saveSharedXML(java.lang.String type,
                                                  java.lang.String ID,
                                                  java.lang.String contents)
                                           throws java.lang.Exception

      Writes or overwrites a UI, DS or APP file with the provided contents. Location of the file is based on the file type - these directories are controlled by the server.properties attributes project.(datasources|apps|ui)

      This method is used by the Visual Builder tool.

      Parameters:
        `type` - UI or DS or APP
        `ID` - Specifies the base filename, .ui.xml or .ds.xml or .app.xml is automatically appended, based on the type.
        `contents` - The contents of the file.
      Returns:
        The 'data' payload of the RPCResponse contains a Map with the 'type' and 'ID' properties as passed in. If an error occurs, the Map contains an 'error' property that contains the error string.
      Throws:
        `java.lang.Exception`

    - #### getLogNames

          public static java.util.List getLogNames()
                                            throws java.lang.Exception

      Returns the list of available log4j log names.

      This method is used by the Server Logs tab of the Developer Console.

      Returns:
        The list of available log names.
      Throws:
        `java.lang.Exception`

    - #### getLogEntries

          public static java.util.Collection getLogEntries(java.lang.String logName)
                                                    throws java.lang.Exception

      Returns the contents of the specified log4j log.

      This method is used by the Server Logs tab of the Developer Console.

      Parameters:
        `logName` - The name of the log.
      Returns:
        The contenst of the specified log4j.log.
      Throws:
        `java.lang.Exception`

    - #### downloadClientExport

          public static void downloadClientExport(java.util.List records,
                                                  java.lang.String exportAs,
                                                  java.lang.String fileName,
                                                  java.lang.String exportDisplay,
                                                  java.util.Map settings,
                                                  javax.servlet.http.HttpServletResponse response,
                                                  RPCManager rpc,
                                                  RPCRequest request)
                                           throws java.lang.Exception

      Accepts a List of formatted Record-data, exports it to the specified format and streams it back as a file with the specified fileName to the requester via content-disposition: attachment.

      Parameters:
        `records` - The records to return in a file for saving.
        `exportAs` - The export-format to convert the passed records into
        `fileName` - If parameter exportDisplay is "download", this method returns a stream with content-disposition: attachment. This argument specifies the default filename that will be shown to the user in the "save as" dialog that comes up in the browser.
        `exportDisplay` - Should the content be exported to a file or a browser window
        `settings` - Settings for the export. See `DataBoundComponent.exportClientData` in the client-side documentation for details
      Throws:
        `java.lang.Exception`