20155 月18
@At
public String test5(@Param("taskId") String taskId) {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task == null)
return "null";
ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(task.getProcessDefinitionId());
List<ActivityImpl> activitiList = def.getActivities();
System.out.println("getTaskDefinitionKey:::" + task.getTaskDefinitionKey());
NutMap map = new NutMap();
int type = 0;
getTaskActivitys(task.getTaskDefinitionKey(), activitiList, type, map);
return Json.toJson(map);
}
public static List<PvmActivity> getTaskActivitys(String activityId, List<ActivityImpl> activityList, int type, NutMap map) {
List<PvmActivity> activitiyIds = new ArrayList<>();
for (ActivityImpl activityImpl : activityList) {
String id = activityImpl.getId();
if (activityId.equals(id)) {
List<PvmTransition> outgoingTransitions = activityImpl.getOutgoingTransitions();//获取某节点所有线路
List<NutMap> list = new ArrayList<>();
for (PvmTransition tr : outgoingTransitions) {
NutMap map1 = new NutMap();
PvmActivity ac = tr.getDestination();//获取线路的终点节点
if (ac.getProperty("type").equals("userTask")) {
map.setv("type", type++);
map1.setv("id", ac.getId());
map1.setv("name", ac.getProperty("name"));
String conditionText=Strings.sNull(tr.getProperty("conditionText"));
if(!Strings.isEmpty(conditionText)){
map1.setv("conditionText",conditionText );
}
list.add(map1);
} else if (ac.getProperty("type").equals("exclusiveGateway")) {
getTaskActivitys(ac.getId(), activityList, type, map);
} else {
map.setv("type", type++);
break;
}
}
if (list.size() > 0)
map.addv("list", list);
break;
}
}
return activitiyIds;
}
20155 月12
通过配置文件实现(这个支持CXF spring注解)点这里
pom.xml
<!--CXF START-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-api</artifactId>
<version>2.7.15</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.7.15</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-bindings-soap</artifactId>
<version>2.7.15</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.7.15</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>2.7.15</version>
</dependency>
<!--CXF END-->
web.xml
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>com.auto.webservice.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>
CXFServlet.java:
package com.auto.webservice.servlet;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
import org.nutz.ioc.Ioc;
import org.nutz.lang.Strings;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.Mvcs;
import javax.jws.WebService;
import javax.servlet.ServletConfig;
import javax.xml.namespace.QName;
/**
* Created by wizzer on 15-4-10.
*/
@SuppressWarnings("serial")
public class CXFServlet extends CXFNonSpringServlet {
private final Log log = Logs.get();
@Override
protected void loadBus(ServletConfig sc) {
super.loadBus(sc);
//全局配置
Bus bus = getBus();
//添加白名单过滤器
bus.getInInterceptors().add(new IpAddressInInterceptor());
//使用全局配置
BusFactory.setDefaultBus(bus);
Ioc ioc = Mvcs.ctx().getDefaultIoc();
for (String name : ioc.getNames()) {
try {
Object obj = ioc.get(null, name);
if (!obj.getClass().getPackage().getName().equals("com.auto.webservice.server")) {
continue;
}
if (obj.getClass().getAnnotation(WebService.class) == null)
continue;
Class face = Class.forName(obj.getClass().getPackage().getName() + "." + Strings.upperFirst(name));
ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
// 设置服务接口类
serverFactoryBean.setServiceClass(face);
// 服务请求路径
serverFactoryBean.setAddress("/" + name.substring(0, name.indexOf("Service")));
// 设置服务实现类
serverFactoryBean.setServiceBean(obj);
serverFactoryBean.setBindingId("http://schemas.xmlsoap.org/wsdl/soap12/");
serverFactoryBean.create();
} catch (Throwable e) {
}
}
}
}
接口类
WorkflowService.java
package com.auto.webservice.server;
import org.nutz.json.Json;
import javax.jws.WebService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by wizzer on 15-4-13.
*/
@WebService
public interface WorkflowService {
String start(String flowKey, String userId);//启动流程
}
实现类
WorkflowServiceImpl.java
package com.auto.webservice.server;
import org.activiti.engine.*;
import org.activiti.engine.form.FormProperty;
import org.activiti.engine.form.StartFormData;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.json.Json;
import org.nutz.json.JsonFormat;
import org.nutz.lang.Strings;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.Mvcs;
import javax.jws.WebService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by wizzer on 15-4-13.
*/
@IocBean(name = "workflowService")
@WebService
public class WorkflowServiceImpl implements WorkflowService {
private final Log log = Logs.get();
@Inject
Dao dao;
@Inject
FormService formService;
@Inject
IdentityService identityService;
@Inject
RepositoryService repositoryService;
@Inject
RuntimeService runtimeService;
@Inject
TaskService taskService;
/**
* 启动一个流程
*
* @param flowKey 流程模型key
* @param userId 用户ID
* @return
*/
public String start(String flowKey, String userId) {
Map<String, Object> map = new HashMap<String, Object>();
try {
if (!Strings.isEmpty(userId)) {
identityService.setAuthenticatedUserId(userId);
}
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(flowKey);
map.put("errcode", 0);
map.put("errmsg", "");
map.put("processInstanceId", processInstance.getId());
} catch (Exception e) {
log.error("WebServcice启动流程出错", e);
map.put("errcode", 1);
map.put("errmsg", e.getMessage());
} finally {
identityService.setAuthenticatedUserId(null);
}
return Json.toJson(map, JsonFormat.compact());
}
}
20155 月7
在nutz filter作用域内才能Mvcs.getIoc()
其他情况:
Mvcs.ctx().getDefaultIoc().get(xxx.class)