InvokeProcessor.java 18.5 KB
Newer Older
R
roo00 已提交
1 2 3
package com.x.processplatform.service.processing.processor.invoke;

import java.util.ArrayList;
R
roo00 已提交
4
import java.util.HashMap;
R
roo00 已提交
5
import java.util.LinkedHashMap;
R
roo00 已提交
6
import java.util.List;
R
roo00 已提交
7 8 9
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
R
roo00 已提交
10

R
roo00 已提交
11 12 13
import javax.script.CompiledScript;
import javax.script.ScriptContext;

R
roo00 已提交
14
import org.apache.commons.lang3.BooleanUtils;
R
roo00 已提交
15
import org.apache.commons.lang3.StringUtils;
R
roo00 已提交
16 17

import com.x.base.core.container.EntityManagerContainer;
R
roo00 已提交
18 19 20
import com.x.base.core.project.Application;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.connection.CipherConnectionAction;
Z
zhourui 已提交
21
import com.x.base.core.project.connection.ConnectionAction;
R
roo00 已提交
22
import com.x.base.core.project.exception.RunningException;
O
o2null 已提交
23
import com.x.base.core.project.http.ActionResult.Type;
R
roo00 已提交
24 25
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
R
Ray 已提交
26 27
import com.x.base.core.project.scripting.JsonScriptingExecutor;
import com.x.base.core.project.scripting.ScriptingFactory;
R
roo00 已提交
28
import com.x.base.core.project.tools.StringTools;
R
roo00 已提交
29 30 31
import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.entity.element.Invoke;
import com.x.processplatform.core.entity.element.Route;
Z
zhourui 已提交
32
import com.x.processplatform.core.entity.log.Signal;
R
roo00 已提交
33
import com.x.processplatform.service.processing.Business;
R
roo00 已提交
34
import com.x.processplatform.service.processing.ThisApplication;
R
roo00 已提交
35
import com.x.processplatform.service.processing.WrapScriptObject;
R
roo00 已提交
36 37 38 39
import com.x.processplatform.service.processing.processor.AeiObjects;

public class InvokeProcessor extends AbstractInvokeProcessor {

R
Ray 已提交
40
	private static final Logger LOGGER = LoggerFactory.getLogger(InvokeProcessor.class);
R
roo00 已提交
41 42 43 44 45 46 47

	public InvokeProcessor(EntityManagerContainer entityManagerContainer) throws Exception {
		super(entityManagerContainer);
	}

	@Override
	protected Work arriving(AeiObjects aeiObjects, Invoke invoke) throws Exception {
Z
zhourui 已提交
48
		// 发送ProcessingSignal
Z
zhourui 已提交
49
		aeiObjects.getProcessingAttributes().push(Signal.invokeArrive(aeiObjects.getWork().getActivityToken(), invoke));
R
roo00 已提交
50 51 52 53 54
		return aeiObjects.getWork();
	}

	@Override
	protected List<Work> executing(AeiObjects aeiObjects, Invoke invoke) throws Exception {
Z
zhourui 已提交
55
		// 发送ProcessingSignal
Z
zhourui 已提交
56 57
		aeiObjects.getProcessingAttributes()
				.push(Signal.invokeExecute(aeiObjects.getWork().getActivityToken(), invoke));
R
roo00 已提交
58
		List<Work> results = new ArrayList<>();
59
		boolean passThrough = false;
R
roo00 已提交
60 61
		switch (invoke.getInvokeMode()) {
		case jaxws:
62 63
			// 可以根据返回脚本判断时候流转
			passThrough = this.jaxws(aeiObjects, invoke);
R
roo00 已提交
64 65
			break;
		case jaxrs:
66 67
			// 可以根据返回脚本判断时候流转
			passThrough = this.jaxrs(aeiObjects, invoke);
R
roo00 已提交
68 69 70
			break;
		default:
			break;
R
roo00 已提交
71
		}
72 73 74
		if (passThrough) {
			results.add(aeiObjects.getWork());
		}
R
roo00 已提交
75 76 77 78 79
		return results;
	}

