Previous Topic: Web Service Workflow Example Files

Next Topic: Glossary

Sample PMService Client

This section contains the following topics:

Sample PMService Client that Reads an Instance Image MIME Attachment

Sample PMService Client that Reads an Instance Image MIME Attachment

This PMService Client example uses a MIME attachment when a getInstanceImage call is provided.

package com.ca.workflow.pmservice.client;

import javax.activation.DataHandler;
import javax.xml.rpc.ServiceException;

import com.ejbtech.processmanager.services.PMServiceException;
import com.ejbtech.processmanager.services.PMService;
import com.ejbtech.processmanager.services.PmServiceServiceLocator;
import com.ejbtech.processmanager.services.PmServiceSoapBindingStub;

public class InstanceImageReader{

	private PMService service;
	private String sessid;

	private void init(String pmServiceUrl) throws Exception{
		PmServiceServiceLocator locator = new PmServiceServiceLocator();
		service = locator.getpmService(new java.net.URL(pmServiceUrl)); 		
	}

	private void login(String userid, String passwd,
				String pmURL) throws Exception{
		sessid = service.logIn(userid, passwd,pmURL);

	}
	
	public	void getInstanceImage( String pmUrl,
					String pmServiceUrl,
					String userid,
					String passwd,
					String instanceId,
					String imgFilePath) throws Exception{
		init(pmServiceUrl);
		login(userid,passwd,pmUrl);
		//Transmission type is MIME attachment
		com.ca.workflow.pmservice.TransmissionType tp = 
			com.ca.workflow.pmservice.TransmissionType.fromString(
				com.ca.workflow.pmservice.TransmissionType._MIME);
		//Image type is PNG.
		com.ca.workflow.pmservice.ImageType IT =
			com.ca.workflow.pmservice.ImageType.fromString(
				com.ca.workflow.pmservice.ImageType._PNG);
		service.getInstanceImage(sessid,instanceId, tp, IT);
		Object[] attach = ((PmServiceSoapBindingStub)service).getAttachments();
		if(attach.length == 0){
			throw new Exception("Image attachment is missing");
		}
		org.apache.axis.attachments.AttachmentPart part = 
				(org.apache.axis.attachments.AttachmentPart)attach[0];
		DataHandler dh = part.getDataHandler();
		java.io.InputStream ips = dh.getInputStream();
		java.io.FileOutputStream fos = new java.io.FileOutputStream(imgFilePath);
		byte data[] = new byte[1024];
		int idataread = -1;
		while((idataread=ips.read(data)) != -1 ){
			fos.write(data, 0, idataread);
		}
		fos.close();

	}
}