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.dataservice.service.DataServer;
12 import org.astrogrid.dataservice.service.ServletHelper;
13 import org.astrogrid.io.account.LoginAccount;
14 import org.astrogrid.query.Query;
15 import org.astrogrid.query.returns.ReturnImage;
16 import org.astrogrid.query.returns.ReturnSpec;
17 import org.astrogrid.query.returns.ReturnTable;
18 import org.astrogrid.slinger.targets.WriterTarget;
19 import org.astrogrid.webapp.DefaultServlet;
20
21 /***
22 * Simple image access protocol. Consists of a query that returns either an image
23 * or a table that
24 * has URLs to the images themselves. This class handles the initial
25 * query
26 * @see http://www.ivoa.net/Documents/latest/SIA.html
27 *
28 * @author M Hill
29 * @author K Andrews
30 * @deprecated KEA: I don't believe this is the correct way to do the intial
31 * query in SIAP - it is using the maths for a conesearch, but that isn't
32 * correct for a SIAP image intersection I don't think...
33 */
34 public class SimpleImageQuery extends DefaultServlet {
35
36 DataServer server = new DataServer();
37
38 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
39
40 try {
41
42
43 double radius = ServletHelper.getRadius(request);
44 double ra = ServletHelper.getRa(request);
45 double dec = ServletHelper.getDec(request);
46
47 String formatParam = request.getParameter("FORMAT");
48 if (formatParam == null) formatParam = request.getParameter("format");
49
50
51 StringTokenizer tokenizer = new StringTokenizer(formatParam, ",");
52 String[] formats = new String[tokenizer.countTokens()];
53 for (int i = 0; i < formats.length; i++) {
54 formats[i] = tokenizer.nextToken();
55 }
56
57
58
59 String format = formats[0];
60
61 ReturnSpec returnSpec = null;
62 boolean isTable = (ReturnTable.isTableFormat(formats));
63 boolean isImage = (ReturnImage.isImageFormat(formats));
64
65
66 if ((isTable) && (isImage)) {
67 throw new IllegalArgumentException("Specify either image or table format, not both. Given="+formatParam);
68 }
69 if (isImage) {
70 returnSpec = new ReturnImage(new WriterTarget(response.getWriter()), format);
71 }
72 else {
73
74 returnSpec = new ReturnTable(
75 new WriterTarget(response.getWriter()), format);
76 }
77
78 try {
79
80 server.askQuery(LoginAccount.ANONYMOUS,
81 new Query(ra, dec, radius, returnSpec),
82 this
83 );
84 } catch (Throwable e) {
85 doError(response,
86 "Pseudo-SIAP RA= " + Double.toString(ra) +
87 ", Dec = " + Double.toString(dec) +
88 ", radius = " + Double.toString(radius) +
89 ", format = " + formatParam,
90 e);
91
92 }
93
94 } catch (NumberFormatException e) {
95 doError(response, "Input parameters not correct",e);
96 }
97 }
98 }
99
100