	@Override
	protected List<Route> inquiring(AeiObjects aeiObjects, Invoke invoke) throws Exception {
Z
zhourui 已提交
80
		// 发送ProcessingSignal
Z
zhourui 已提交
81 82
		aeiObjects.getProcessingAttributes()
				.push(Signal.invokeInquire(aeiObjects.getWork().getActivityToken(), invoke));
R
roo00 已提交
83 84 85 86 87
		List<Route> results = new ArrayList<>();
		results.add(aeiObjects.getRoutes().get(0));
		return results;
	}

88
	private boolean jaxws(AeiObjects aeiObjects, Invoke invoke) throws Exception {
R
roo00 已提交
89
		if (BooleanUtils.isTrue(invoke.getInternal())) {
90
			return this.jaxwsInternal(aeiObjects, invoke);
R
roo00 已提交
91
		} else {
92
			return this.jaxwsExternal(aeiObjects, invoke);
R
roo00 已提交
93 94 95
		}
	}

R
Ray 已提交
96
	private boolean jaxwsInternal(AeiObjects aeiObjects, Invoke invoke) {
97
		return true;
R
roo00 已提交
98 99
	}

100
	private boolean jaxwsExternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
R
roo00 已提交
101 102 103 104 105
		Object[] parameters = this.jaxwsEvalParameters(aeiObjects, invoke);
		JaxwsObject jaxwsObject = new JaxwsObject();
		jaxwsObject.setAddress(invoke.getJaxwsAddress());
		jaxwsObject.setMethod(invoke.getJaxwsMethod());
		jaxwsObject.setParameters(parameters);
106
		boolean passThrough = false;
R
roo00 已提交
107 108
		if (BooleanUtils.isTrue(invoke.getAsync())) {
			ThisApplication.syncJaxwsInvokeQueue.send(jaxwsObject);
109
			passThrough = true;
R
roo00 已提交
110 111
		} else {
			InvokeExecutor executor = new InvokeExecutor();
112
			Object[] response = executor.execute(jaxwsObject);
R
roo00 已提交
113 114
			if ((StringUtils.isNotEmpty(invoke.getJaxwsResponseScript()))
					|| (StringUtils.isNotEmpty(invoke.getJaxwsResponseScriptText()))) {
R
roo00 已提交
115 116 117 118
				ScriptContext scriptContext = aeiObjects.scriptContext();
				CompiledScript cs = aeiObjects.business().element().getCompiledScript(
						aeiObjects.getWork().getApplication(), aeiObjects.getActivity(),
						Business.EVENT_INVOKEJAXWSRESPONSE);
R
Ray 已提交
119
				scriptContext.getBindings(ScriptContext.ENGINE_SCOPE).put(ScriptingFactory.BINDING_NAME_JAXWSRESPONSE,
O
o2null 已提交
120
						response);
R
Ray 已提交
121
				passThrough = JsonScriptingExecutor.evalBoolean(cs, scriptContext);
122 123
			} else {
				passThrough = true;
R
roo00 已提交
124 125
			}
		}
126
		return passThrough;
R
roo00 已提交
127 128 129
	}

	private Object[] jaxwsEvalParameters(AeiObjects aeiObjects, Invoke invoke) throws Exception {
R
fix  
Ray 已提交
130
		List<Object> parameters = new ArrayList<>();
R
roo00 已提交
131 132
		if ((StringUtils.isNotEmpty(invoke.getJaxwsParameterScript()))
				|| (StringUtils.isNotEmpty(invoke.getJaxwsParameterScriptText()))) {
R
roo00 已提交
133 134 135
			ScriptContext scriptContext = aeiObjects.scriptContext();
			CompiledScript cs = aeiObjects.business().element().getCompiledScript(aeiObjects.getWork().getApplication(),
					aeiObjects.getActivity(), Business.EVENT_INVOKEJAXWSPARAMETER);
R
Ray 已提交
136
			scriptContext.getBindings(ScriptContext.ENGINE_SCOPE).put(ScriptingFactory.BINDING_NAME_JAXWSPARAMETERS,
O
o2null 已提交
137
					parameters);
R
fix  
Ray 已提交
138 139 140 141 142 143
			JsonScriptingExecutor.eval(cs, scriptContext);
//			JsonScriptingExecutor.jsonArray(cs, scriptContext, o -> {
//				if (o.size() > 0) {
//					parameters.addAll(gson.fromJson(o, parameters.getClass()));
//				}
//			});
R
roo00 已提交
144 145 146 147
		}
		return parameters.toArray();
	}

