1
2
3
4
5 package org.astrogrid.dataservice.service.siap;
6
7 import java.io.IOException;
8 import java.util.StringTokenizer;
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 import org.astrogrid.account.LoginAccount;
12 import org.astrogrid.dataservice.service.DataServer;
13 import org.astrogrid.dataservice.service.ServletHelper;
14 import org.astrogrid.query.Query;
15 import org.astrogrid.query.condition.CircleCondition;
16 import org.astrogrid.query.returns.ReturnImage;
17 import org.astrogrid.query.returns.ReturnSpec;
18 import org.astrogrid.query.returns.ReturnTable;
19 import org.astrogrid.slinger.targets.TargetMaker;
20 import org.astrogrid.webapp.DefaultServlet;
21
22 /***
23 * Simple image access protocol. Consists of a query that returns either an image
24 * or a table that
25 * has URLs to the images themselves. This class handles the initial
26 * query
27 * @see http://www.ivoa.net/Documents/latest/SIA.html
28 *
29 * @author mch
30 */
31 public class SimpleImageQuery extends DefaultServlet {
32
33 DataServer server = new DataServer();
34
35 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
36
37 try {
38 CircleCondition circleCon = ServletHelper.makeCircleCondition(request);
39 String formatParam = request.getParameter("FORMAT");
40 if (formatParam == null) formatParam = request.getParameter("format");
41
42
43 StringTokenizer tokenizer = new StringTokenizer(formatParam, ",");
44 String[] formats = new String[tokenizer.countTokens()];
45 for (int i = 0; i < formats.length; i++) {
46 formats[i] = tokenizer.nextToken();
47 }
48
49
50
51 String format = formats[0];
52
53
54 ReturnSpec returnSpec = null;
55 boolean isTable = (ReturnTable.isTableFormat(formats));
56 boolean isImage = (ReturnImage.isImageFormat(formats));
57
58
59 if ((isTable) && (isImage)) {
60 throw new IllegalArgumentException("Specify either image or table format, not both. Given="+formatParam);
61 }
62 if (isImage) {
63 returnSpec = new ReturnImage(TargetMaker.makeTarget(response.getWriter()), format);
64 }
65 else {
66
67 returnSpec = new ReturnTable(TargetMaker.makeTarget(response.getWriter()), format);
68 }
69
70 try {
71 server.askQuery(LoginAccount.ANONYMOUS, new Query(circleCon, returnSpec), this);
72 } catch (Throwable e) {
73 doError(response, "SIAP error (RA="+circleCon.getRa()+", DEC="+circleCon.getDec()+", SIZE="+circleCon.getRadius()+", FORMAT="+formatParam+")", e);
74 }
75
76 } catch (NumberFormatException e) {
77 doError(response, "Input parameters not correct",e);
78 }
79 }
80 }
81
82