1
2
3
4
5
6
7 package org.astrogrid.datacenter.service.v06;
8
9 import java.io.IOException;
10 import java.io.StringWriter;
11 import java.net.MalformedURLException;
12 import java.rmi.RemoteException;
13 import javax.xml.rpc.ServiceException;
14 import javax.xml.rpc.server.ServiceLifecycle;
15 import org.apache.axis.AxisFault;
16 import org.astrogrid.community.Account;
17 import org.astrogrid.datacenter.axisdataserver.v05.QueryStatusSoapyBean;
18 import org.astrogrid.datacenter.queriers.status.QuerierStatus;
19 import org.astrogrid.datacenter.query.Adql074Writer;
20 import org.astrogrid.datacenter.query.AdqlQueryMaker;
21 import org.astrogrid.datacenter.query.Query;
22 import org.astrogrid.datacenter.query.SqlQueryMaker;
23 import org.astrogrid.datacenter.service.AxisDataServer;
24 import org.astrogrid.slinger.targets.TargetMaker;
25 import org.astrogrid.status.ServiceStatus;
26
27 /***
28 * The implementation of the Datacenter axis web service for end of Itn06
29 * <p>
30 * When Axis receives a SOAP message from the client it is routed to this class for processing.
31 * It is a singleton; state comes from the Queriers.
32
33 * @author M Hill
34 *
35 */
36
37 public class AxisDataService_v06 implements ServiceLifecycle {
38
39
40 AxisDataServer server = new AxisDataServer();
41
42 /*** Called by Axis when the service needs to be initialised. Not actuall of
43 * much use, as it only gets called when Axis is called, and other servlet/JSP access
44 * won't do that
45 */
46 public void init(Object context) throws ServiceException {
47 if (context instanceof javax.xml.rpc.server.ServletEndpointContext) {
48 javax.xml.rpc.server.ServletEndpointContext secontext = (javax.xml.rpc.server.ServletEndpointContext) context;
49
50 }
51 }
52
53 public void destroy() {
54 }
55
56 /***
57 * Ask adql query (blocking request). Returns results.
58 */
59 public String askAdql(String adql, String requestedFormat) throws AxisFault {
60 try {
61 StringWriter sw = new StringWriter();
62 Query query = AdqlQueryMaker.makeQuery(adql);
63 query.getResultsDef().setFormat(requestedFormat);
64 query.getResultsDef().setTarget(TargetMaker.makeIndicator(sw));
65 server.askQuery(getUser(), query, this);
66 return sw.toString();
67 }
68 catch (Throwable e) {
69 throw server.makeFault(server.SERVERFAULT, e+", asking Query("+adql+", "+requestedFormat+")", e);
70 }
71 }
72
73 /***
74 * Ask adql query (blocking request) sending results to given target
75 */
76 public String askAdql(String adql, String requestedFormat, String target) throws AxisFault {
77 try {
78 Query query = AdqlQueryMaker.makeQuery(adql);
79 query.getResultsDef().setFormat(requestedFormat);
80 query.getResultsDef().setTarget(TargetMaker.makeIndicator(target));
81 server.askQuery(getUser(), query, this);
82 return target.toString();
83 }
84 catch (Throwable e) {
85 throw server.makeFault(server.SERVERFAULT, e+", asking Query("+adql+", "+requestedFormat+", ->"+target+")", e);
86 }
87 }
88
89 /***
90 * Translation service - Converts SQL-like ADQL into XML ADQL
91 */
92 public String adqlSql2xml(String sql) throws AxisFault {
93 try {
94 return Adql074Writer.makeAdql(SqlQueryMaker.makeQuery(sql), "From SQL: "+sql);
95 }
96 catch (Throwable e) {
97 throw server.makeFault(server.SERVERFAULT, e+", converting SQL "+sql, e);
98 }
99 }
100
101 /*** Returns the number of matches - this ought to be part of the select statement but
102 * it will do for temporary use */
103 public long askCount(String adql) throws AxisFault {
104 try {
105 Query query = AdqlQueryMaker.makeQuery(adql);
106 return server.askCount(getUser(), query.getCriteria(), this);
107 }
108 catch (Throwable e) {
109 throw server.makeFault(server.SERVERFAULT, e+", asking Query("+adql+")", e);
110 }
111 }
112
113 /***
114 * Ask raw sql for blocking operation - returns the results
115 *
116 public String askSql(String sql, String requestedFormat) throws AxisFault {
117 try {
118 if (!SimpleConfig.getSingleton().getBoolean(DataServer.SQL_PASSTHROUGH_ENABLED, false)) {
119 throw new UnsupportedOperationException("This server does not support raw SQL queries - use ADQL");
120 }
121
122 StringWriter sw = new StringWriter();
123 Query query = SqlQueryMaker.makeQuery(sql);
124 query.getResultsDef().setFormat(requestedFormat);
125 query.getResultsDef().setTarget(TargetIndicator.makeIndicator(sw));
126 server.askQuery(getUser(), query);
127 return sw.toString();
128 }
129 catch (Throwable e) {
130 throw server.makeFault(server.SERVERFAULT, "Error asking Query("+sql+", "+requestedFormat+")", e);
131 }
132 }
133
134 /**
135 * Submit query for asynchronous operation - returns id of query
136 */
137 public String submitAdql(String adql, String requestedFormat, String resultsTarget) throws AxisFault {
138 try {
139 Query query = AdqlQueryMaker.makeQuery(adql);
140 query.getResultsDef().setFormat(requestedFormat);
141 query.getResultsDef().setTarget(TargetMaker.makeIndicator(resultsTarget));
142 return server.submitQuery(getUser(), query, this);
143 }
144 catch (MalformedURLException mue) {
145 throw server.makeFault(server.CLIENTFAULT, "malformed resultsTarget", mue);
146 }
147 catch (Throwable th) {
148 throw server.makeFault(server.SERVERFAULT, th+", submitting Adql Query", th);
149 }
150 }
151
152
153 /***
154 * Aborts the query specified by the given id. Returns
155 * nothing - if the server can't stop it it's a server-end problem.
156 */
157 public void abortQuery(String queryId) throws AxisFault {
158 try {
159 server.abortQuery(getUser(), queryId);
160 }
161 catch (IOException ioe) {
162 throw server.makeFault(server.SERVERFAULT, ioe+", aborting query "+queryId, ioe);
163 }
164 }
165
166 /***
167 * Returns the state of the query with the given id
168 */
169 public QueryStatusSoapyBean getQueryStatus(String queryId) throws AxisFault {
170 try {
171 QueryStatusSoapyBean soapyStatus = new QueryStatusSoapyBean();
172 soapyStatus.setQueryID(queryId);
173 QuerierStatus status = server.getQueryStatus(getUser(), queryId);
174 soapyStatus.setState(status.getState().toString());
175 soapyStatus.setNote(status.getMessage());
176 return soapyStatus;
177 }
178 catch (IOException ioe) {
179 throw server.makeFault(server.SERVERFAULT, ioe+", getting status of query "+queryId, ioe);
180 }
181 }
182
183 /***
184 * Returns the state of the service
185 */
186 public ServiceStatus getServiceStatus() throws AxisFault {
187 return server.getStatus().getServiceStatus();
188 }
189
190 /***
191 * Returns a simple text string indicating the state of the service
192 */
193 public String getSimpleServiceStatus() throws AxisFault {
194 return server.getStatus().toString();
195 }
196
197 /***
198 * Returns the user from the current Message Context header
199 */
200 protected Account getUser() {
201 return Account.ANONYMOUS;
202 }
203
204 /*** Returns the Registry entries for this service. Same as getMetadata */
205 public String getRegistration() throws RemoteException {
206 try {
207 return server.getMetadata();
208 }
209 catch (IOException ioe) {
210 throw server.makeFault(server.SERVERFAULT, ioe+", getting metadata", ioe);
211 }
212 }
213
214 /*** Returns a document describing the service */
215 public String getMetadata() throws RemoteException {
216 try {
217 return server.getMetadata();
218 }
219 catch (IOException ioe) {
220 throw server.makeFault(server.SERVERFAULT, ioe+", getting metadata", ioe);
221 }
222 }
223
224 /***
225 * Useful mechanism for testing that clients can receive and process faults.
226 * The useful bit of stack trace will be limited to this method but ho hum
227 */
228 public void throwFault() throws AxisFault {
229 throw server.makeFault(server.CLIENTFAULT, "Client asked for this", new IOException("Client deliberately threw test fault "));
230 }
231
232
233
234 }
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316