@RequestMapping ( "/diagram/{processId}" ) 
public  void  genProcessDiagram ( HttpServletResponse  response, @PathVariable ( "processId" )  String  processId)  { InputStream  inputStream =  flowTaskService. diagram ( processId) ; OutputStream  os =  null ; BufferedImage  image =  null ; try  { image =  ImageIO . read ( inputStream) ; response. setContentType ( "image/png" ) ; os =  response. getOutputStream ( ) ; if  ( image !=  null )  { ImageIO . write ( image,  "png" ,  os) ; } }  catch  ( Exception  e)  { e. printStackTrace ( ) ; }  finally  { try  { if  ( os !=  null )  { os. flush ( ) ; os. close ( ) ; } }  catch  ( IOException  e)  { e. printStackTrace ( ) ; } } 
} 
public  InputStream  diagram ( String  processId)  { String  processDefinitionId; ProcessInstance  processInstance =  runtimeService. createProcessInstanceQuery ( ) . processInstanceId ( processId) . singleResult ( ) ; if  ( Objects . isNull ( processInstance) )  { HistoricProcessInstance  pi =  historyService. createHistoricProcessInstanceQuery ( ) . processInstanceId ( processId) . singleResult ( ) ; processDefinitionId =  pi. getProcessDefinitionId ( ) ; }  else  { ProcessInstance  pi =  runtimeService. createProcessInstanceQuery ( ) . processInstanceId ( processId) . singleResult ( ) ; processDefinitionId =  pi. getProcessDefinitionId ( ) ; } List < HistoricActivityInstance > =  historyService. createHistoricActivityInstanceQuery ( ) . processInstanceId ( processId) . orderByHistoricActivityInstanceStartTime ( ) . asc ( ) . list ( ) ; List < String > =  new  ArrayList < > ( ) ; List < String > =  new  ArrayList < > ( ) ; for  ( HistoricActivityInstance  tempActivity :  highLightedFlowList)  { if  ( "sequenceFlow" . equals ( tempActivity. getActivityType ( ) ) )  { highLightedFlows. add ( tempActivity. getActivityId ( ) ) ; }  else  { highLightedNodes. add ( tempActivity. getActivityId ( ) ) ; } } BpmnModel  bpmnModel =  repositoryService. getBpmnModel ( processDefinitionId) ; ProcessEngineConfiguration  configuration =  processEngine. getProcessEngineConfiguration ( ) ; ProcessDiagramGenerator  diagramGenerator =  new  CustomProcessDiagramGenerator ( ) ; return  diagramGenerator. generateDiagram ( bpmnModel,  "png" ,  highLightedNodes,  highLightedFlows,  configuration. getActivityFontName ( ) , configuration. getLabelFontName ( ) ,  configuration. getAnnotationFontName ( ) ,  configuration. getClassLoader ( ) ,  1.0 ,  true ) ; 
}