1515 */
1616package io .serverlessworkflow .impl .executors .openapi ;
1717
18+ import static io .serverlessworkflow .impl .executors .http .HttpExecutor .getTargetSupplier ;
19+
1820import io .serverlessworkflow .api .types .CallHTTP ;
1921import io .serverlessworkflow .api .types .CallOpenAPI ;
20- import io .serverlessworkflow .api .types .Endpoint ;
21- import io .serverlessworkflow .api .types .EndpointUri ;
2222import io .serverlessworkflow .api .types .TaskBase ;
23- import io .serverlessworkflow .api .types .UriTemplate ;
2423import io .serverlessworkflow .api .types .Workflow ;
2524import io .serverlessworkflow .impl .TaskContext ;
2625import io .serverlessworkflow .impl .WorkflowApplication ;
3029import io .serverlessworkflow .impl .WorkflowModel ;
3130import io .serverlessworkflow .impl .executors .CallableTask ;
3231import io .serverlessworkflow .impl .executors .http .HttpExecutor ;
33- import io .serverlessworkflow .impl .expressions .ExpressionDescriptor ;
34- import io .serverlessworkflow .impl .expressions .ExpressionFactory ;
32+ import io .serverlessworkflow .impl .executors .http .TargetSupplier ;
3533import io .serverlessworkflow .impl .resources .ResourceLoader ;
36- import jakarta .ws .rs .core .UriBuilder ;
37- import java .net .URI ;
3834import java .util .concurrent .CompletableFuture ;
3935import java .util .stream .Collectors ;
4036
@@ -56,36 +52,17 @@ public boolean accept(Class<? extends TaskBase> clazz) {
5652 @ Override
5753 public CompletableFuture <WorkflowModel > apply (
5854 WorkflowContext workflowContext , TaskContext taskContext , WorkflowModel input ) {
59- String operationId = task .getWith ().getOperationId ();
60- URI openAPIEndpoint = targetSupplier .apply (workflowContext , taskContext , input );
61- OpenAPIProcessor processor = new OpenAPIProcessor (operationId , openAPIEndpoint );
62- OperationDefinition operation = processor .parse ();
6355
64- OperationPathResolver pathResolver =
65- new OperationPathResolver (
66- operation . getPath (),
67- application ,
68- task . getWith (). getParameters (). getAdditionalProperties () );
56+ OperationDefinitionSupplier operationDefinitionSupplier =
57+ new OperationDefinitionSupplier ( application , task );
58+
59+ OperationDefinition operation =
60+ operationDefinitionSupplier . get ( workflowContext , taskContext , input );
6961
7062 return CompletableFuture .supplyAsync (
7163 () -> {
7264 HttpCallAdapter httpCallAdapter =
73- new HttpCallAdapter ()
74- .auth (task .getWith ().getAuthentication ())
75- .body (operation .getBody ())
76- .contentType (operation .getContentType ())
77- .headers (
78- operation .getParameters ().stream ()
79- .filter (p -> "header" .equals (p .getIn ()))
80- .collect (Collectors .toUnmodifiableSet ()))
81- .method (operation .getMethod ())
82- .query (
83- operation .getParameters ().stream ()
84- .filter (p -> "query" .equals (p .getIn ()))
85- .collect (Collectors .toUnmodifiableSet ()))
86- .redirect (task .getWith ().isRedirect ())
87- .target (pathResolver .resolve (workflowContext , taskContext , input ))
88- .workflowParams (task .getWith ().getParameters ().getAdditionalProperties ());
65+ getHttpCallAdapter (operation , workflowContext , taskContext , input );
8966
9067 WorkflowException workflowException = null ;
9168
@@ -120,35 +97,32 @@ public void init(CallOpenAPI task, WorkflowDefinition definition) {
12097 task .getWith ().getDocument ().getEndpoint (), application .expressionFactory ());
12198 }
12299
123- private TargetSupplier getTargetSupplier (Endpoint endpoint , ExpressionFactory expressionFactory ) {
124- if (endpoint .getEndpointConfiguration () != null ) {
125- EndpointUri uri = endpoint .getEndpointConfiguration ().getUri ();
126- if (uri .getLiteralEndpointURI () != null ) {
127- return getURISupplier (uri .getLiteralEndpointURI ());
128- } else if (uri .getExpressionEndpointURI () != null ) {
129- return new ExpressionURISupplier (
130- expressionFactory .resolveString (
131- ExpressionDescriptor .from (uri .getExpressionEndpointURI ())));
132- }
133- } else if (endpoint .getRuntimeExpression () != null ) {
134- return new ExpressionURISupplier (
135- expressionFactory .resolveString (
136- ExpressionDescriptor .from (endpoint .getRuntimeExpression ())));
137- } else if (endpoint .getUriTemplate () != null ) {
138- return getURISupplier (endpoint .getUriTemplate ());
139- }
140- throw new IllegalArgumentException ("Invalid endpoint definition " + endpoint );
141- }
100+ private HttpCallAdapter getHttpCallAdapter (
101+ OperationDefinition operation ,
102+ WorkflowContext workflowContext ,
103+ TaskContext taskContext ,
104+ WorkflowModel input ) {
105+ OperationPathResolver pathResolver =
106+ new OperationPathResolver (
107+ operation .getPath (),
108+ application ,
109+ task .getWith ().getParameters ().getAdditionalProperties ());
142110
143- private TargetSupplier getURISupplier (UriTemplate template ) {
144- if (template .getLiteralUri () != null ) {
145- return (w , t , n ) -> template .getLiteralUri ();
146- } else if (template .getLiteralUriTemplate () != null ) {
147- return (w , t , n ) ->
148- UriBuilder .fromUri (template .getLiteralUriTemplate ())
149- .resolveTemplates (n .asMap ().orElseThrow (), false )
150- .build ();
151- }
152- throw new IllegalArgumentException ("Invalid uri template definition " + template );
111+ return new HttpCallAdapter ()
112+ .auth (task .getWith ().getAuthentication ())
113+ .body (operation .getBody ())
114+ .contentType (operation .getContentType ())
115+ .headers (
116+ operation .getParameters ().stream ()
117+ .filter (p -> "header" .equals (p .getIn ()))
118+ .collect (Collectors .toUnmodifiableSet ()))
119+ .method (operation .getMethod ())
120+ .query (
121+ operation .getParameters ().stream ()
122+ .filter (p -> "query" .equals (p .getIn ()))
123+ .collect (Collectors .toUnmodifiableSet ()))
124+ .redirect (task .getWith ().isRedirect ())
125+ .target (pathResolver .resolve (workflowContext , taskContext , input ))
126+ .workflowParams (task .getWith ().getParameters ().getAdditionalProperties ());
153127 }
154128}
0 commit comments