148
	private boolean jaxrs(AeiObjects aeiObjects, Invoke invoke) throws Exception {
R
roo00 已提交
149
		if (BooleanUtils.isTrue(invoke.getInternal())) {
150
			return this.jaxrsInternal(aeiObjects, invoke);
R
roo00 已提交
151
		} else {
152
			return this.jaxrsExternal(aeiObjects, invoke);
R
roo00 已提交
153 154 155
		}
	}

156
	private boolean jaxrsInternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
R
roo00 已提交
157 158 159
		ActionResponse resp = null;
		Class<?> clz = Class.forName("com.x.base.core.project." + invoke.getInternalProject());
		String uri = this.jaxrsUrl(aeiObjects, invoke);
O
o2null 已提交
160
		switch (StringUtils.upperCase(invoke.getJaxrsMethod())) {
Z
zhourui 已提交
161
		case ConnectionAction.METHOD_POST:
O
o2null 已提交
162
			resp = jaxrsInternalPost(aeiObjects, invoke, clz, uri);
R
roo00 已提交
163
			break;
Z
zhourui 已提交
164
		case ConnectionAction.METHOD_PUT:
O
o2null 已提交
165
			resp = jaxrsInternalPut(aeiObjects, invoke, clz, uri);
R
roo00 已提交
166
			break;
Z
zhourui 已提交
167
		case ConnectionAction.METHOD_GET:
O
o2null 已提交
168
			resp = jaxrsInternalGet(aeiObjects, invoke, clz, uri);
R
roo00 已提交
169
			break;
Z
zhourui 已提交
170
		case ConnectionAction.METHOD_DELETE:
O
o2null 已提交
171
			resp = jaxrsInternalDelete(aeiObjects, invoke, clz, uri);
R
roo00 已提交
172 173 174 175 176 177 178 179 180 181
			break;
		case "head":
			break;
		case "options":
			break;
		case "patch":
			break;
		case "trace":
			break;
		default:
O
o2null 已提交
182 183 184 185 186 187
			throw new ExceptionUnknownHttpMethod(invoke.getJaxrsMethod());
		}
		// 同步执行状态下进行调用判断
		if ((!BooleanUtils.isTrue(invoke.getAsync()))
				&& ((null == resp) || (!Objects.equals(Type.success, resp.getType())))) {
			throw new RunningException("invoke url:{} not success, work:{}.", uri, aeiObjects.getWork().getId());
R
roo00 已提交
188
		}
189
		boolean passThrough = false;
R
roo00 已提交
190 191
		if (!BooleanUtils.isTrue(invoke.getAsync())) {
			WrapScriptObject jaxrsResponse = new WrapScriptObject();
O
o2null 已提交
192
			if (null != resp) {
R
Ray 已提交
193
				jaxrsResponse.type(resp.getType().toString());
O
o2null 已提交
194 195
				jaxrsResponse.set(gson.toJson(resp.getData()));
			}
R
roo00 已提交
196 197
			if ((StringUtils.isNotEmpty(invoke.getJaxrsResponseScript()))
					|| (StringUtils.isNotEmpty(invoke.getJaxrsResponseScriptText()))) {
R
roo00 已提交
198 199 200 201
				ScriptContext scriptContext = aeiObjects.scriptContext();
				CompiledScript cs = aeiObjects.business().element().getCompiledScript(
						aeiObjects.getWork().getApplication(), aeiObjects.getActivity(),
						Business.EVENT_INVOKEJAXRSRESPONSE);
R
Ray 已提交
202
				scriptContext.getBindings(ScriptContext.ENGINE_SCOPE).put(ScriptingFactory.BINDING_NAME_JAXRSRESPONSE,
O
o2null 已提交
203
						jaxrsResponse);
R
Ray 已提交
204 205
				passThrough = JsonScriptingExecutor.evalBoolean(cs, scriptContext);
				// passThrough = ScriptFactory.asBoolean(cs.eval(scriptContext), true);
206 207
			} else {
				passThrough = true;
R
roo00 已提交
208
			}
209 210
		} else {
			passThrough = true;
R
roo00 已提交
211
		}
