Listing of simple java DIME client

packcage edu.jhu.pha.imgcutout;
import edu.jhu.pha.skyservice.*;
import org.apache.axis.attachments.*;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
 A simple dime client which will pull down a requesed image from
 SDDS DR1 Image Cutout WebService.
public class CutOutClient {
	 * simple main loop which parses command line to call the webservice
	 * if you pass no args defaults are provided
	 * otherwise you must specify
    public static void main(String[] args) throws Exception {
		CutOutClient cl = new CutOutClient();
		int ind =0;
		String fname = "CutOutClient.jpg";
		double ra= 180;
		double dec= 0;
		int ppd = 9000;
		int width = 512;
		int height = 512;
		String opt="";

		if (args.length ==7) {
			fname = args[ind++];
			ra = Double.parseDouble(args[ind++]);
			dec = Double.parseDouble(args[ind++]);
			ppd = Integer.parseInt(args[ind++]);
			width = Integer.parseInt(args[ind++]);
			height = Integer.parseInt(args[ind++]);
			opt = args[ind++];
		} else if (args.length>0) {
			System.err.println("Pass no args to use the defaults otherwise pass:");
			System.err.println("FileName RA DEC PPD WIDTH HEIGHT OPTIONS");


	 * Call the webservice and get the attachement out of it.
	 * This is returnde as DataHandler which is part of Javax.Activation.
	public DataHandler getImage(double ra, double dec, int ppd,
								int width , int height , String opt ) throws Exception {

		ImgCutoutLocator loc = new ImgCutoutLocator();
		ImgCutoutSoap imgProvider = loc.getImgCutoutSoap();
		// not so nice but we must cast to a stub to get att the attachements
		Object[] obj =  ((org.apache.axis.client.Stub) imgProvider).getAttachments();
		// assuming one attachemnt only
		if(obj.length != 1 ) throw new Exception("Expected a single attachemnt but got "+obj.length);
		//Each Attachment is actually an AttachmentPart - we only have 1
		AttachmentPart p = (AttachmentPart) obj[0];
		// from the part we may get the dataHandler
		DataHandler dh = p.getActivationDataHandler();
		return dh;

	 * Save the image to the given file
	public void saveImage(String fname, double ra, double dec, int ppd,
								int width , int height , String opt ) throws Exception {
			  DataHandler dh = getImage(ra,dec,ppd,width,height,opt);
			  FileOutputStream fs = new FileOutputStream(fname);
			  // need to delete temp file which Axis creates
			  File f = new File(dh.getName());


William O'Mullane
Last Modified: $Revision: 1.4 $