Class AiSuggestionsProxyWebScript
- All Implemented Interfaces:
org.springframework.extensions.webscripts.WebScript
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/applyPOST /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
FieldsModifier and TypeFieldDescriptionprivate static final StringThe becpg-ai API root, appended to the configured base URL.private BeCPGTicketServiceprivate static final StringConfiguration key holding the internal becpg-ai base URL.private static final org.apache.commons.logging.Logprivate StringThe operation this instance of the bean serves; injected by the Spring context.private SystemConfigurationService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate URIBuilds the upstream URI of the operation this bean serves.voidexecute(org.springframework.extensions.webscripts.WebScriptRequest req, org.springframework.extensions.webscripts.WebScriptResponse res) voidsetBeCPGTicketService(BeCPGTicketService beCPGTicketService) Setter for the fieldbeCPGTicketService.voidsetOperation(String operation) Setter for the fieldoperation.voidsetSystemConfigurationService(SystemConfigurationService systemConfigurationService) Setter for the fieldsystemConfigurationService.private voidWrites 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
-
Field Details
-
logger
private static final org.apache.commons.logging.Log logger -
CONF_AI_SERVER_URL
Configuration key holding the internal becpg-ai base URL. Empty = becpg-ai not deployed.- See Also:
-
AI_API_BASE
The becpg-ai API root, appended to the configured base URL.- See Also:
-
operation
The operation this instance of the bean serves; injected by the Spring context. -
beCPGTicketService
-
systemConfigurationService
-
-
Constructor Details
-
AiSuggestionsProxyWebScript
public AiSuggestionsProxyWebScript()
-
-
Method Details
-
setOperation
Setter for the field
operation.- Parameters:
operation-suggestions,applyorapplyPlan
-
setBeCPGTicketService
Setter for the field
beCPGTicketService.- Parameters:
beCPGTicketService- aBeCPGTicketServiceobject
-
setSystemConfigurationService
Setter for the field
systemConfigurationService.- Parameters:
systemConfigurationService- aSystemConfigurationServiceobject
-
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 URLreq- 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 responsestatus- the HTTP status to forwardbody- the body, may be null- Throws:
IOException- if any
-