212
		return passThrough;
R
roo00 已提交
213 214
	}

O
o2null 已提交
215 216 217 218 219 220 221 222
	private ActionResponse jaxrsInternalDelete(AeiObjects aeiObjects, Invoke invoke, Class<?> clz, String uri)
			throws Exception {
		if (BooleanUtils.isTrue(invoke.getAsync())) {
			JaxrsObject jaxrsObject = new JaxrsObject();
			Application application = ThisApplication.context().applications().randomWithWeight(clz.getName());
			jaxrsObject
					.setAddress(StringTools.JoinUrl(application.getUrlJaxrsRoot() + CipherConnectionAction.trim(uri)));
			jaxrsObject.setInternal(invoke.getInternal());
Z
zhourui 已提交
223
			jaxrsObject.setMethod(ConnectionAction.METHOD_DELETE);
O
o2null 已提交
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
			jaxrsObject.setContentType(invoke.getJaxrsContentType());
			ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
		} else {
			return ThisApplication.context().applications().deleteQuery(clz, uri);
		}
		return null;
	}

	private ActionResponse jaxrsInternalGet(AeiObjects aeiObjects, Invoke invoke, Class<?> clz, String uri)
			throws Exception {
		if (BooleanUtils.isTrue(invoke.getAsync())) {
			JaxrsObject jaxrsObject = new JaxrsObject();
			Application application = ThisApplication.context().applications().randomWithWeight(clz.getName());
			jaxrsObject
					.setAddress(StringTools.JoinUrl(application.getUrlJaxrsRoot() + CipherConnectionAction.trim(uri)));
			jaxrsObject.setInternal(invoke.getInternal());
Z
zhourui 已提交
240
			jaxrsObject.setMethod(ConnectionAction.METHOD_GET);
O
o2null 已提交
241 242
			jaxrsObject.setContentType(invoke.getJaxrsContentType());
			ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
243
			return null;
O
o2null 已提交
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
		} else {
			return ThisApplication.context().applications().getQuery(clz, uri);
		}
	}

	private ActionResponse jaxrsInternalPut(AeiObjects aeiObjects, Invoke invoke, Class<?> clz, String uri)
			throws Exception {
		String body = this.jaxrsEvalBody(aeiObjects, invoke);
		if (BooleanUtils.isTrue(invoke.getAsync())) {
			JaxrsObject jaxrsObject = new JaxrsObject();
			Application application = ThisApplication.context().applications().randomWithWeight(clz.getName());
			jaxrsObject
					.setAddress(StringTools.JoinUrl(application.getUrlJaxrsRoot() + CipherConnectionAction.trim(uri)));
			jaxrsObject.setBody(body);
			jaxrsObject.setInternal(invoke.getInternal());
Z
zhourui 已提交
259
			jaxrsObject.setMethod(ConnectionAction.METHOD_PUT);
O
o2null 已提交
260 261
			jaxrsObject.setContentType(invoke.getJaxrsContentType());
			ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
262
			return null;
O
o2null 已提交
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
		} else {
			return ThisApplication.context().applications().putQuery(clz, uri, body);
		}
	}

	private ActionResponse jaxrsInternalPost(AeiObjects aeiObjects, Invoke invoke, Class<?> clz, String uri)
			throws Exception {
		String body = this.jaxrsEvalBody(aeiObjects, invoke);
		if (BooleanUtils.isTrue(invoke.getAsync())) {
			JaxrsObject jaxrsObject = new JaxrsObject();
			Application application = ThisApplication.context().applications().randomWithWeight(clz.getName());
			jaxrsObject
					.setAddress(StringTools.JoinUrl(application.getUrlJaxrsRoot() + CipherConnectionAction.trim(uri)));
			jaxrsObject.setBody(body);
			jaxrsObject.setInternal(invoke.getInternal());
Z
zhourui 已提交
278
			jaxrsObject.setMethod(ConnectionAction.METHOD_POST);
O
o2null 已提交
279 280
			jaxrsObject.setContentType(invoke.getJaxrsContentType());
			ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
281
			return null;
O
o2null 已提交
282 283 284 285 286
		} else {
			return ThisApplication.context().applications().postQuery(clz, uri, body);
		}
	}

