public static void createXpdlImage(String designerwebBaseUrl, String processDefId) {
String baseDir = getXpdlImagePath(processDefId);
ApplicationContext appContext = WorkflowUtil.getApplicationContext();
WorkflowManager workflowManager = (WorkflowManager) appContext.getBean("workflowManager");
WorkflowProcess process = workflowManager.getProcess(processDefId);
byte[] xpdlBytes = workflowManager.getPackageContent(process.getPackageId(), process.getVersion());
FileOutputStream fos = null;
try {
String fileName = processDefId + IMAGE_EXTENSION;
File file = new File(baseDir);
file.mkdirs();
file = new File(baseDir, fileName);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
String url = designerwebBaseUrl + "/viewer/viewer.jsp?processId=" + process.getEncodedId();
URL urlObj = new URL(url);
if ("https".equals(urlObj.getProtocol())) {
// add support for self-signed SSL
String protocolPrefix = "custom";
String protocol = protocolPrefix + "https";
url = protocolPrefix + url;
Protocol customHttps = new Protocol(protocol, new CustomSSLProtocolSocketFactory(), urlObj.getPort());
Protocol.registerProtocol(protocol, customHttps);
}
HttpClient httpClient = new HttpClient();
PostMethod post = new PostMethod(url);
NameValuePair[] data = {
new NameValuePair("xpdl", new String(xpdlBytes, "UTF-8")),
new NameValuePair("packageId", process.getPackageId()),
new NameValuePair("processId", processDefId)
};
post.setRequestBody(data);
post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");