//classString 为类名字符串,比如 "java.util.Calendar"
var Class = Java.type( classString );
var object = new Class();
//object.method()
或者
var object = new Class();
//比如 var simpleDateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
样例:
获取当前日期后的第5天
function setDate(){
var Date = java.util.Date();
var Calendar = Java.type("java.util.Calendar");
var GregorianCalendar = Java.type("java.util.GregorianCalendar");
var now = new Date();
var calendar = new GregorianCalendar();
calendar.setTime(now);
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - Config.waitDay);
return calendar.getTime();
}
var applications = resources.getContext().applications();
var serviceRoot = "x_processplatform_assemble_surface";
var path = "work/workorworkcompleted/dcd8e168-2da0-4496-83ee-137dc976c7f6"
var resp = applications.getQuery( serviceRoot, path );
var json = JSON.parse( resp.toString() );
var applications = resources.getContext().applications();
var serviceRoot = "x_processplatform_assemble_surface";
var path = "work/0b7c5c43-caa8-4789-a263-308508d44016";
var resp = applications.deleteQuery( serviceRoot, path );
var json = JSON.parse( resp.toString() );
调用本系统服务管理中的接口
样例:现有一个名称为“sendSMS”的接口,接收的requestText为 "{ mobile : mobile, content : content }"
var CipherConnectionAction = Java.type('com.x.base.core.project.connection.CipherConnectionAction');
var Config = Java.type('com.x.base.core.project.config.Config');
var path = "invoke/sendSMS/execute";
var dataString = JSON.stringify({
"mobile" : "13500000000",
"content" : "测试短信内容"
});
var resp = CipherConnectionAction.post(false, Config.url_x_program_center_jaxrs() + path, dataString );
//var resp = CipherConnectionAction.post(false, Config.x_program_centerUrlRoot() + path, dataString );
var json = JSON.parse( resp.toString() );
function sendRequest( xml ){
try{
print("发起请求:"+xml);
var url = 'http://hostname/UnifiedWorkbench/ProcessTaskService'
var ArrayList = Java.type('java.util.ArrayList');
var heads = new ArrayList();
var NameValuePair = Java.type('com.x.base.core.project.bean.NameValuePair');
var p1 = new NameValuePair('Content-Type', 'text/xml; charset=utf-8');
heads.add(p1);
var HttpConnectionClass = Java.type('com.x.base.core.project.connection.HttpConnection');
var resp = HttpConnectionClass.postAsString(url, heads, xml);
print( "统一待办返回:"+ resp.toString());
}catch(e){
print("发送请求出错:");
print( e.printStackTrace() );
}
}