287
	private boolean jaxrsExternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
R
roo00 已提交
288
		String result = "";
O
o2null 已提交
289
		String uri = this.jaxrsUrl(aeiObjects, invoke);
R
roo00 已提交
290
		JaxrsObject jaxrsObject = new JaxrsObject();
R
Ray 已提交
291
		jaxrsObject.setHead(this.jaxrsEvalHeader(aeiObjects, invoke));
O
o2null 已提交
292
		switch (StringUtils.upperCase(invoke.getJaxrsMethod())) {
Z
zhourui 已提交
293
		case ConnectionAction.METHOD_POST:
O
o2null 已提交
294
			result = jaxrsExternalPost(aeiObjects, invoke, uri, jaxrsObject);
R
roo00 已提交
295
			break;
Z
zhourui 已提交
296
		case ConnectionAction.METHOD_PUT:
O
o2null 已提交
297
			result = jaxrsExternalPut(aeiObjects, invoke, uri, jaxrsObject);
R
roo00 已提交
298
			break;
Z
zhourui 已提交
299
		case ConnectionAction.METHOD_GET:
O
o2null 已提交
300
			result = jaxrsExternalGet(aeiObjects, invoke, uri, jaxrsObject);
R
roo00 已提交
301
			break;
Z
zhourui 已提交
302
		case ConnectionAction.METHOD_DELETE:
O
o2null 已提交
303
			result = jaxrsExternalDelete(aeiObjects, invoke, uri, jaxrsObject);
R
roo00 已提交
304 305 306 307 308 309 310 311 312 313
			break;
		case "head":
			break;
		case "options":
			break;
		case "patch":
			break;
		case "trace":
			break;
		default:
O
o2null 已提交
314 315 316 317 318
			throw new ExceptionUnknownHttpMethod(invoke.getJaxrsMethod());
		}
		// 同步执行状态下进行调用判断
		if ((!BooleanUtils.isTrue(invoke.getAsync())) && (null == result)) {
			throw new RunningException("invoke address:{} not success, work:{}.", uri, aeiObjects.getWork().getId());
R
roo00 已提交
319
		}
320
		boolean passThrough = false;
R
roo00 已提交
321 322
		if (!BooleanUtils.isTrue(invoke.getAsync())) {
			WrapScriptObject jaxrsResponse = new WrapScriptObject();
R
Ray 已提交
323 324 325 326 327
			if (null == result) {
				jaxrsResponse.type(Type.connectFatal.toString());
			} else {
				jaxrsResponse.type(Type.success.toString());
			}
R
roo00 已提交
328 329 330
			jaxrsResponse.set(result);
			if ((StringUtils.isNotEmpty(invoke.getJaxrsResponseScript()))
					|| (StringUtils.isNotEmpty(invoke.getJaxrsResponseScriptText()))) {
R
roo00 已提交
331 332 333 334
				ScriptContext scriptContext = aeiObjects.scriptContext();
				CompiledScript cs = aeiObjects.business().element().getCompiledScript(
						aeiObjects.getWork().getApplication(), aeiObjects.getActivity(),
						Business.EVENT_INVOKEJAXRSRESPONSE);
R
Ray 已提交
335
				scriptContext.getBindings(ScriptContext.ENGINE_SCOPE).put(ScriptingFactory.BINDING_NAME_JAXRSRESPONSE,
O
o2null 已提交
336
						jaxrsResponse);
R
Ray 已提交
337
				passThrough = JsonScriptingExecutor.evalBoolean(cs, scriptContext);
338 339
			} else {
				passThrough = true;
R
roo00 已提交
340
			}
341 342
		} else {
			passThrough = true;
R
roo00 已提交
343
		}
