Class AiSuggestionsProxyWebScript

java.lang.Object
org.springframework.extensions.webscripts.AbstractWebScript
fr.becpg.repo.web.scripts.remote.ai.AiSuggestionsProxyWebScript
All Implemented Interfaces:
org.springframework.extensions.webscripts.WebScript

public class AiSuggestionsProxyWebScript extends org.springframework.extensions.webscripts.AbstractWebScript
Proxies the becpg-ai suggestion API, so that no client has to know where becpg-ai lives.

Same arrangement as becpg/olap/chart: the repository holds the address of the companion service (beCPG.ai.serverUrl) and knows how to authenticate the current user against it through BeCPGTicketService.getCurrentAuthToken(). A front end calling becpg-ai directly would need the AI base URL, an AI credential and the format of that credential — none of which it should hold, the format being owned by beCPG alone.

There is deliberately no free-form path parameter: a proxy forwarding an arbitrary path is a generic tunnel into becpg-ai. Three operations are exposed, one descriptor each:

  • GET /becpg/ai/suggestions?nodeRef=…&listId=…&locale=…
  • POST /becpg/ai/suggestions/apply
  • POST /becpg/ai/suggestions/apply-plan

The upstream status is forwarded as-is rather than collapsed, so that a caller can tell "becpg-ai refused you" (401/403) from "becpg-ai is not configured" (503) from "becpg-ai broke" (502). An unset beCPG.ai.serverUrl answers 503.

Author:
matthieu
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.springframework.extensions.webscripts.AbstractWebScript

    org.springframework.extensions.webscripts.AbstractWebScript.ScriptDetails
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    The becpg-ai API root, appended to the configured base URL.
     
    private static final String
    Configuration key holding the internal becpg-ai base URL.
    private static final org.apache.commons.logging.Log
     
    private String
    The operation this instance of the bean serves; injected by the Spring context.
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private URI
    buildUri(String baseUrl, org.springframework.extensions.webscripts.WebScriptRequest req)
    Builds the upstream URI of the operation this bean serves.
    void
    execute(org.springframework.extensions.webscripts.WebScriptRequest req, org.springframework.extensions.webscripts.WebScriptResponse res)
    void
    Setter for the field beCPGTicketService.
    void
    setOperation(String operation)
    Setter for the field operation.
    void
    Setter for the field systemConfigurationService.
    private void
    write(org.springframework.extensions.webscripts.WebScriptResponse res, int status, String body)
    Writes an upstream answer back to the caller, status included.

    Methods inherited from class org.springframework.extensions.webscripts.AbstractWebScript

    addModuleBundleToCache, checkModuleBundleCache, createArgs, createArgsM, createHeaders, createHeadersM, createScriptParameters, createStatusException, createTemplateParameters, executeScript, getContainer, getDescription, getExecuteScript, getResources, getStatusTemplate, init, renderString, renderString, renderTemplate, sendStatus, setURLModelFactory, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • logger

      private static final org.apache.commons.logging.Log logger
    • CONF_AI_SERVER_URL

      private static final String CONF_AI_SERVER_URL
      Configuration key holding the internal becpg-ai base URL. Empty = becpg-ai not deployed.
      See Also:
    • AI_API_BASE

      private static final String AI_API_BASE
      The becpg-ai API root, appended to the configured base URL.
      See Also:
    • operation

      private String operation
      The operation this instance of the bean serves; injected by the Spring context.
    • beCPGTicketService

      private BeCPGTicketService beCPGTicketService
    • systemConfigurationService

      private SystemConfigurationService systemConfigurationService
  • Constructor Details

    • AiSuggestionsProxyWebScript

      public AiSuggestionsProxyWebScript()
  • Method Details

    • setOperation

      public void setOperation(String operation)

      Setter for the field operation.

      Parameters:
      operation - suggestions, apply or applyPlan
    • setBeCPGTicketService

      public void setBeCPGTicketService(BeCPGTicketService beCPGTicketService)

      Setter for the field beCPGTicketService.

      Parameters:
      beCPGTicketService - a BeCPGTicketService object
    • setSystemConfigurationService

      public void setSystemConfigurationService(SystemConfigurationService systemConfigurationService)

      Setter for the field systemConfigurationService.

      Parameters:
      systemConfigurationService - a SystemConfigurationService object
    • execute

      public void execute(org.springframework.extensions.webscripts.WebScriptRequest req, org.springframework.extensions.webscripts.WebScriptResponse res) throws IOException
      Throws:
      IOException
    • buildUri

      private URI buildUri(String baseUrl, org.springframework.extensions.webscripts.WebScriptRequest req) throws URISyntaxException
      Builds the upstream URI of the operation this bean serves.

      The path is chosen from operation, never from the request: that is what keeps the proxy closed. Only the parameters a given operation declares are forwarded.

      Parameters:
      baseUrl - the configured becpg-ai base URL
      req - the incoming request
      Returns:
      the upstream URI
      Throws:
      URISyntaxException - when the configured URL is not a URI
    • write

      private void write(org.springframework.extensions.webscripts.WebScriptResponse res, int status, String body) throws IOException
      Writes an upstream answer back to the caller, status included.
      Parameters:
      res - the response
      status - the HTTP status to forward
      body - the body, may be null
      Throws:
      IOException - if any