View Javadoc

1   /*
2    * $Id: AxisDataService_v06.java,v 1.13 2004/11/11 20:42:50 mch Exp $
3    *
4    * (C) Copyright Astrogrid...
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           //erm.
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 $Log: AxisDataService_v06.java,v $
238 Revision 1.13  2004/11/11 20:42:50  mch
239 Fixes to Vizier plugin, introduced SkyNode, started SssImagePlugin
240 
241 Revision 1.12  2004/11/09 18:27:21  mch
242 added askCount
243 
244 Revision 1.11  2004/11/09 17:42:22  mch
245 Fixes to tests after fixes for demos, incl adding closable to targetIndicators
246 
247 Revision 1.10  2004/11/03 00:17:56  mch
248 PAL_MCH Candidate 2 merge
249 
250 Revision 1.6.8.4  2004/11/02 19:41:26  mch
251 Split TargetIndicator to indicator and maker
252 
253 Revision 1.6.8.3  2004/10/27 00:43:40  mch
254 Started adding getCount, some resource fixes, some jsps
255 
256 Revision 1.6.8.2  2004/10/21 19:10:24  mch
257 Removed deprecated translators, moved SqlMaker back to server,
258 
259 Revision 1.6.8.1  2004/10/20 19:09:21  mch
260 Added doc on init
261 
262 Revision 1.6  2004/10/12 21:33:57  mch
263 Slight change to error messages
264 
265 Revision 1.5  2004/10/08 15:16:04  mch
266 More on providing status
267 
268 Revision 1.4  2004/10/06 21:12:17  mch
269 Big Lump of changes to pass Query OM around instead of Query subclasses, and TargetIndicator mixed into Slinger
270 
271 Revision 1.3  2004/10/06 11:35:35  mch
272 A bit of tidying up around the web service interfaces.First stage SkyNode implementation
273 
274 Revision 1.2  2004/10/05 19:22:11  mch
275 Added SQL to ADQL converter method
276 
277 Revision 1.1  2004/10/05 14:56:45  mch
278 Added new web interface and partial skynode
279 
280 Revision 1.2  2004/10/01 18:04:59  mch
281 Some factoring out of status stuff, added monitor page
282 
283 Revision 1.1  2004/09/28 15:02:13  mch
284 Merged PAL and server packages
285 
286 Revision 1.6  2004/08/27 17:47:19  mch
287 Added first servlet; started making more use of ReturnSpec
288 
289 Revision 1.5  2004/08/25 23:38:34  mch
290 (Days changes) moved many query- and results- related classes, renamed packages, added tests, added CIRCLE to sql/adql parsers
291 
292 Revision 1.4  2004/08/18 22:29:39  mch
293 Take more general TargetIndicator rather than AGSL
294 
295 Revision 1.3  2004/08/17 20:19:36  mch
296 Moved TargetIndicator to client
297 
298 Revision 1.2  2004/04/05 15:59:36  mch
299 Introduced multiple services to one deployment
300 
301 Revision 1.1  2004/04/05 15:55:06  mch
302 Renamed it05 axis data service
303 
304 Revision 1.3  2004/03/18 23:42:09  mch
305 Removed dummy getMetadata
306 
307 Revision 1.2  2004/03/17 01:47:26  mch
308 Added v05 Axis web interface
309 
310 Revision 1.1  2004/03/17 00:27:21  mch
311 Added v05 AxisDataServer
312 
313  */
314 
315 
316