344
		return passThrough;
R
roo00 已提交
345 346
	}

O
o2null 已提交
347 348
	private String jaxrsExternalDelete(AeiObjects aeiObjects, Invoke invoke, String address, JaxrsObject jaxrsObject)
			throws Exception {
Z
zhourui 已提交
349
		jaxrsObject.setMethod(ConnectionAction.METHOD_DELETE);
O
o2null 已提交
350 351 352 353 354
		jaxrsObject.setInternal(false);
		jaxrsObject.setAddress(address);
		jaxrsObject.setContentType(invoke.getJaxrsContentType());
		if (BooleanUtils.isTrue(invoke.getAsync())) {
			ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
355
			return null;
O
o2null 已提交
356 357 358 359 360 361 362 363
		} else {
			InvokeExecutor executor = new InvokeExecutor();
			return executor.execute(jaxrsObject);
		}
	}

	private String jaxrsExternalGet(AeiObjects aeiObjects, Invoke invoke, String address, JaxrsObject jaxrsObject)
			throws Exception {
Z
zhourui 已提交
364
		jaxrsObject.setMethod(ConnectionAction.METHOD_GET);
O
o2null 已提交
365 366 367 368 369
		jaxrsObject.setInternal(false);
		jaxrsObject.setAddress(address);
		jaxrsObject.setContentType(invoke.getJaxrsContentType());
		if (BooleanUtils.isTrue(invoke.getAsync())) {
			ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
370
			return null;
O
o2null 已提交
371 372 373 374 375 376 377 378 379
		} else {
			InvokeExecutor executor = new InvokeExecutor();
			return executor.execute(jaxrsObject);
		}
	}

	private String jaxrsExternalPut(AeiObjects aeiObjects, Invoke invoke, String address, JaxrsObject jaxrsObject)
			throws Exception {
		String body = this.jaxrsEvalBody(aeiObjects, invoke);
Z
zhourui 已提交
380
		jaxrsObject.setMethod(ConnectionAction.METHOD_PUT);
O
o2null 已提交
381 382 383 384 385 386
		jaxrsObject.setInternal(false);
		jaxrsObject.setAddress(address);
		jaxrsObject.setBody(body);
		jaxrsObject.setContentType(invoke.getJaxrsContentType());
		if (BooleanUtils.isTrue(invoke.getAsync())) {
			ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
387
			return null;
O
o2null 已提交
388 389 390 391 392 393 394 395 396
		} else {
			InvokeExecutor executor = new InvokeExecutor();
			return executor.execute(jaxrsObject);
		}
	}

	private String jaxrsExternalPost(AeiObjects aeiObjects, Invoke invoke, String address, JaxrsObject jaxrsObject)
			throws Exception {
		String body = this.jaxrsEvalBody(aeiObjects, invoke);
Z
zhourui 已提交
397
		jaxrsObject.setMethod(ConnectionAction.METHOD_POST);
O
o2null 已提交
398 399 400 401 402 403
		jaxrsObject.setInternal(false);
		jaxrsObject.setAddress(address);
		jaxrsObject.setBody(body);
		jaxrsObject.setContentType(invoke.getJaxrsContentType());
		if (BooleanUtils.isTrue(invoke.getAsync())) {
			ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
404
			return null;
O
o2null 已提交
405 406 407 408 409 410
		} else {
			InvokeExecutor executor = new InvokeExecutor();
			return executor.execute(jaxrsObject);
		}
	}

