15
15
*/
16
16
package io .serverlessworkflow .impl .executors .openapi ;
17
17
18
+ import static io .serverlessworkflow .impl .executors .http .HttpExecutor .getTargetSupplier ;
19
+
18
20
import io .serverlessworkflow .api .types .CallHTTP ;
19
21
import io .serverlessworkflow .api .types .CallOpenAPI ;
20
- import io .serverlessworkflow .api .types .Endpoint ;
21
- import io .serverlessworkflow .api .types .EndpointUri ;
22
22
import io .serverlessworkflow .api .types .TaskBase ;
23
- import io .serverlessworkflow .api .types .UriTemplate ;
24
23
import io .serverlessworkflow .api .types .Workflow ;
25
24
import io .serverlessworkflow .impl .TaskContext ;
26
25
import io .serverlessworkflow .impl .WorkflowApplication ;
30
29
import io .serverlessworkflow .impl .WorkflowModel ;
31
30
import io .serverlessworkflow .impl .executors .CallableTask ;
32
31
import 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 ;
35
33
import io .serverlessworkflow .impl .resources .ResourceLoader ;
36
- import jakarta .ws .rs .core .UriBuilder ;
37
- import java .net .URI ;
38
34
import java .util .concurrent .CompletableFuture ;
39
35
import java .util .stream .Collectors ;
40
36
@@ -56,36 +52,17 @@ public boolean accept(Class<? extends TaskBase> clazz) {
56
52
@ Override
57
53
public CompletableFuture <WorkflowModel > apply (
58
54
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 ();
63
55
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 );
69
61
70
62
return CompletableFuture .supplyAsync (
71
63
() -> {
72
64
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 );
89
66
90
67
WorkflowException workflowException = null ;
91
68
@@ -120,35 +97,32 @@ public void init(CallOpenAPI task, WorkflowDefinition definition) {
120
97
task .getWith ().getDocument ().getEndpoint (), application .expressionFactory ());
121
98
}
122
99
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 ());
142
110
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 ());
153
127
}
154
128
}
0 commit comments