diagram-viewer跟蹤查看流程圖,springmvc+activiti5.19

新的activi 中未能找到老版簡介中提供的ActivitiRestApplication,因此就直接由springmvc爲Diagram Viewer提供服務,也好你們理解一下Diagram Viewer怎麼運行的。html

一、在官方提供的Zip文件(能夠從www.activiti.org/download.html下載)中有一個activiti-explorer.war文件,解壓文件,複製其中的diagram-viewer複製到項目中。java

複製modules\activiti-diagram-rest下面的java源文件到項目源文件中,如放到com.ffcs.zzy.workflow.control包下面web

  • BaseProcessDefinitionDiagramLayoutResource.java
  • ProcessDefinitionDiagramLayoutResource.java
  • ProcessInstanceDiagramLayoutResource.java
  • ProcessInstanceHighlightsResource.java

二、修改上述後面3個源文件的RequestMapping,在原來的路徑前面加/service,總共有3個地方,原來是spring

@RequestMapping(value="/process-definition/{processDefinitionId}/diagram-layout", method = RequestMethod.GET, produces = "application/json")

修改爲express

@RequestMapping(value="/service/process-definition/{processDefinitionId}/diagram-layout", method = RequestMethod.GET, produces = "application/json")

三、調整spring-mvc.xml,原來是json

<!-- 自動掃描的包名 -->
	<context:component-scan base-package="com.ffcs.**" />

修改爲spring-mvc

<!-- 自動掃描的包名 -->
	<context:component-scan base-package="com.ffcs.**" /> 
	
	<!-- 爲了返回jsonp添加的 ControllerAdvice-->
	<context:component-scan base-package="com.ffcs.**" use-default-filters="false">
        <context:include-filter type="annotation"
                                expression="org.springframework.stereotype.Controller"/>
        <context:include-filter type="annotation"
                                expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
    </context:component-scan>

四、添加spring-mvc-modeler.xml,mvc

<!-- 自動掃描且只掃描@Controller -->
	<context:component-scan base-package="org.activiti.rest.editor,org.activiti.rest.diagram">
		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
	</context:component-scan>

	<mvc:annotation-driven />

五、添加JsonpAdvice,其中com.ffcs.zzy.workflow.control就是上面源文件的所在的包app

import javax.servlet.http.HttpServletRequest;

import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJacksonValue;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpRequest;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpResponseBodyAdvice;


@ControllerAdvice(basePackages = "com.ffcs.zzy.workflow.control")
public class JsonpAdvice extends AbstractJsonpResponseBodyAdvice {

    private final String[] jsonpQueryParamNames;

    public JsonpAdvice() {
        super("callback", "jsonp");
        this.jsonpQueryParamNames = new String[]{"callback"};
    }

    @Override
    protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType,
                                           MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) {

        HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
        //若是不存在callback這個請求參數,直接返回,不須要處理爲jsonp
              if ((servletRequest.getParameter("callback")==null)) {
                  return;
              }
              
        //按設定的請求參數(JsonAdvice構造方法中的this.jsonpQueryParamNames = new String[]{"callback"};),處理返回結果爲jsonp格式
        for (String name : this.jsonpQueryParamNames) {
            String value = servletRequest.getParameter(name);
            if (value != null) {
                MediaType contentTypeToUse = getContentType(contentType, request, response);
                response.getHeaders().setContentType(contentTypeToUse);
                bodyContainer.setJsonpFunction(value);
                return;
            }
        }
    }
}

六、前臺調用的地址webapp

http://localhost/zzy-webapp/activiti/diagram-viewer/index.html?processDefinitionId=metaVersionProcess:1:12504&processInstanceId=212501

其中processDefinitionId是流程定義的ID,processInstanceId爲流程實例的ID

就能夠顯示了。。

相關文章
相關標籤/搜索