### Install plugin from disk Source: https://github.com/houxinlin/cool-request/blob/main/README.md Steps to install the built plugin zip from disk in IntelliJ IDEA. ```text 2. Open Plugin Setting 3. Install Plugin For Disk 4. Select ./build/distributions/cool-request-plugin.zip ``` -------------------------------- ### Catch StaticServerStartException when starting static server Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/errors.md Wrap static server creation and start in try-catch to handle StaticServerStartException for port busy or bad root. ```java try { StaticResourceServer server = StaticResourceServerFactory.createStaticResourceServer(new StaticServer(id, 8082, root)); server.start(); } catch (StaticServerStartException e) { /* port busy, bad root, ... */ } ``` -------------------------------- ### Direct Tomcat use via StaticResourceServerFactory Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/static-server.md Creates a StaticResourceServer directly with StaticResourceServerFactory and starts it, serving /tmp/out at http://localhost:9000/. start() throws StaticServerStartException on failure. listDir is disabled after start, then the server is stopped. ```java StaticResourceServer server = StaticResourceServerFactory.createStaticResourceServer(new StaticServer("id1", 9000, "/tmp/out")); server.start(); // serves /tmp/out at http://localhost:9000/ ; throws StaticServerStartException on failure server.setListDir(false); server.stop(); ``` -------------------------------- ### IEnv interface example - environment access Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Shows how to use the IEnv interface in a script handler to access the current environment, modify its headers, and create a new environment. The example checks for an 'Authorization' header and sets it from a system property if missing, then creates a new environment named 'nightly'. ```java public boolean handlerRequest(ILog log, HTTPRequest request, IEnv env) { Env current = env.getCurrentEnv(); log.println("env=" + current.getEnvName() + " host-params=" + current.listUrlParamKeys()); if (current.getEnvHeader("Authorization") == null) { current.setEnvHeader("Authorization", "Bearer " + System.getProperty("token")); } env.createNewEnv("nightly"); return true; } ``` -------------------------------- ### HTTPRequest basic use example Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Shows how to use the HTTPRequest interface in a script handler. Logs the current URL, adds a header, and sets a query parameter. Returns true to allow the request to proceed. ```java public boolean handlerRequest(ILog log, HTTPRequest request, IEnv env) { log.println("before: " + request.getUrl()); request.addHeader("X-Trace", "abc"); request.setParameter("page", "2"); return true; } ``` -------------------------------- ### Programmatic scan with Scans.getInstance Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/scanning.md Retrieves the Scans instance for a project and scans for controllers and scheduled tasks. The scanController method supports Spring, JAX-RS, and Rose frameworks. The example prints HTTP method and URL for each controller, e.g., "GET /api/users". ```java Scans scans = Scans.getInstance(project); List controllers = scans.scanController(project); // Spring + JAX-RS + Rose List scheduled = scans.scanScheduled(project); for (Controller c : controllers) { System.out.println(c.getHttpMethod() + " " + c.getUrl()); // e.g. "GET /api/users" } ``` -------------------------------- ### HTTPRequest mutation with error handling example Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Shows how to inspect and mutate the request with error handling. Blocks the request if the token parameter is missing, and sets a default JSON body if the 'kind' key is absent. Returns false to cancel the HTTP request. ```java public boolean handlerRequest(ILog log, HTTPRequest request, IEnv env) { if (request.getParameterMap().getOrDefault("token", List.of()).isEmpty()) { log.println("missing token, blocking request"); return false; // cancels the HTTP request } try { JSONBody body = request.getIfJSONBody(); if (body.getKey("kind") == null) { request.setRequestBody("{ \"kind\": \"default\" }"); } } catch (Exception e) { log.println("body inspect failed: " + e.getMessage()); } return true; } ``` -------------------------------- ### Start/stop a StaticServer via StaticResourceServerService Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/static-server.md Uses the application-level StaticResourceServerService to start and later stop a StaticServer. The server is created with a random UUID, port 8123, and root "/var/www/site"; listDir is enabled before starting. Stop is guarded by isRunning(s). ```java StaticResourceServerService service = ApplicationManager.getApplication().getService(StaticResourceServerService.class); StaticServer s = new StaticServer(UUID.randomUUID().toString(), 8123, "/var/www/site"); s.setListDir(true); service.start(s); // ... later if (service.isRunning(s)) service.stop(s); ``` -------------------------------- ### Env Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/types.md Interface for environment accessors and mutators. Provides methods to get, set, remove, and list environment keys. ```APIDOC ## Env ### Description Interface for environment accessors and mutators. Provides methods to get, set, remove, and list environment keys. ### Methods - `getEnv*` - Getter methods for environment properties. - `setEnv*` - Setter methods for environment properties. - `remove*` - Methods to remove environment properties. - `list*Keys` - Methods to list environment keys. ``` -------------------------------- ### HttpMethod enum Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/types.md Enumerates HTTP methods including ALL, GET, OPTIONS, POST, PUT, DELETE, PATCH, HEAD, TRACE. Helpers: getValues() excludes ALL, parse() falls back to GET. Used by StandardHttpRequestParam.method, Controller.httpMethod, and HttpMethodDefinition.parseHttpMethod. ```java public enum HttpMethod { ALL, GET, OPTIONS, POST, PUT, DELETE, PATCH, HEAD, TRACE } ``` -------------------------------- ### IEnv Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/types.md Interface for environment management. Provides methods to get current environment, create new environments, and retrieve environments by name. ```APIDOC ## IEnv ### Description Interface for environment management. Provides methods to get current environment, create new environments, and retrieve environments by name. ### Methods - `Env getCurrentEnv()` - Returns the current environment. - `void createNewEnv(String)` - Creates a new environment with the given name. - `Env getEnvByName(String)` - Returns the environment with the specified name. - `List getEnvsByName(String)` - Returns all environments with the specified name. ``` -------------------------------- ### ScriptExecute interface Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-engine.md Defines the contract for pre/post request script execution. execRequest returns false to reject/cancel the outgoing HTTP request; execResponse handles the response. Installed per request by RequestManager.sendRequest. ```java public interface ScriptExecute { public boolean execRequest(Project project, Request request) throws Exception; public void execResponse(Project project, RequestContext requestContext, Response response); } ``` -------------------------------- ### StaticResourceServerService interface Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/static-server.md Interface defining lifecycle operations for static resource servers: stop, isRunning, start, and getStaticServerIfRunning. Registered as an application service in plugin.xml; obtain via ApplicationManager.getApplication().getService(StaticResourceServerService.class). ```java public interface StaticResourceServerService { public void stop(StaticServer staticServer); public boolean isRunning(StaticServer staticServer); public void start(StaticServer staticServer); public StaticResourceServer getStaticServerIfRunning(StaticServer staticServer); } ``` -------------------------------- ### FormURLEncodedBody Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/types.md Interface for accessing form-urlencoded body values. Provides methods to get values by key. ```APIDOC ## FormURLEncodedBody ### Description Interface for accessing form-urlencoded body values. Provides methods to get values by key. ### Methods - `List getValue(String)` - Returns all values for the specified key. - `String getOneValue(String)` - Returns the first value for the specified key. ``` -------------------------------- ### Check if controller is marked with MarkPersistent Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/persistence-and-state.md Gets the MarkPersistent instance for the project and checks whether the given controller is marked, using a Map> keyed by id. ```java MarkPersistent marks = MarkPersistent.getInstance(project); boolean starred = marks.in(controller); // checks Map> by id ``` -------------------------------- ### HTTPResponse Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/types.md Interface extending HTTP for HTTP response handling. Provides methods to get response body, status code, and setters, and to retrieve form-urlencoded or JSON body. ```APIDOC ## HTTPResponse ### Description Interface extending HTTP for HTTP response handling. Provides methods to get response body, status code, and setters, and to retrieve form-urlencoded or JSON body. ### Methods - `byte[] getResponseBody()` - Returns the response body as a byte array. - `int getCode()` - Returns the HTTP status code. - Setters - Methods to set response properties. - `getIfFormURLEncodedBody()` - Returns the form-urlencoded body if present. - `getIfJSONBody()` - Returns the JSON body if present. ``` -------------------------------- ### HttpMethod.parse(Object) Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/http-request-layer.md Parses a given object into an HttpMethod. Accepts an HttpMethod instance or a case-insensitive string name. Returns GET on any parse failure. ```APIDOC ## HttpMethod.parse(Object) ### Description Parses a given object into an HttpMethod. Accepts an HttpMethod instance or a case-insensitive string name. Returns GET on any parse failure. ### Method GET ### Endpoint N/A (static method) ### Parameters #### Request Body - **method** (Object) - Required - The object to parse, either an HttpMethod or a String. ### Response #### Success Response - **HttpMethod** - The parsed HttpMethod, or GET if parsing fails. #### Response Example ```java HttpMethod method = HttpMethod.parse("POST"); ``` ``` -------------------------------- ### ICoolRequestPluginRMI interface Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/rmi-and-socket.md Defines the plugin-side RMI contract exported to the user app. Implemented by CoolRequestPluginRMIImpl (extends UnicastRemoteObject). Methods loadController, loadScheduled, loadXXLScheduled, loadGateway, and projectStartup handle dynamic component loading and environment setup. ```java public interface ICoolRequestPluginRMI extends Remote { public void loadController(List dynamicController) throws RemoteException; public void loadScheduled(List scheduleds) throws RemoteException; public void loadXXLScheduled(List xxlJobScheduleds) throws RemoteException; public void loadGateway(String contextPath, int port, String prefix, String id) throws RemoteException; public void projectStartup(int availableTcpPort, int serverPort) throws RemoteException; } ``` -------------------------------- ### projectStartup Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/endpoints.md Notifies the IDE of project startup with available TCP port and server port. Used by the user app to push startup information. ```APIDOC ## [RMI] projectStartup ### Description Notifies the IDE of project startup with available TCP port and server port. Used by the user app to push startup information. ### Method RMI ### Endpoint rmi://localhost:/com.cool.request.rmi.plugin.ICoolRequestPluginRMI ### Parameters #### Request Body - **availableTcpPort** (int) - Required - Available TCP port - **serverPort** (int) - Required - Server port ### Response No response body ``` -------------------------------- ### init() Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/component-model.md Initializes the UserProjectManager instance. Call this after obtaining the instance to set up internal state. ```APIDOC ## init() ### Description Initializes the UserProjectManager instance. Call this after obtaining the instance to set up internal state. ### Method INSTANCE ### Signature `public UserProjectManager init()` ### Return Value - **UserProjectManager** - The initialized instance (fluent). ``` -------------------------------- ### Build plugin with Gradle Source: https://github.com/houxinlin/cool-request/blob/main/README.md Builds the plugin using Gradle wrapper. The output zip is placed in ./build/distributions/. ```cmd ./gradlew buildPlugin ``` -------------------------------- ### onStartup Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/endpoints.md Called by the user process to register the agent RMI registry port. Used for initialization. ```APIDOC ## [RMI] onStartup ### Description Called by the user process to register the agent RMI registry port. Used for initialization. ### Method RMI ### Endpoint rmi://localhost:/com.cool.request.rmi.agent.ICoolRequestAgentServer ### Parameters #### Request Body - **port** (int) - Required - Port of the agent RMI registry ### Response No response body ``` -------------------------------- ### JSONBody Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/types.md Functional interface for accessing JSON body values. Provides a method to get a key from the JSON object. ```APIDOC ## JSONBody ### Description Functional interface for accessing JSON body values. Provides a method to get a key from the JSON object. ### Methods - `Object getKey(String)` - Returns the value associated with the specified key. ``` -------------------------------- ### SettingsState access pattern Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/persistence-and-state.md Shows how to obtain the SettingsState instance and mutate a field. Changes are persisted automatically on IDE close via the PersistentStateComponent contract. ```java SettingsState state = SettingPersistentState.getInstance().getState(); state.requestTimeout = 30; // mutate // persisted automatically on IDE close (PersistentStateComponent contract) ``` -------------------------------- ### Drive a request programmatically with RequestManager Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/request-manager.md Shows how to obtain a Controller, build a RequestContext with an HTTPEventListener, and send a request via RequestManager. The listener prints the response code and id on endSend. Requires a Project and userProjectManager instance. ```java Project project = ...; Controller controller = userProjectManager.getComponentByType(StaticController.class).get(0); RequestContext ctx = new RequestContext(controller, project); ctx.setHttpEventListeners(List.of(new HTTPEventListener() { public void beginSend(RequestContext c, ProgressIndicator p) {} public void endSend(RequestContext c, @NotNull HTTPResponseBody b, ProgressIndicator p) { System.out.println("code=" + b.getCode() + " id=" + b.getId()); } })); new RequestManager(requestParamManager, project, userProjectManager).sendRequest(ctx); ``` -------------------------------- ### addSpringBootApplicationInstance Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/component-model.md Tracks ProjectStartupModel instances (springBootApplicationStartupModel) keyed by server port. Used to manage running Spring Boot instances. ```APIDOC ## addSpringBootApplicationInstance ### Description Tracks ProjectStartupModel instances (springBootApplicationStartupModel) keyed by server port. Used to manage running Spring Boot instances. ### Method INSTANCE ### Signature `public void addSpringBootApplicationInstance(...)` ### Parameters - (Not explicitly documented in source) ``` -------------------------------- ### Add and configure environment with CoolRequestEnvironmentPersistentComponent Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/persistence-and-state.md Retrieves the persistent environment component for the project, adds a new environment named 'staging' with a random UUID id, then sets the host address of the first environment to 'http://localhost:8080'. ```java CoolRequestEnvironmentPersistentComponent.State envs = CoolRequestEnvironmentPersistentComponent.getInstance(project); envs.addNewEnv("staging"); // random UUID id RequestEnvironment first = envs.getEnvironments().get(0); first.setHostAddress("http://localhost:8080"); ``` -------------------------------- ### HttpMethod enum definition Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/http-request-layer.md Defines the HTTP methods supported by the request layer. The ALL member is excluded from getValues() and parse() falls back to GET on failure. ```java public enum HttpMethod { ALL, GET, OPTIONS, POST, PUT, DELETE, PATCH, HEAD, TRACE; } ``` -------------------------------- ### getIfJSONBody Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Jackson-parses the raw body into a Map. Returns null for unknown keys. ```APIDOC ## getIfJSONBody ### Description Jackson-parses the raw body into a Map. Returns null for unknown keys. ### Method `JSONBody getIfJSONBody()` ### Return Value - **JSONBody** - The parsed JSON body, or null if the key is unknown. ``` -------------------------------- ### IEnv.getCurrentEnv Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Returns a snapshot of the environment currently selected in the UI. ```APIDOC ## IEnv.getCurrentEnv ### Description Returns a snapshot of the environment currently selected in the UI. ### Method `Env getCurrentEnv()` ### Return Value - **Env** - The current environment snapshot. ### Example ```java Env current = env.getCurrentEnv(); ``` ``` -------------------------------- ### ILog Interface Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Provides logging capabilities for script execution. Output is forwarded to the request log panel and the script log page. ```APIDOC ## ILog Interface ### Description Provides logging capabilities for script execution. Output is forwarded to the request log panel and the script log page. ### Methods - `void println(Object obj)` - Prints an object to the log. - `void print(Object obj)` - Prints an object to the log without a newline. - `void clearLog()` - Clears the log. ``` -------------------------------- ### IEnv.createNewEnv Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Creates a new environment with the given name. No-op if the name is blank or an environment with that name already exists. ```APIDOC ## IEnv.createNewEnv ### Description Creates a new environment with the given name. No-op if the name is blank or an environment with that name already exists. ### Method `void createNewEnv(String name)` ### Parameters - **name** (String) - Required - The name of the new environment. ### Example ```java env.createNewEnv("nightly"); ``` ``` -------------------------------- ### addHeader Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Adds a header with the given key and value to the response. ```APIDOC ## addHeader ### Description Adds a header with the given key and value to the response. ### Method `void addHeader(String key, String value)` ### Parameters - **key** (String) - Required - The header name. - **value** (String) - Required - The header value. ``` -------------------------------- ### getInstance(Project) Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/component-model.md Static factory method to obtain the singleton UserProjectManager instance for a given project. Use this as the entry point to access component registries and Spring Boot instance tracking. ```APIDOC ## getInstance(Project) ### Description Static factory method to obtain the singleton UserProjectManager instance for a given project. Use this as the entry point to access component registries and Spring Boot instance tracking. ### Method STATIC ### Signature `public static UserProjectManager getInstance(Project project)` ### Parameters - **project** (Project) - Required - The project for which to retrieve the manager. ### Return Value - **UserProjectManager** - The singleton instance for the given project. ### Example ```java UserProjectManager m = UserProjectManager.getInstance(project); ``` ``` -------------------------------- ### IEnv.getEnvsByName Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Returns all environments with the given name. ```APIDOC ## IEnv.getEnvsByName ### Description Returns all environments with the given name. ### Method `List getEnvsByName(String envName)` ### Parameters - **envName** (String) - Required - The environment name to search for. ### Return Value - **List** - All environments with the given name. ### Example ```java List envs = env.getEnvsByName("nightly"); ``` ``` -------------------------------- ### StaticServer data object constructors and accessors Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/static-server.md Defines the configuration data object for a static server instance. The no-arg constructor is used for deserialization; the parameterized constructor sets id, port, and root. The listDir flag controls directory listing and is passed to the embedded servlet as the 'listings' init parameter. ```java public StaticServer(String id, int port, String root) public StaticServer() public boolean isListDir(); public void setListDir(boolean listDir); public String getId(); public void setId(String id); public int getPort(); public void setPort(int port); public String getRoot(); public void setRoot(String root); ``` -------------------------------- ### getCode Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Returns the HTTP status code of the response, or -1 if absent. ```APIDOC ## getCode ### Description Returns the HTTP status code of the response, or -1 if absent. ### Method `int getCode()` ### Return Value - **int** - The HTTP status code, or -1 if not set. ``` -------------------------------- ### loadController Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/endpoints.md Loads a list of dynamic controllers into the IDE. Used by the user app to push component data. ```APIDOC ## [RMI] loadController ### Description Loads a list of dynamic controllers into the IDE. Used by the user app to push component data. ### Method RMI ### Endpoint rmi://localhost:/com.cool.request.rmi.plugin.ICoolRequestPluginRMI ### Parameters #### Request Body - **List** (list) - Required - List of dynamic controllers to load ### Response No response body ``` -------------------------------- ### Enumerate components with UserProjectManager Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/component-model.md Retrieves all components of a given type (e.g., StaticController) for a project and prints their HTTP method, URL, and method name. Useful for inspecting registered components. ```java UserProjectManager m = UserProjectManager.getInstance(project); for (StaticController c : m.getComponentByType(StaticController.class)) { System.out.println(c.getHttpMethod() + " " + c.getUrl() + " -> " + c.getMethodName()); } ``` -------------------------------- ### ping Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/endpoints.md Liveness probe to check if the agent is responsive. Returns a boolean indicating availability. ```APIDOC ## [RMI] ping ### Description Liveness probe to check if the agent is responsive. Returns a boolean indicating availability. ### Method RMI ### Endpoint rmi://localhost:/com.cool.request.rmi.agent.ICoolRequestAgentRMIInterface ### Parameters None ### Response #### Success Response - **boolean** - Indicates whether the agent is alive ``` -------------------------------- ### HTTP Interface Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Base interface for HTTP request and response objects, providing header access methods. ```APIDOC ## HTTP Interface ### Description Base interface extended by HTTPRequest and HTTPResponse, providing header access methods. ### Methods - `String getHeader(String key)` - Returns the first value of the named header, or null. - `List getHeaders(String key)` - Returns all values for the header key (case-insensitive). - `List getHeaderKeys()` - Returns all header keys. ``` -------------------------------- ### IEnv.getEnvByName Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Returns the first environment whose `environmentName` equals the given name, or `null` if none found. ```APIDOC ## IEnv.getEnvByName ### Description Returns the first environment whose `environmentName` equals the given name, or `null` if none found. ### Method `Env getEnvByName(String envName)` ### Parameters - **envName** (String) - Required - The environment name to search for. ### Return Value - **Env** - The first matching environment, or `null`. ### Example ```java Env env = env.getEnvByName("nightly"); ``` ``` -------------------------------- ### SimpleScriptExecute constructor Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-engine.md Constructor for the SimpleScriptExecute implementation. Takes lists of request and response scripts plus an ILog for script logging. Used to execute user-defined pre/post request scripts. ```java public SimpleScriptExecute(List requestScript, List responseScript, ILog iScriptLog) ``` -------------------------------- ### FormURLEncodedBody.getValue Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Returns all values for the given key in an `application/x-www-form-urlencoded` body. ```APIDOC ## FormURLEncodedBody.getValue ### Description Returns all values for the given key in an `application/x-www-form-urlencoded` body. ### Method `List getValue(String key)` ### Parameters - **key** (String) - Required - The key to look up. ### Return Value - **List** - All values associated with the key. ### Example ```java List values = body.getValue("key"); ``` ``` -------------------------------- ### beforeCall script for xxl-job Source: https://github.com/houxinlin/cool-request/blob/main/README.md In the Script tab of a test case, inject the jobParam parameter into the XxlJobContext in the beforeCall method. The second parameter is the jobParam string. ```java public void beforeCall(ApplicationContext applicationContext, Method method, Map parameterValueMap) { XxlJobContext x=new XxlJobContext(1l,"{\"storeNo\": \"1\"}",null,0,0); XxlJobContext.setXxlJobContext(x); } ``` -------------------------------- ### Human-readable description strategy with AllMethodDescriptionParse Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/scanning.md Uses AllMethodDescriptionParse to parse method and parameter descriptions. The method description parser prioritizes Swagger annotations over defaults and throws IllegalArgumentException("") if none is found. The parameter description parser accepts a default value as the second argument. ```java MethodDescriptionParse parse = AllMethodDescriptionParse.getInstance(); MethodDescription md = parse.parseMethodDescription(psiMethod); // Swagger > default; throws IllegalArgumentException("") if none String p = parse.parseParameterDescription(psiParam, "default"); ``` -------------------------------- ### CacheStorageService interface Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/persistence-and-state.md Defines methods for storing and retrieving request and response caches. Implementations persist entries as JSON files under ~/.config/.cool-request/request/controller-setting and /response-cache. Missing files return null for requests and an empty-body model for responses. ```java public interface CacheStorageService { public void storageRequestCache(String id, RequestCache requestCache); public void removeRequestCache(String id); public RequestCache getRequestCache(String id); public void storageResponseCache(String requestId, HTTPResponseBody httpResponseBody); public void removeResponseCache(String id); public HTTPResponseBody getResponseCache(String requestId); public void removeAllCache(); } ``` -------------------------------- ### setContentType Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Sets the Content-Type header, removing any existing content-type headers first. ```APIDOC ## setContentType ### Description Sets the Content-Type header, removing any existing content-type headers first. ### Method `void setContentType(String type)` ### Parameters - **type** (String) - Required - The new Content-Type value. ``` -------------------------------- ### Assembling a request with StandardHttpRequestParam Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/http-request-layer.md Shows how to build a POST request with URL, headers, URL parameters, and a JSON body, then expand the path variable {id} using UriComponentsBuilder. ```java StandardHttpRequestParam p = new StandardHttpRequestParam(); p.setUrl("http://localhost:8080/api/users/{id}"); p.setMethod(HttpMethod.POST); p.getHeaders().add(new KeyValue("Content-Type", "application/json")); p.getUrlParam().add(new KeyValue("verbose", "true")); p.setBody(new StringBody("{\"name\":\"a\"}")); // path expansion: String url = UriComponentsBuilder.fromHttpUrl(p.getUrl()) .buildAndExpand(Map.of("id", "42")).toUriString(); ``` -------------------------------- ### CoolResponseScript.handlerResponse(ILog, HTTPResponse, IEnv) Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Post-request hook that users implement to process or inspect the HTTP response after it is received. ```APIDOC ## [SCRIPT] CoolResponseScript.handlerResponse(ILog, HTTPResponse, IEnv) ### Description Post-request hook that users implement to process or inspect the HTTP response after it is received. ### Method handlerResponse ### Signature void handlerResponse(ILog log, HTTPResponse response, IEnv env) ### Parameters - **log** (ILog) - Required - Logging interface for script output. - **response** (HTTPResponse) - Required - The HTTP response object, modifiable or inspectable. - **env** (IEnv) - Required - Environment variables and configuration. ### Return Value - **void** - No return value. ### Example ```java class CoolResponseScript { public void handlerResponse(ILog log, HTTPResponse response, IEnv env) { // write your code here } } ``` ``` -------------------------------- ### getIfFormURLEncodedBody Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Parses the raw body as a query string and returns a FormURLEncodedBody object. ```APIDOC ## getIfFormURLEncodedBody ### Description Parses the raw body as a query string and returns a FormURLEncodedBody object. ### Method `FormURLEncodedBody getIfFormURLEncodedBody()` ### Return Value - **FormURLEncodedBody** - The parsed form-url-encoded body. ``` -------------------------------- ### Compile and execute a request script with JavaCodeEngine Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-engine.md Creates a JavaCodeEngine and compiles a simple script class that returns true from handlerRequest. The execRequest method returns false when the request is cancelled. ```java JavaCodeEngine engine = new JavaCodeEngine(project); String code = "class CoolRequestScript { public boolean handlerRequest(ILog log, HTTPRequest req, IEnv env) { return true; } }"; boolean proceed = engine.execRequest(new Request(param, scriptLog), code); // false → request cancelled ``` -------------------------------- ### HTTPRequest Interface Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Mutable view of the outgoing HTTP request. Allows modification of URL, parameters, headers, and body. ```APIDOC ## HTTPRequest Interface ### Description Mutable view of the outgoing HTTP request. Allows modification of URL, parameters, headers, and body. ### Methods - `String getUrl()` - Returns the URL-decoded current request URL. - `void setUrl(String url)` - Sets the request URL. - `String getParameter(String key)` - Returns the first query value or null. - `void setParameter(String key, String value)` - Replaces/removes-then-adds the query key. - `void addParameter(String key, String value)` - Adds a query parameter. - `void removeParameter(String key)` - Removes a query parameter. - `Map> getParameterMap()` - Parses the query string (URLDecoder UTF-8). - `List getParameterValues(String key)` - Returns all values for a query parameter. - `void setFormData(String key, String value, boolean isFile)` - Sets form data (only effective when body is FormBody; isFile=true records type "file"). - `void setHeader(String key, String value)` - Sets a header (remove-then-add). - `void addHeader(String key, String value)` - Adds a header. - `void removeHeader(String key)` - Removes a header (case-insensitive). - `byte[] getRequestBody()` - Returns the request body as bytes. - `void setRequestBody(String body)` - Sets the request body as a StringBody. - `void setRequestBody(byte[] bytes)` - Sets the request body as a ByteBody. - `void setRequestBody(InputStream inputStream)` - Sets the request body from an InputStream (reads all bytes into ByteBody). - `FormURLEncodedBody getIfFormURLEncodedBody()` - Returns the body as form-urlencoded if applicable. - `JSONBody getIfJSONBody()` - Returns the body as a JSON object if applicable. ``` -------------------------------- ### RMIFactory method signatures Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/rmi-and-socket.md Public static methods of RMIFactory for obtaining RMI stubs. getStarterRMI(port) returns an ICoolRequestStarterRMI instance via getRMIInstance(port, ICoolRequestStarterRMI.class.getName()). getRMIInstance performs Naming.lookup("rmi://localhost:" + port + "/" + name) and wraps NotBoundException, MalformedURLException, or RemoteException in RuntimeException. ```java public static ICoolRequestStarterRMI getStarterRMI(int port) public static Remote getRMIInstance(int port, String name) ``` -------------------------------- ### getResponseBody Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Returns the Base64-decoded body bytes of the HTTP response. ```APIDOC ## getResponseBody ### Description Returns the Base64-decoded body bytes of the HTTP response. ### Method `byte[] getResponseBody()` ### Return Value - **byte[]** - The decoded body bytes. ``` -------------------------------- ### loadXXLScheduled Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/endpoints.md Loads a list of dynamic XXL-Job scheduled tasks into the IDE. Used by the user app to push component data. ```APIDOC ## [RMI] loadXXLScheduled ### Description Loads a list of dynamic XXL-Job scheduled tasks into the IDE. Used by the user app to push component data. ### Method RMI ### Endpoint rmi://localhost:/com.cool.request.rmi.plugin.ICoolRequestPluginRMI ### Parameters #### Request Body - **List** (list) - Required - List of dynamic XXL-Job scheduled tasks to load ### Response No response body ``` -------------------------------- ### FormURLEncodedBody.getOneValue Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Returns the first value for the given key, or `null` if none exists. ```APIDOC ## FormURLEncodedBody.getOneValue ### Description Returns the first value for the given key, or `null` if none exists. ### Method `String getOneValue(String key)` ### Parameters - **key** (String) - Required - The key to look up. ### Return Value - **String** - The first value, or `null`. ### Example ```java String value = body.getOneValue("key"); ``` ``` -------------------------------- ### JavaCodeEngine constructor Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-engine.md Constructor for the JavaCodeEngine facade, the compiler/invoker for user scripts. Takes the current Project to access project libraries and output paths. ```java public JavaCodeEngine(Project project) ``` -------------------------------- ### Execute request and response scripts with SimpleScriptExecute Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-engine.md Runs request and response scripts using SimpleScriptExecute. execRequest throws on script error, while execResponse never throws and shows errors in dialogs. ```java SimpleScriptExecute exec = new SimpleScriptExecute( Arrays.asList(panelRequestScript, envRequestScript), Arrays.asList(panelResponseScript, envResponseScript), scriptLog); boolean ok = exec.execRequest(project, request); // throws on script error exec.execResponse(project, context, response); // never throws; errors shown in dialogs ``` -------------------------------- ### HTTPHeader constructor Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/http-request-layer.md Creates an HTTPHeader instance from a list of Header objects. Null-safe: replaces null with an empty list. ```APIDOC ## HTTPHeader(List
headers) ### Description Creates an HTTPHeader instance from a list of Header objects. Null-safe: replaces null with an empty list. ### Method GET ### Endpoint N/A (constructor) ### Parameters #### Request Body - **headers** (List
) - Required - The list of headers to wrap. ### Response #### Success Response - **HTTPHeader** - The constructed HTTPHeader instance. #### Response Example ```java HTTPHeader header = new HTTPHeader(headers); ``` ``` -------------------------------- ### loadGateway Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/endpoints.md Loads gateway routing information into the IDE. Used by the user app to push gateway configuration. ```APIDOC ## [RMI] loadGateway ### Description Loads gateway routing information into the IDE. Used by the user app to push gateway configuration. ### Method RMI ### Endpoint rmi://localhost:/com.cool.request.rmi.plugin.ICoolRequestPluginRMI ### Parameters #### Request Body - **contextPath** (String) - Required - Context path of the gateway - **port** (int) - Required - Port of the gateway - **prefix** (String) - Required - Prefix for routes - **id** (String) - Required - Identifier for the gateway ### Response No response body ``` -------------------------------- ### httpRequestFinish Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/endpoints.md Delivers trace frames back to the plugin after an HTTP request finishes. Used for tracing. ```APIDOC ## [RMI] httpRequestFinish ### Description Delivers trace frames back to the plugin after an HTTP request finishes. Used for tracing. ### Method RMI ### Endpoint rmi://localhost:/com.cool.request.rmi.agent.ICoolRequestAgentServer ### Parameters #### Request Body - **List** (list) - Required - List of trace frames to deliver ### Response No response body ``` -------------------------------- ### Post-request hook template (plugin-script-response.java) Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Template for the post-request hook class `CoolResponseScript`. The `handlerResponse` method receives an `ILog`, `HTTPResponse`, and `IEnv`. `JavaCodeEngine` forces the class public before compiling and invokes the handler via `MethodHandle` with method type `(ILog, HTTPResponse, IEnv) void`. Named class/method/parameter must not be changed. ```java // plugin-script-response.java package com.cool.request.script; class CoolResponseScript { public void handlerResponse(ILog log, HTTPResponse response, IEnv env) { // write your code here } } ``` -------------------------------- ### BasicControllerRequestCallMethod abstract class methods Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/request-manager.md Abstract base class for request call methods. Constructor takes a StandardHttpRequestParam, getInvokeData() returns it, and invoke() is abstract, throwing InvokeException. ```java public BasicControllerRequestCallMethod(StandardHttpRequestParam reflexHttpRequestParam) public StandardHttpRequestParam getInvokeData() public abstract void invoke(RequestContext requestContext) throws InvokeException; ``` -------------------------------- ### RequestContext constructor Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/request-manager.md Constructor for RequestContext that takes a Controller and Project. The id defaults to controller.getId(). ```java public RequestContext(Controller controller, Project project) ``` -------------------------------- ### Catch exceptions in invoke/transport consumers Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/errors.md For RequestManager internals and plugins, catch exceptions around requestSync and starter.invokeController. requestSync does not throw IOException; RuntimeException wraps RemoteException/NotBoundException from RMIFactory. ```java try { InvokeResult r = new ReflexControllerRequest(port).requestSync(body); if (r == InvokeResult.FAIL) { /* app not reachable on port */ } } catch (Exception ignored) { /* requestSync does not throw IOException */ } try { ICoolRequestStarterRMI starter = RMIFactory.getStarterRMI(port); starter.invokeController(adapter); } catch (RuntimeException e) { // wraps RemoteException/NotBoundException (RMIFactory) // e.g. user app not running → fallback } ``` -------------------------------- ### createStaticResourceServer factory method Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/static-server.md Factory method that creates a StaticResourceServer for the given StaticServer configuration. Returns a new TomcatServer instance. ```java public static StaticResourceServer createStaticResourceServer(StaticServer staticServer) { return new TomcatServer(staticServer); } ``` -------------------------------- ### Invoke a controller via RMI (ICoolRequestStarterRMI.invokeController) Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/rmi-and-socket.md Retrieves the RMI port for project port 8080 and returns early if it is negative. Obtains the starter RMI through RMIFactory and invokes the controller with the adapter body, returning an InvokeResponseModel. ```java int rmiPort = userProjectManager.getRMIPortByProjectPort(8080); // may be < 0 if (rmiPort < 0) return; ICoolRequestStarterRMI starter = RMIFactory.getStarterRMI(rmiPort); InvokeResponseModel model = starter.invokeController(adapterBody); ``` -------------------------------- ### setResponseBody (String) Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Sets the response body to the given string. Throws IllegalArgumentException if the body is null or empty. ```APIDOC ## setResponseBody (String) ### Description Sets the response body to the given string. Throws IllegalArgumentException if the body is null or empty. ### Method `void setResponseBody(String body)` ### Parameters - **body** (String) - Required - The new response body as a string. ### Exceptions - **IllegalArgumentException** - If `body` is null or empty. ``` -------------------------------- ### getSpringBootPorts() / accessors Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/component-model.md Returns the list of running Spring Boot instance ports. ```APIDOC ## getSpringBootPorts() / accessors ### Description Returns the list of running Spring Boot instance ports. ### Method INSTANCE ### Signature `public ... getSpringBootPorts()` ### Return Value - List of running instance ports. ``` -------------------------------- ### OkHttpRequest abstract class template method Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/http-request-layer.md Abstract wrapper over OkHttp 4 defining the request methods and an abstract init method. Subclasses control timeouts, proxies, and follow-redirects via init. ```java public abstract class OkHttpRequest { private final OkHttpClient okHttpClient; // okHttpClient = init(new OkHttpClient.Builder()); private final Gson gson = new Gson(); public Call postFormUrlencoded(String url, Map param, Headers headers); public Call post(String url); public Call postBody(String url, String body, String type, Headers headers); public Call getBody(String url, Headers headers); public Call getBody(String url); public byte[] getByteBody(String url); public abstract OkHttpClient init(OkHttpClient.Builder builder); } ``` -------------------------------- ### CoolRequestScript.handlerRequest(ILog, HTTPRequest, IEnv) Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Pre-request hook that users implement to customize or cancel an HTTP request before it is sent. Returning false cancels the request. ```APIDOC ## [SCRIPT] CoolRequestScript.handlerRequest(ILog, HTTPRequest, IEnv) ### Description Pre-request hook that users implement to customize or cancel an HTTP request before it is sent. Returning false cancels the request. ### Method handlerRequest ### Signature boolean handlerRequest(ILog log, HTTPRequest request, IEnv env) ### Parameters - **log** (ILog) - Required - Logging interface for script output. - **request** (HTTPRequest) - Required - The HTTP request object, modifiable before sending. - **env** (IEnv) - Required - Environment variables and configuration. ### Return Value - **boolean** - Return true to proceed with the request, false to cancel it. ### Example ```java class CoolRequestScript { public boolean handlerRequest(ILog log, HTTPRequest request, IEnv env) { // write your code here return true; } } ``` ``` -------------------------------- ### Read project Spring Boot config via PropertiesReader Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/configuration.md Reads server port, context path, and custom properties from a project's Spring Boot configuration. Defaults: server.port=8080, server.servlet.context-path="". Use for accessing project-level settings. ```java PropertiesReader reader = new PropertiesReader(); int port = reader.readServerPort(project, module); // server.port, default 8080 String ctx = reader.readContextPath(project, module); // server.servlet.context-path, default "" String custom = reader.readCustomAsString("my.key", project, module); ``` -------------------------------- ### invokeController Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/endpoints.md Invokes a controller method via reflection, honoring proxy, interceptor, and filter settings. Returns an InvokeResponseModel with headers, Base64 body, and status code. ```APIDOC ## [RMI] invokeController ### Description Invokes a controller method via reflection, honoring proxy, interceptor, and filter settings. Returns an InvokeResponseModel with headers, Base64 body, and status code. ### Method RMI ### Endpoint rmi://localhost:/com.cool.request.rmi.starter.ICoolRequestStarterRMI ### Parameters #### Request Body - **ReflexHttpRequestParamAdapterBody** (object) - Required - Request body with type "controller" ### Response #### Success Response - **InvokeResponseModel** (object) - Contains header (List
), baseBodyData (Base64 body), id, code, attachData #### Error Response - **InvokeTimeoutException** - Timeout handling in RequestManager - **null response** - Timeout handling in RequestManager ``` -------------------------------- ### Pre-request hook template (plugin-script-request.java) Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/script-api.md Template for the pre-request hook class `CoolRequestScript`. The `handlerRequest` method receives an `ILog`, `HTTPRequest`, and `IEnv`; returning `false` cancels the HTTP request. `JavaCodeEngine` forces the class public before compiling and invokes the handler via `MethodHandle` with method type `(ILog, HTTPRequest, IEnv) boolean`. Named class/method/parameter must not be changed. ```java // plugin-script-request.java package com.cool.request.script; class CoolRequestScript { public boolean handlerRequest(ILog log, HTTPRequest request, IEnv env) { // write your code here return true; } } ``` -------------------------------- ### Construct reflex invoke payload with ReflexHttpRequestParamAdapterBody Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/component-model.md Builds a reflex HTTP request payload using the builder pattern, specifying URL, content type, method, and flags for proxy, interceptor, and filter usage. Then invokes the controller via RMI on port 33333. ```java ReflexHttpRequestParamAdapterBody body = ReflexHttpRequestParamAdapterBody .ReflexHttpRequestParamAdapterBuilder.aReflexHttpRequestParamAdapter() .withUrl("http://localhost:8080/api/ping") .withContentType("application/json") .withMethod("GET") .withUseProxyObject(true).withUseInterceptor(false).withUserFilter(false) .build(); InvokeResponseModel model = RMIFactory.getStarterRMI(33333).invokeController(body); ``` -------------------------------- ### ICoolRequestAgentServer extends Remote - method signatures Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/rmi-and-socket.md Plugin-side interface implemented by ICoolRequestAgentServerImpl. Methods publish trace frames, look up the agent RMI interface on startup, and return the trace log setting. ```java public void httpRequestFinish(List traceFrames) throws RemoteException; public void onStartup(int port) throws RemoteException; public boolean isLog() throws RemoteException; ``` -------------------------------- ### DynamicReflexHttpRequestParam constructor Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/http-request-layer.md Extends ReflexHttpRequestParam with an additional Object attachData parameter. Attach data carries transient execution state (e.g. a timestamp) through the reflex pipeline and back in the InvokeResponseModel.attachData. ```java public DynamicReflexHttpRequestParam(boolean useProxyObject, boolean useInterceptor, boolean userFilter, Object attachData) ``` -------------------------------- ### StaticResourceServer interface Source: https://github.com/houxinlin/cool-request/blob/main/_autodocs/api-reference/static-server.md Defines the contract for a static resource server. Implementations must provide an ID, start/stop lifecycle methods, and a setter for directory listing. This interface is implemented by TomcatServer. ```java public interface StaticResourceServer { public String getId(); public void start(); public void stop(); public void setListDir(boolean listDir); } ```