R
roo00 已提交
411 412 413 414 415
	private String jaxrsUrl(AeiObjects aeiObjects, Invoke invoke) throws Exception {
		String url = invoke.getJaxrsAddress();
		Map<String, String> parameters = new HashMap<>();
		if ((StringUtils.isNotEmpty(invoke.getJaxrsParameterScript()))
				|| (StringUtils.isNotEmpty(invoke.getJaxrsParameterScriptText()))) {
R
roo00 已提交
416 417 418 419

			ScriptContext scriptContext = aeiObjects.scriptContext();
			CompiledScript cs = aeiObjects.business().element().getCompiledScript(aeiObjects.getWork().getApplication(),
					aeiObjects.getActivity(), Business.EVENT_INVOKEJAXRSPARAMETER);
R
Ray 已提交
420
			scriptContext.getBindings(ScriptContext.ENGINE_SCOPE).put(ScriptingFactory.BINDING_NAME_JAXRSPARAMETERS,
O
o2null 已提交
421
					parameters);
R
Ray 已提交
422
			JsonScriptingExecutor.eval(cs, scriptContext);
R
roo00 已提交
423 424 425 426 427 428 429 430 431 432 433
		}
		for (Entry<String, String> entry : parameters.entrySet()) {
			url = StringUtils.replace(url, "{" + entry.getKey() + "}", entry.getValue());
		}
		return url;
	}

	private String jaxrsEvalBody(AeiObjects aeiObjects, Invoke invoke) throws Exception {
		JaxrsBody jaxrsBody = new JaxrsBody();
		if ((StringUtils.isNotEmpty(invoke.getJaxrsBodyScript()))
				|| (StringUtils.isNotEmpty(invoke.getJaxrsBodyScriptText()))) {
R
roo00 已提交
434
			ScriptContext scriptContext = aeiObjects.scriptContext();
O
o2null 已提交
435
			CompiledScript cs = aeiObjects.business().element().getCompiledScript(aeiObjects.getApplication().getId(),
R
roo00 已提交
436
					aeiObjects.getActivity(), Business.EVENT_INVOKEJAXRSBODY);
R
Ray 已提交
437 438 439
			scriptContext.getBindings(ScriptContext.ENGINE_SCOPE).put(ScriptingFactory.BINDING_NAME_JAXRSBODY,
					jaxrsBody);
			JsonScriptingExecutor.eval(cs, scriptContext);
R
roo00 已提交
440 441 442 443
		}
		return jaxrsBody.get();
	}

R
Ray 已提交
444
	private Map<String, String> jaxrsEvalHeader(AeiObjects aeiObjects, Invoke invoke) throws Exception {
R
roo00 已提交
445 446 447
		Map<String, String> map = new LinkedHashMap<>();
		if ((StringUtils.isNotEmpty(invoke.getJaxrsHeadScript()))
				|| (StringUtils.isNotEmpty(invoke.getJaxrsHeadScriptText()))) {
R
roo00 已提交
448 449 450
			ScriptContext scriptContext = aeiObjects.scriptContext();
			CompiledScript cs = aeiObjects.business().element().getCompiledScript(aeiObjects.getWork().getApplication(),
					aeiObjects.getActivity(), Business.EVENT_INVOKEJAXRSHEAD);
R
Ray 已提交
451 452
			scriptContext.getBindings(ScriptContext.ENGINE_SCOPE).put(ScriptingFactory.BINDING_NAME_JAXRSHEADERS, map);
			JsonScriptingExecutor.eval(cs, scriptContext);
R
roo00 已提交
453 454 455 456
		}
		return map;
	}

R
roo00 已提交
457 458 459 460 461 462 463 464
	public class JaxrsBody {

		private String value;

		private String get() {
			return Objects.toString(value, "");
		}

O
o2null 已提交
465
		public void set(String value) {
R
roo00 已提交
466 467 468 469
			this.value = value;
		}

	}
R
roo00 已提交
470 471 472

	@Override
	protected void arrivingCommitted(AeiObjects aeiObjects, Invoke invoke) throws Exception {
O
o2null 已提交
473
		// nothing
R
roo00 已提交
474 475 476
	}

	@Override
477
	protected void executingCommitted(AeiObjects aeiObjects, Invoke invoke, List<Work> works) throws Exception {
O
o2null 已提交
478
		// nothing
R
roo00 已提交
479 480 481 482
	}

	@Override
	protected void inquiringCommitted(AeiObjects aeiObjects, Invoke invoke) throws Exception {
O
o2null 已提交
483
		// nothing
R
roo00 已提交
484 485 486
	}

}