提交 76656af1 编写于 作者: R roo00

增加invoke异步/同步调用功能.

上级 6530f1a6
......@@ -23,16 +23,16 @@ import com.x.base.core.project.tools.ListTools;
public class HttpConnection {
private static String Access_Control_Allow_Credentials = "Access-Control-Allow-Credentials";
private static String Access_Control_Allow_Credentials_Value = "true";
private static String Access_Control_Allow_Headers = "Access-Control-Allow-Headers";
private static String Access_Control_Allow_Headers_Value = "x-requested-with, x-request, x-token,Content-Type, x-cipher";
private static String Access_Control_Allow_Methods = "Access-Control-Allow-Methods";
private static String Access_Control_Allow_Methods_Value = "GET, POST, OPTIONS, PUT, DELETE, HEAD, TRACE";
private static String Cache_Control = "Cache-Control";
private static String Cache_Control_Value = "no-cache, no-transform";
private static String Content_Type = "Content-Type";
private static String Content_Type_Value = "application/json;charset=UTF-8";
public static final String Access_Control_Allow_Credentials = "Access-Control-Allow-Credentials";
public static final String Access_Control_Allow_Credentials_Value = "true";
public static final String Access_Control_Allow_Headers = "Access-Control-Allow-Headers";
public static final String Access_Control_Allow_Headers_Value = "x-requested-with, x-request, x-token,Content-Type, x-cipher";
public static final String Access_Control_Allow_Methods = "Access-Control-Allow-Methods";
public static final String Access_Control_Allow_Methods_Value = "GET, POST, OPTIONS, PUT, DELETE, HEAD, TRACE";
public static final String Cache_Control = "Cache-Control";
public static final String Cache_Control_Value = "no-cache, no-transform";
public static final String Content_Type = "Content-Type";
public static final String Content_Type_Value = "application/json;charset=UTF-8";
public static String getAsString(String address, List<NameValuePair> heads) throws Exception {
HttpURLConnection connection = prepare(address, heads);
......
......@@ -31,7 +31,10 @@ public class ScriptingEngine {
public static final String BINDINGNAME__LOOKUP = "lookup";
public static final String BINDINGNAME_APPLICATIONS = "applications";
public static final String BINDINGNAME_PARAMETER = "parameter";
public static final String BINDINGNAME_PARAMETERS = "parameters";
public static final String BINDINGNAME_EFFECTIVEPERSON = "effectivePerson";
public static final String BINDINGNAME_JAXRSRESPONSE = "jaxrsResponse";
public static final String BINDINGNAME_JAXWSRESPONSE = "jaxwsResponse";
public ScriptingEngine(ScriptEngine scriptEngine) {
this.scriptEngine = scriptEngine;
......@@ -78,17 +81,32 @@ public class ScriptingEngine {
this.scriptEngine.put(BINDINGNAME_APPLICATIONS, o);
return this;
}
public ScriptingEngine bindingEffectivePerson(EffectivePerson effectivePerson) {
this.scriptEngine.put(BINDINGNAME_EFFECTIVEPERSON, effectivePerson);
return this;
}
public ScriptingEngine bindingJaxrsResponse(Object o) {
this.scriptEngine.put(BINDINGNAME_JAXRSRESPONSE, o);
return this;
}
public ScriptingEngine bindingJaxwsResponse(Object o) {
this.scriptEngine.put(BINDINGNAME_JAXWSRESPONSE, o);
return this;
}
public ScriptingEngine bindingParameter(Object o) {
this.scriptEngine.put(BINDINGNAME_PARAMETER, o);
return this;
}
public ScriptingEngine bindingParameters(Object o) {
this.scriptEngine.put(BINDINGNAME_PARAMETERS, o);
return this;
}
public Object eval(String scriptText) throws Exception {
StringBuffer sb = new StringBuffer();
try {
......
......@@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.webservices.WebservicesClient;
import com.x.organization.core.express.Organization;
import com.x.processplatform.core.entity.content.Data;
import com.x.processplatform.core.entity.content.Task;
......
......@@ -8,7 +8,8 @@ import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.message.MessageConnector;
import com.x.collaboration.core.message.Collaboration;
import com.x.processplatform.service.processing.processor.embed.SyncEmbedQueue;
import com.x.processplatform.service.processing.processor.invoke.SyncInvokeQueue;
import com.x.processplatform.service.processing.processor.invoke.SyncJaxrsInvokeQueue;
import com.x.processplatform.service.processing.processor.invoke.SyncJaxwsInvokeQueue;
import com.x.processplatform.service.processing.schedule.Delay;
import com.x.processplatform.service.processing.schedule.Expire;
import com.x.processplatform.service.processing.schedule.Reorganize;
......@@ -18,7 +19,9 @@ public class ThisApplication {
protected static Context context;
public static SyncInvokeQueue syncInvokeQueue = new SyncInvokeQueue();
public static SyncJaxrsInvokeQueue syncJaxrsInvokeQueue = new SyncJaxrsInvokeQueue();
public static SyncJaxwsInvokeQueue syncJaxwsInvokeQueue = new SyncJaxwsInvokeQueue();
public static SyncEmbedQueue syncEmbedQueue = new SyncEmbedQueue();
......@@ -32,7 +35,8 @@ public class ThisApplication {
ScriptHelperFactory.initialScriptText = Config.initialScriptText();
Collaboration.start(context());
MessageConnector.start(context());
context().startQueue(syncInvokeQueue);
context().startQueue(syncJaxrsInvokeQueue);
context().startQueue(syncJaxwsInvokeQueue);
context().startQueue(syncEmbedQueue);
if (BooleanUtils.isTrue(Config.processPlatform().getUrge().getEnable())) {
context.schedule(Urge.class, Config.processPlatform().getUrge().getCron());
......
package com.x.processplatform.service.processing;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import com.google.gson.JsonElement;
public class WebservicesClient {
public Object[] jaxws(String wsdl, String method, Object... objects) {
Object[] result = null;
try {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(wsdl);
result = client.invoke(method, objects);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public JsonElement jaxrsGet(String applicationName, String uri) throws Exception {
Class<?> clz = Class.forName("com.x.base.core.project." + applicationName);
return ThisApplication.context().applications().getQuery(clz, uri).getData();
}
public JsonElement jaxrsPut(String applicationName, String uri, Object o) throws Exception {
Class<?> clz = Class.forName("com.x.base.core.project." + applicationName);
return ThisApplication.context().applications().putQuery(clz, uri, o).getData();
}
public JsonElement jaxrsPost(String applicationName, String uri, Object o) throws Exception {
Class<?> clz = Class.forName("com.x.base.core.project." + applicationName);
return ThisApplication.context().applications().postQuery(clz, uri, o).getData();
}
public JsonElement jaxrsDelete(String applicationName, String uri, Object o) throws Exception {
Class<?> clz = Class.forName("com.x.base.core.project." + applicationName);
return ThisApplication.context().applications().deleteQuery(clz, uri).getData();
}
}
package com.x.processplatform.service.processing.processor.invoke;
import com.x.processplatform.core.entity.element.Invoke;
import com.x.processplatform.service.processing.processor.AeiObjects;
public class ExecuteObject {
public ExecuteObject(AeiObjects aeiObjects, Invoke invoke) {
this.aeiObjects = aeiObjects;
this.invoke = invoke;
}
private AeiObjects aeiObjects;
private Invoke invoke;
public AeiObjects getAeiObjects() {
return aeiObjects;
}
public void setAeiObjects(AeiObjects aeiObjects) {
this.aeiObjects = aeiObjects;
}
public Invoke getInvoke() {
return invoke;
}
public void setInvoke(Invoke invoke) {
this.invoke = invoke;
}
}
package com.x.processplatform.service.processing.processor.invoke;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.exception.RunningException;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpToken;
import com.x.base.core.project.bean.NameValuePair;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.base.core.project.connection.HttpConnection;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.processplatform.core.entity.element.Invoke;
import com.x.processplatform.service.processing.BindingPair;
import com.x.processplatform.service.processing.ScriptHelper;
import com.x.processplatform.service.processing.ScriptHelperFactory;
import com.x.processplatform.service.processing.ThisApplication;
import com.x.processplatform.service.processing.WebservicesClient;
import com.x.processplatform.service.processing.WrapScriptObject;
import com.x.processplatform.service.processing.processor.AeiObjects;
import com.x.base.core.project.webservices.WebservicesClient;
public class InvokeExecutor {
private static Logger logger = LoggerFactory.getLogger(InvokeExecutor.class);
public void execute(ExecuteObject o) throws Exception {
switch (o.getInvoke().getInvokeMode()) {
case jaxws:
this.jaxws(o.getAeiObjects(), o.getInvoke());
break;
case jaxrs:
this.jaxrs(o.getAeiObjects(), o.getInvoke());
break;
default:
break;
}
}
private void jaxws(AeiObjects aeiObjects, Invoke invoke) throws Exception {
if (BooleanUtils.isTrue(invoke.getInternal())) {
this.jaxwsInternal(aeiObjects, invoke);
} else {
this.jaxwsExternal(aeiObjects, invoke);
}
}
private void jaxwsInternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
}
private void jaxwsExternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
Object[] parameters = this.jaxwsEvalParameters(aeiObjects, invoke);
WebservicesClient client = new WebservicesClient();
Object response = client.jaxws(invoke.getJaxwsAddress(), invoke.getJaxwsMethod(), parameters);
if ((StringUtils.isNotEmpty(invoke.getJaxwsResponseScript()))
|| (StringUtils.isNotEmpty(invoke.getJaxwsResponseScriptText()))) {
ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects, new BindingPair("response", response));
scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxwsResponseScript(),
invoke.getJaxwsResponseScriptText());
}
}
private Object[] jaxwsEvalParameters(AeiObjects aeiObjects, Invoke invoke) throws Exception {
List<?> parameters = new ArrayList<>();
if ((StringUtils.isNotEmpty(invoke.getJaxwsParameterScript()))
|| (StringUtils.isNotEmpty(invoke.getJaxwsParameterScriptText()))) {
ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
new BindingPair("parameters", parameters));
scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxwsParameterScript(),
invoke.getJaxwsParameterScriptText());
}
return parameters.toArray();
}
private void jaxrs(AeiObjects aeiObjects, Invoke invoke) throws Exception {
if (BooleanUtils.isTrue(invoke.getInternal())) {
this.jaxrsInternal(aeiObjects, invoke);
} else {
this.jaxrsExternal(aeiObjects, invoke);
}
}
private void jaxrsInternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
ActionResponse resp = null;
Class<?> clz = Class.forName("com.x.base.core.project." + invoke.getInternalProject());
String uri = this.jaxrsUrl(aeiObjects, invoke);
String body = null;
switch (StringUtils.lowerCase(invoke.getJaxrsMethod())) {
public String execute(JaxrsObject o) throws Exception {
String result = "";
switch (StringUtils.lowerCase(o.getMethod())) {
case "post":
body = this.jaxrsEvalBody(aeiObjects, invoke);
resp = ThisApplication.context().applications().postQuery(clz, uri, body);
result = this.jaxrsHttpPost(o);
break;
case "put":
body = this.jaxrsEvalBody(aeiObjects, invoke);
resp = ThisApplication.context().applications().putQuery(clz, uri, body);
result = this.jaxrsHttpPut(o);
break;
case "get":
resp = ThisApplication.context().applications().getQuery(clz, uri);
result = this.jaxrsHttpGet(o);
break;
case "delete":
resp = ThisApplication.context().applications().deleteQuery(clz, uri);
result = this.jaxrsHttpDelete(o);
break;
case "head":
// resp = ThisApplication.context().applications().headQuery(clz,
// uri);
break;
case "options":
// result = this.httpOptions(business, attributes, work, data,
// invoke);
break;
case "patch":
// result = this.httpPatch(business, attributes, work, data,
// invoke);
break;
case "trace":
// result = this.httpTrace(business, attributes, work, data,
// invoke);
break;
default:
throw new Exception("unknown http method " + invoke.getJaxrsMethod());
}
/** 进行错误监测 */
if (!Objects.equals(resp.getType(), ActionResponse.Type.success)) {
throw new RunningException("invoke url:{} not success, because:{}, work:{}.", uri, resp.getMessage(),
aeiObjects.getWork().getId());
}
WrapScriptObject jaxrsResponse = new WrapScriptObject();
// LinkedHashMap<?, ?> map = resp.getData(LinkedHashMap.class);
jaxrsResponse.set(XGsonBuilder.toJson(resp.getData()));
if ((StringUtils.isNotEmpty(invoke.getJaxrsResponseScript()))
|| (StringUtils.isNotEmpty(invoke.getJaxrsResponseScriptText()))) {
ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
new BindingPair("jaxrsResponse", jaxrsResponse));
scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsResponseScript(),
invoke.getJaxrsResponseScriptText());
}
}
private void jaxrsExternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
String result;
switch (StringUtils.lowerCase(invoke.getJaxrsMethod())) {
case "post":
result = this.httpPost(aeiObjects, invoke);
break;
case "put":
result = this.httpPut(aeiObjects, invoke);
break;
case "get":
result = this.httpGet(aeiObjects, invoke);
break;
case "delete":
result = this.httpDelete(aeiObjects, invoke);
break;
case "head":
result = this.httpHead(aeiObjects, invoke);
break;
case "options":
result = this.httpOptions(aeiObjects, invoke);
break;
case "patch":
result = this.httpPatch(aeiObjects, invoke);
break;
case "trace":
result = this.httpTrace(aeiObjects, invoke);
break;
default:
throw new Exception("unknown http method " + invoke.getJaxrsMethod());
}
WrapScriptObject jaxrsResponse = new WrapScriptObject();
jaxrsResponse.set(result);
if ((StringUtils.isNotEmpty(invoke.getJaxrsResponseScript()))
|| (StringUtils.isNotEmpty(invoke.getJaxrsResponseScriptText()))) {
ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
new BindingPair("jaxrsResponse", jaxrsResponse));
scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsResponseScript(),
invoke.getJaxrsResponseScriptText());
}
return result;
}
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()))) {
ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
new BindingPair("parameters", parameters));
scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsParameterScript(),
invoke.getJaxrsParameterScriptText());
}
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()))) {
ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects, new BindingPair("jaxrsBody", jaxrsBody));
scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsBodyScript(),
invoke.getJaxrsBodyScriptText());
}
return jaxrsBody.get();
}
private String httpPost(AeiObjects aeiObjects, Invoke invoke) throws Exception {
String address = this.jaxrsUrl(aeiObjects, invoke);
HttpURLConnection connection = this.prepareConnection(address, true, invoke.getJaxrsContentType());
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
Object o = this.jaxrsEvalBody(aeiObjects, invoke);
connection.connect();
this.doOutput(connection, o);
return this.readResultString(connection);
}
private String httpPut(AeiObjects aeiObjects, Invoke invoke) throws Exception {
String address = this.jaxrsUrl(aeiObjects, invoke);
HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
invoke.getJaxrsContentType());
connection.setRequestMethod("PUT");
connection.setDoOutput(true);
connection.setDoInput(true);
Object o = this.jaxrsEvalBody(aeiObjects, invoke);
connection.connect();
this.doOutput(connection, o);
return this.readResultString(connection);
}
private String httpGet(AeiObjects aeiObjects, Invoke invoke) throws Exception {
String address = this.jaxrsUrl(aeiObjects, invoke);
HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
invoke.getJaxrsContentType());
connection.setRequestMethod("GET");
connection.setDoOutput(false);
connection.setDoInput(true);
connection.connect();
return this.readResultString(connection);
}
private String httpDelete(AeiObjects aeiObjects, Invoke invoke) throws Exception {
String address = this.jaxrsUrl(aeiObjects, invoke);
HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
invoke.getJaxrsContentType());
connection.setRequestMethod("DELETE");
connection.setDoOutput(false);
connection.setDoInput(true);
connection.connect();
return this.readResultString(connection);
}
private String httpHead(AeiObjects aeiObjects, Invoke invoke) throws Exception {
String address = this.jaxrsUrl(aeiObjects, invoke);
HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
invoke.getJaxrsContentType());
connection.setRequestMethod("HEAD");
connection.setDoOutput(false);
connection.setDoInput(true);
connection.connect();
return this.readResultString(connection);
}
private String httpOptions(AeiObjects aeiObjects, Invoke invoke) throws Exception {
String address = this.jaxrsUrl(aeiObjects, invoke);
HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
invoke.getJaxrsContentType());
connection.setRequestMethod("OPTIONS");
connection.setDoOutput(false);
connection.setDoInput(true);
connection.connect();
return this.readResultString(connection);
}
private String httpPatch(AeiObjects aeiObjects, Invoke invoke) throws Exception {
String address = this.jaxrsUrl(aeiObjects, invoke);
HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
invoke.getJaxrsContentType());
connection.setRequestMethod("PATCH");
connection.setDoOutput(false);
connection.setDoInput(true);
connection.connect();
return this.readResultString(connection);
}
private String httpTrace(AeiObjects aeiObjects, Invoke invoke) throws Exception {
String address = this.jaxrsUrl(aeiObjects, invoke);
HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
invoke.getJaxrsContentType());
connection.setRequestMethod("TRACE");
connection.setDoOutput(false);
connection.setDoInput(true);
connection.connect();
return this.readResultString(connection);
public Object execute(JaxwsObject o) throws Exception {
WebservicesClient client = new WebservicesClient();
return client.jaxws(o.getAddress(), o.getMethod(), o.getParameters());
}
public class JaxrsBody {
private String value;
private String get() {
return Objects.toString(value, "");
}
public void set(String value) throws Exception {
this.value = value;
private String jaxrsHttpPost(JaxrsObject jaxrsObject) throws Exception {
if (jaxrsObject.getInternal()) {
return CipherConnectionAction.post(true, jaxrsObject.getAddress(), jaxrsObject.getBody()).getData()
.toString();
} else {
List<NameValuePair> heads = new ArrayList<>();
heads.add(new NameValuePair(HttpConnection.Content_Type, jaxrsObject.getContentType()));
return HttpConnection.postAsString(jaxrsObject.getAddress(), heads, jaxrsObject.getBody());
}
}
private HttpURLConnection prepareConnection(String address, boolean withCipher, String contentType)
throws Exception {
try {
URL url = new URL(address);
HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection();
httpUrlConnection.setUseCaches(false);
httpUrlConnection.setRequestProperty("Content-Type", contentType);
if (BooleanUtils.isTrue(withCipher)) {
EffectivePerson effectivePerson = EffectivePerson.cipher(Config.token().getCipher());
httpUrlConnection.setRequestProperty(HttpToken.X_Token, effectivePerson.getToken());
}
return httpUrlConnection;
} catch (Exception e) {
throw new Exception("prepareConnection error", e);
private String jaxrsHttpPut(JaxrsObject jaxrsObject) throws Exception {
if (jaxrsObject.getInternal()) {
return CipherConnectionAction.post(true, jaxrsObject.getAddress(), jaxrsObject.getBody()).getData()
.toString();
} else {
List<NameValuePair> heads = new ArrayList<>();
heads.add(new NameValuePair(HttpConnection.Content_Type, jaxrsObject.getContentType()));
return HttpConnection.postAsString(jaxrsObject.getAddress(), heads, jaxrsObject.getBody());
}
}
private void doOutput(HttpURLConnection connection, Object data) throws Exception {
try (OutputStream output = connection.getOutputStream()) {
if (null != data) {
if (data instanceof String) {
IOUtils.write(data.toString(), output, StandardCharsets.UTF_8);
} else {
IOUtils.write(XGsonBuilder.toJson(data), output, StandardCharsets.UTF_8);
}
output.flush();
}
private String jaxrsHttpGet(JaxrsObject jaxrsObject) throws Exception {
if (jaxrsObject.getInternal()) {
return CipherConnectionAction.get(true, jaxrsObject.getAddress()).getData().toString();
} else {
List<NameValuePair> heads = new ArrayList<>();
heads.add(new NameValuePair(HttpConnection.Content_Type, jaxrsObject.getContentType()));
return HttpConnection.getAsString(jaxrsObject.getAddress(), heads);
}
}
private String readResultString(HttpURLConnection connection) throws Exception {
String result = "";
try (InputStream input = connection.getInputStream()) {
result = IOUtils.toString(input, StandardCharsets.UTF_8);
private String jaxrsHttpDelete(JaxrsObject jaxrsObject) throws Exception {
if (jaxrsObject.getInternal()) {
return CipherConnectionAction.delete(true, jaxrsObject.getAddress()).getData().toString();
} else {
List<NameValuePair> heads = new ArrayList<>();
heads.add(new NameValuePair(HttpConnection.Content_Type, jaxrsObject.getContentType()));
return HttpConnection.deleteAsString(jaxrsObject.getAddress(), heads);
}
return result;
}
}
package com.x.processplatform.service.processing.processor.invoke;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.project.Application;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.base.core.project.exception.RunningException;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.scripting.ScriptingEngine;
import com.x.base.core.project.tools.StringTools;
import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.entity.element.Invoke;
import com.x.processplatform.core.entity.element.Route;
import com.x.processplatform.service.processing.BindingPair;
import com.x.processplatform.service.processing.ScriptHelper;
import com.x.processplatform.service.processing.ScriptHelperFactory;
import com.x.processplatform.service.processing.ThisApplication;
import com.x.processplatform.service.processing.WrapScriptObject;
import com.x.processplatform.service.processing.processor.AeiObjects;
public class InvokeProcessor extends AbstractInvokeProcessor {
......@@ -30,21 +45,15 @@ public class InvokeProcessor extends AbstractInvokeProcessor {
@Override
protected List<Work> executing(AeiObjects aeiObjects, Invoke invoke) throws Exception {
List<Work> results = new ArrayList<>();
if (BooleanUtils.isTrue(invoke.getAsync())) {
ThisApplication.syncInvokeQueue.send(new ExecuteObject(aeiObjects, invoke));
} else {
InvokeExecutor executor = new InvokeExecutor();
executor.execute(new ExecuteObject(aeiObjects, invoke));
// switch (invoke.getInvokeMode()) {
// case jaxws:
// this.jaxws(aeiObjects, invoke);
// break;
// case jaxrs:
// this.jaxrs(aeiObjects, invoke);
// break;
// default:
// break;
// }
switch (invoke.getInvokeMode()) {
case jaxws:
this.jaxws(aeiObjects, invoke);
break;
case jaxrs:
this.jaxrs(aeiObjects, invoke);
break;
default:
break;
}
results.add(aeiObjects.getWork());
return results;
......@@ -57,317 +66,281 @@ public class InvokeProcessor extends AbstractInvokeProcessor {
return results;
}
// private void jaxws(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// if (BooleanUtils.isTrue(invoke.getInternal())) {
// this.jaxwsInternal(aeiObjects, invoke);
// } else {
// this.jaxwsExternal(aeiObjects, invoke);
// }
// }
//
// private void jaxwsInternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// }
//
// private void jaxwsExternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// Object[] parameters = this.jaxwsEvalParameters(aeiObjects, invoke);
// WebservicesClient client = new WebservicesClient();
// Object response = client.jaxws(invoke.getJaxwsAddress(), invoke.getJaxwsMethod(), parameters);
// if ((StringUtils.isNotEmpty(invoke.getJaxwsResponseScript()))
// || (StringUtils.isNotEmpty(invoke.getJaxwsResponseScriptText()))) {
// ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects, new BindingPair("response", response));
// scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxwsResponseScript(),
// invoke.getJaxwsResponseScriptText());
// }
// }
//
// private Object[] jaxwsEvalParameters(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// List<?> parameters = new ArrayList<>();
// if ((StringUtils.isNotEmpty(invoke.getJaxwsParameterScript()))
// || (StringUtils.isNotEmpty(invoke.getJaxwsParameterScriptText()))) {
// ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
// new BindingPair("parameters", parameters));
// scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxwsParameterScript(),
// invoke.getJaxwsParameterScriptText());
// }
// return parameters.toArray();
// }
//
// private void jaxrs(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// if (BooleanUtils.isTrue(invoke.getInternal())) {
// this.jaxrsInternal(aeiObjects, invoke);
// } else {
// this.jaxrsExternal(aeiObjects, invoke);
// }
// }
//
// private void jaxrsInternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// ActionResponse resp = null;
// Class<?> clz = Class.forName("com.x.base.core.project." + invoke.getInternalProject());
// String uri = this.jaxrsUrl(aeiObjects, invoke);
// String body = null;
// switch (StringUtils.lowerCase(invoke.getJaxrsMethod())) {
// case "post":
// body = this.jaxrsEvalBody(aeiObjects, invoke);
// resp = ThisApplication.context().applications().postQuery(clz, uri, body);
// break;
// case "put":
// body = this.jaxrsEvalBody(aeiObjects, invoke);
// resp = ThisApplication.context().applications().putQuery(clz, uri, body);
// break;
// case "get":
// resp = ThisApplication.context().applications().getQuery(clz, uri);
// break;
// case "delete":
// resp = ThisApplication.context().applications().deleteQuery(clz, uri);
// break;
// case "head":
// // resp = ThisApplication.context().applications().headQuery(clz,
// // uri);
// break;
// case "options":
// // result = this.httpOptions(business, attributes, work, data,
// // invoke);
// break;
// case "patch":
// // result = this.httpPatch(business, attributes, work, data,
// // invoke);
// break;
// case "trace":
// // result = this.httpTrace(business, attributes, work, data,
// // invoke);
// break;
// default:
// throw new Exception("unknown http method " + invoke.getJaxrsMethod());
// }
// /** 进行错误监测 */
// if (!Objects.equals(resp.getType(), ActionResponse.Type.success)) {
// throw new RunningException("invoke url:{} not success, because:{}, work:{}.", uri, resp.getMessage(),
// aeiObjects.getWork().getId());
// }
// WrapScriptObject jaxrsResponse = new WrapScriptObject();
// // LinkedHashMap<?, ?> map = resp.getData(LinkedHashMap.class);
// jaxrsResponse.set(gson.toJson(resp.getData()));
// if ((StringUtils.isNotEmpty(invoke.getJaxrsResponseScript()))
// || (StringUtils.isNotEmpty(invoke.getJaxrsResponseScriptText()))) {
// ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
// new BindingPair("jaxrsResponse", jaxrsResponse));
// scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsResponseScript(),
// invoke.getJaxrsResponseScriptText());
// }
// }
//
// private void jaxrsExternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String result;
// switch (StringUtils.lowerCase(invoke.getJaxrsMethod())) {
// case "post":
// result = this.httpPost(aeiObjects, invoke);
// break;
// case "put":
// result = this.httpPut(aeiObjects, invoke);
// break;
// case "get":
// result = this.httpGet(aeiObjects, invoke);
// break;
// case "delete":
// result = this.httpDelete(aeiObjects, invoke);
// break;
// case "head":
// result = this.httpHead(aeiObjects, invoke);
// break;
// case "options":
// result = this.httpOptions(aeiObjects, invoke);
// break;
// case "patch":
// result = this.httpPatch(aeiObjects, invoke);
// break;
// case "trace":
// result = this.httpTrace(aeiObjects, invoke);
// break;
// default:
// throw new Exception("unknown http method " + invoke.getJaxrsMethod());
// }
// WrapScriptObject jaxrsResponse = new WrapScriptObject();
// jaxrsResponse.set(result);
// if ((StringUtils.isNotEmpty(invoke.getJaxrsResponseScript()))
// || (StringUtils.isNotEmpty(invoke.getJaxrsResponseScriptText()))) {
// ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
// new BindingPair("jaxrsResponse", jaxrsResponse));
// scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsResponseScript(),
// invoke.getJaxrsResponseScriptText());
// }
// }
//
// 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()))) {
// ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
// new BindingPair("parameters", parameters));
// scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsParameterScript(),
// invoke.getJaxrsParameterScriptText());
// }
// 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()))) {
// ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects, new BindingPair("jaxrsBody", jaxrsBody));
// scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsBodyScript(),
// invoke.getJaxrsBodyScriptText());
//
// }
// return jaxrsBody.get();
// }
//
// private String httpPost(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, true, invoke.getJaxrsContentType());
// connection.setRequestMethod("POST");
// connection.setDoOutput(true);
// connection.setDoInput(true);
// Object o = this.jaxrsEvalBody(aeiObjects, invoke);
// connection.connect();
// this.doOutput(connection, o);
// return this.readResultString(connection);
// }
//
// private String httpPut(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("PUT");
// connection.setDoOutput(true);
// connection.setDoInput(true);
// Object o = this.jaxrsEvalBody(aeiObjects, invoke);
// connection.connect();
// this.doOutput(connection, o);
// return this.readResultString(connection);
// }
//
// private String httpGet(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("GET");
// connection.setDoOutput(false);
// connection.setDoInput(true);
// connection.connect();
// return this.readResultString(connection);
//
// }
//
// private String httpDelete(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("DELETE");
// connection.setDoOutput(false);
// connection.setDoInput(true);
// connection.connect();
// return this.readResultString(connection);
// }
//
// private String httpHead(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("HEAD");
// connection.setDoOutput(false);
// connection.setDoInput(true);
// connection.connect();
// return this.readResultString(connection);
// }
//
// private String httpOptions(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("OPTIONS");
// connection.setDoOutput(false);
// connection.setDoInput(true);
// connection.connect();
// return this.readResultString(connection);
// }
//
// private String httpPatch(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("PATCH");
// connection.setDoOutput(false);
// connection.setDoInput(true);
// connection.connect();
// return this.readResultString(connection);
// }
//
// private String httpTrace(AeiObjects aeiObjects, Invoke invoke) throws Exception {
// String address = this.jaxrsUrl(aeiObjects, invoke);
// HttpURLConnection connection = this.prepareConnection(address, invoke.getJaxrsWithCipher(),
// invoke.getJaxrsContentType());
// connection.setRequestMethod("TRACE");
// connection.setDoOutput(false);
// connection.setDoInput(true);
// connection.connect();
// return this.readResultString(connection);
// }
//
// public class JaxrsBody {
//
// private String value;
//
// private String get() {
// return Objects.toString(value, "");
// }
//
// public void set(String value) throws Exception {
// this.value = value;
// }
//
// }
//
// private HttpURLConnection prepareConnection(String address, boolean withCipher, String contentType)
// throws Exception {
// try {
// URL url = new URL(address);
// HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection();
// httpUrlConnection.setUseCaches(false);
// httpUrlConnection.setRequestProperty("Content-Type", contentType);
// if (BooleanUtils.isTrue(withCipher)) {
// EffectivePerson effectivePerson = EffectivePerson.cipher(Config.token().getCipher());
// httpUrlConnection.setRequestProperty(HttpToken.X_Token, effectivePerson.getToken());
// }
// return httpUrlConnection;
// } catch (Exception e) {
// throw new Exception("prepareConnection error", e);
// }
// }
//
// private void doOutput(HttpURLConnection connection, Object data) throws Exception {
// try (OutputStream output = connection.getOutputStream()) {
// if (null != data) {
// if (data instanceof String) {
// IOUtils.write(data.toString(), output, StandardCharsets.UTF_8);
// } else {
// IOUtils.write(XGsonBuilder.toJson(data), output, StandardCharsets.UTF_8);
// }
// output.flush();
// }
// }
// }
//
// private String readResultString(HttpURLConnection connection) throws Exception {
// String result = "";
// try (InputStream input = connection.getInputStream()) {
// result = IOUtils.toString(input, StandardCharsets.UTF_8);
// }
// return result;
// }
private void jaxws(AeiObjects aeiObjects, Invoke invoke) throws Exception {
if (BooleanUtils.isTrue(invoke.getInternal())) {
this.jaxwsInternal(aeiObjects, invoke);
} else {
this.jaxwsExternal(aeiObjects, invoke);
}
}
private void jaxwsInternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
}
private void jaxwsExternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
Object[] parameters = this.jaxwsEvalParameters(aeiObjects, invoke);
JaxwsObject jaxwsObject = new JaxwsObject();
jaxwsObject.setAddress(invoke.getJaxwsAddress());
jaxwsObject.setMethod(invoke.getJaxwsMethod());
jaxwsObject.setParameters(parameters);
if (BooleanUtils.isTrue(invoke.getAsync())) {
ThisApplication.syncJaxwsInvokeQueue.send(jaxwsObject);
} else {
InvokeExecutor executor = new InvokeExecutor();
Object response = executor.execute(jaxwsObject);
if ((StringUtils.isNotEmpty(invoke.getJaxwsResponseScript()))
|| (StringUtils.isNotEmpty(invoke.getJaxwsResponseScriptText()))) {
ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
new BindingPair(ScriptingEngine.BINDINGNAME_JAXWSRESPONSE, response));
scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxwsResponseScript(),
invoke.getJaxwsResponseScriptText());
}
}
}
private Object[] jaxwsEvalParameters(AeiObjects aeiObjects, Invoke invoke) throws Exception {
List<?> parameters = new ArrayList<>();
if ((StringUtils.isNotEmpty(invoke.getJaxwsParameterScript()))
|| (StringUtils.isNotEmpty(invoke.getJaxwsParameterScriptText()))) {
ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
new BindingPair(ScriptingEngine.BINDINGNAME_PARAMETERS, parameters));
scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxwsParameterScript(),
invoke.getJaxwsParameterScriptText());
}
return parameters.toArray();
}
private void jaxrs(AeiObjects aeiObjects, Invoke invoke) throws Exception {
if (BooleanUtils.isTrue(invoke.getInternal())) {
this.jaxrsInternal(aeiObjects, invoke);
} else {
this.jaxrsExternal(aeiObjects, invoke);
}
}
private void jaxrsInternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
ActionResponse resp = null;
Class<?> clz = Class.forName("com.x.base.core.project." + invoke.getInternalProject());
String uri = this.jaxrsUrl(aeiObjects, invoke);
String body = "";
switch (StringUtils.lowerCase(invoke.getJaxrsMethod())) {
case "post":
body = this.jaxrsEvalBody(aeiObjects, invoke);
if (BooleanUtils.isTrue(invoke.getAsync())) {
JaxrsObject jaxrsObject = new JaxrsObject();
Application application = ThisApplication.context().applications().randomWithWeight(clz);
jaxrsObject
.setAddress(StringTools.JoinUrl(application.getUrlRoot() + CipherConnectionAction.trim(uri)));
jaxrsObject.setBody(body);
jaxrsObject.setInternal(invoke.getInternal());
jaxrsObject.setMethod("post");
jaxrsObject.setContentType(invoke.getJaxrsContentType());
ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
} else {
resp = ThisApplication.context().applications().postQuery(clz, uri, body);
}
break;
case "put":
body = this.jaxrsEvalBody(aeiObjects, invoke);
if (BooleanUtils.isTrue(invoke.getAsync())) {
JaxrsObject jaxrsObject = new JaxrsObject();
Application application = ThisApplication.context().applications().randomWithWeight(clz);
jaxrsObject
.setAddress(StringTools.JoinUrl(application.getUrlRoot() + CipherConnectionAction.trim(uri)));
jaxrsObject.setBody(body);
jaxrsObject.setInternal(invoke.getInternal());
jaxrsObject.setMethod("put");
jaxrsObject.setContentType(invoke.getJaxrsContentType());
ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
} else {
resp = ThisApplication.context().applications().putQuery(clz, uri, body);
}
break;
case "get":
if (BooleanUtils.isTrue(invoke.getAsync())) {
JaxrsObject jaxrsObject = new JaxrsObject();
Application application = ThisApplication.context().applications().randomWithWeight(clz);
jaxrsObject
.setAddress(StringTools.JoinUrl(application.getUrlRoot() + CipherConnectionAction.trim(uri)));
jaxrsObject.setInternal(invoke.getInternal());
jaxrsObject.setMethod("get");
jaxrsObject.setContentType(invoke.getJaxrsContentType());
ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
} else {
resp = ThisApplication.context().applications().getQuery(clz, uri);
}
break;
case "delete":
if (BooleanUtils.isTrue(invoke.getAsync())) {
JaxrsObject jaxrsObject = new JaxrsObject();
Application application = ThisApplication.context().applications().randomWithWeight(clz);
jaxrsObject
.setAddress(StringTools.JoinUrl(application.getUrlRoot() + CipherConnectionAction.trim(uri)));
jaxrsObject.setInternal(invoke.getInternal());
jaxrsObject.setMethod("delete");
jaxrsObject.setContentType(invoke.getJaxrsContentType());
ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
} else {
resp = ThisApplication.context().applications().deleteQuery(clz, uri);
}
break;
case "head":
break;
case "options":
break;
case "patch":
break;
case "trace":
break;
default:
throw new Exception("unknown http method " + invoke.getJaxrsMethod());
}
/** 进行错误监测 */
if (!BooleanUtils.isTrue(invoke.getAsync())) {
if (!Objects.equals(resp.getType(), ActionResponse.Type.success)) {
throw new RunningException("invoke url:{} not success, because:{}, work:{}.", uri, resp.getMessage(),
aeiObjects.getWork().getId());
}
WrapScriptObject jaxrsResponse = new WrapScriptObject();
// LinkedHashMap<?, ?> map = resp.getData(LinkedHashMap.class);
jaxrsResponse.set(gson.toJson(resp.getData()));
if ((StringUtils.isNotEmpty(invoke.getJaxrsResponseScript()))
|| (StringUtils.isNotEmpty(invoke.getJaxrsResponseScriptText()))) {
ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
new BindingPair(ScriptingEngine.BINDINGNAME_JAXRSRESPONSE, jaxrsResponse));
scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsResponseScript(),
invoke.getJaxrsResponseScriptText());
}
}
}
private void jaxrsExternal(AeiObjects aeiObjects, Invoke invoke) throws Exception {
String result = "";
String address = this.jaxrsUrl(aeiObjects, invoke);
String body = "";
JaxrsObject jaxrsObject = null;
switch (StringUtils.lowerCase(invoke.getJaxrsMethod())) {
case "post":
body = this.jaxrsEvalBody(aeiObjects, invoke);
jaxrsObject = new JaxrsObject();
jaxrsObject.setMethod("post");
jaxrsObject.setInternal(false);
jaxrsObject.setAddress(address);
jaxrsObject.setBody(body);
jaxrsObject.setContentType(invoke.getJaxrsContentType());
if (BooleanUtils.isTrue(invoke.getAsync())) {
ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
} else {
InvokeExecutor executor = new InvokeExecutor();
result = executor.execute(jaxrsObject);
}
break;
case "put":
body = this.jaxrsEvalBody(aeiObjects, invoke);
jaxrsObject = new JaxrsObject();
jaxrsObject.setMethod("put");
jaxrsObject.setInternal(false);
jaxrsObject.setAddress(address);
jaxrsObject.setBody(body);
jaxrsObject.setContentType(invoke.getJaxrsContentType());
if (BooleanUtils.isTrue(invoke.getAsync())) {
ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
} else {
InvokeExecutor executor = new InvokeExecutor();
result = executor.execute(jaxrsObject);
}
break;
case "get":
jaxrsObject = new JaxrsObject();
jaxrsObject.setMethod("get");
jaxrsObject.setInternal(false);
jaxrsObject.setAddress(address);
jaxrsObject.setContentType(invoke.getJaxrsContentType());
if (BooleanUtils.isTrue(invoke.getAsync())) {
ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
} else {
InvokeExecutor executor = new InvokeExecutor();
result = executor.execute(jaxrsObject);
}
break;
case "delete":
jaxrsObject = new JaxrsObject();
jaxrsObject.setMethod("delete");
jaxrsObject.setInternal(false);
jaxrsObject.setAddress(address);
jaxrsObject.setContentType(invoke.getJaxrsContentType());
if (BooleanUtils.isTrue(invoke.getAsync())) {
ThisApplication.syncJaxrsInvokeQueue.send(jaxrsObject);
} else {
InvokeExecutor executor = new InvokeExecutor();
result = executor.execute(jaxrsObject);
}
break;
case "head":
break;
case "options":
break;
case "patch":
break;
case "trace":
break;
default:
throw new Exception("unknown http method " + invoke.getJaxrsMethod());
}
if (!BooleanUtils.isTrue(invoke.getAsync())) {
WrapScriptObject jaxrsResponse = new WrapScriptObject();
jaxrsResponse.set(result);
if ((StringUtils.isNotEmpty(invoke.getJaxrsResponseScript()))
|| (StringUtils.isNotEmpty(invoke.getJaxrsResponseScriptText()))) {
ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
new BindingPair(ScriptingEngine.BINDINGNAME_JAXRSRESPONSE, jaxrsResponse));
scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsResponseScript(),
invoke.getJaxrsResponseScriptText());
}
}
}
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()))) {
ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects,
new BindingPair("parameters", parameters));
scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsParameterScript(),
invoke.getJaxrsParameterScriptText());
}
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()))) {
ScriptHelper scriptHelper = ScriptHelperFactory.create(aeiObjects, new BindingPair("jaxrsBody", jaxrsBody));
scriptHelper.eval(aeiObjects.getWork().getApplication(), invoke.getJaxrsBodyScript(),
invoke.getJaxrsBodyScriptText());
}
return jaxrsBody.get();
}
public class JaxrsBody {
private String value;
private String get() {
return Objects.toString(value, "");
}
public void set(String value) throws Exception {
this.value = value;
}
}
@Override
protected void arrivingCommitted(AeiObjects aeiObjects, Invoke invoke) throws Exception {
......
package com.x.processplatform.service.processing.processor.invoke;
import com.x.base.core.project.gson.GsonPropertyObject;
public class JaxrsObject extends GsonPropertyObject {
private String method;
private String body;
private String address;
private String contentType;
private Boolean internal;
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Boolean getInternal() {
return internal;
}
public void setInternal(Boolean internal) {
this.internal = internal;
}
}
package com.x.processplatform.service.processing.processor.invoke;
import com.x.base.core.project.gson.GsonPropertyObject;
public class JaxwsObject extends GsonPropertyObject {
private String method;
private String address;
private Object[] parameters;
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Object[] getParameters() {
return parameters;
}
public void setParameters(Object[] parameters) {
this.parameters = parameters;
}
}
......@@ -2,10 +2,10 @@ package com.x.processplatform.service.processing.processor.invoke;
import com.x.base.core.project.queue.AbstractQueue;
public class SyncInvokeQueue extends AbstractQueue<ExecuteObject> {
public class SyncJaxrsInvokeQueue extends AbstractQueue<JaxrsObject> {
@Override
protected void execute(ExecuteObject o) throws Exception {
protected void execute(JaxrsObject o) throws Exception {
InvokeExecutor executor = new InvokeExecutor();
executor.execute(o);
}
......
package com.x.processplatform.service.processing.processor.invoke;
import com.x.base.core.project.queue.AbstractQueue;
public class SyncJaxwsInvokeQueue extends AbstractQueue<JaxwsObject> {
@Override
protected void execute(JaxwsObject o) throws Exception {
InvokeExecutor executor = new InvokeExecutor();
executor.execute(o);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册