1
2
3
4
5
6
7
8
9
10
11
12
13 package org.astrogrid.ace.webservice.axis;
14
15 import javax.xml.parsers.DocumentBuilderFactory;
16 import javax.xml.parsers.DocumentBuilder;
17 import javax.xml.soap.SOAPMessage;
18
19 import org.w3c.dom.Document;
20 import org.w3c.dom.DocumentType;
21 import org.w3c.dom.Element;
22 import org.w3c.dom.NodeList;
23 import org.w3c.dom.Node;
24 import org.w3c.dom.CDATASection;
25 import org.w3c.dom.Text;
26 import org.w3c.dom.Attr;
27 import org.w3c.dom.NamedNodeMap;
28
29 import org.apache.axis.AxisFault;
30 import org.apache.axis.utils.XMLUtils;
31 import org.apache.axis.message.SOAPBodyElement;
32
33 import org.astrogrid.ace.web.Ace;
34 import org.astrogrid.ace.service.AceContext;
35
36
37
38
39 import org.astrogrid.xmlutils.XmlValidatorIfc;
40 import org.astrogrid.xmlutils.XmlValidatorXercesImpl;
41
42
43 import org.astrogrid.log.Log;
44
45
46 import java.io.StringReader;
47 import java.io.IOException;
48 import java.util.Vector;
49
50
51
52
53 import java.io.BufferedWriter;
54 import java.io.FileWriter;
55
56 /***
57 * <p>???
58 *
59 * <p>???
60 *
61 * <p>See ???.java for a ???
62 *
63 * <p>TO DO: <ul>
64 * <li>Nicer exception-throwing and handling?</li>
65 * </ul>
66 *
67 *
68 * @see org.astrogrid.ace.webservice.axis.???
69 * @see AceService_deploy.wsdd
70 * @see AceService_undeploy.wsdd
71 *
72 * @author Kona Andrews,
73 * <a href="mailto:kea@ast.cam.ac.uk">kea@ast.cam.ac.uk</a>
74 * @version 1.0
75 */
76
77
78 public class AceService
79 {
80 /***
81 * Location of logfile - each instance should have a separate logfile -
82 fix this when policy is decided re instance working directories etc.
83 */
84
85
86
87
88 static final String LOGFILE = "/dev/null";
89
90
91 /***
92 * Dummy constructor - does nothing.
93 */
94 public AceService()
95 {
96 }
97
98 /***
99 * This function is the Ace web-service's public interface.
100 * It accepts a DOM Element representing the root of an XML
101 * document n
102 *
103 * @param xmlIn A (pre-initialised) reader for the input XML
104 *
105 * @return A Document containing the DOM tree for the input XML.
106 */
107
108 public Element[] processParams(Element[] soapBodyElements) throws AxisFault
109 {
110 try
111 {
112 net.mchill.log.Log.addHandler(new net.mchill.log.Log2File(LOGFILE));
113
114
115 Element soapBody = soapBodyElements[0];
116
117 Log.trace("Webservice: Validating XML input against its schema");
118
119 XmlValidatorXercesImpl validator = new XmlValidatorXercesImpl();
120 StringReader reader =
121 new StringReader(XMLUtils.ElementToString(soapBody));
122
123
124 try
125 {
126 validator.validate(reader);
127 }
128 catch (Exception e)
129 {
130 AxisFault fault = AxisFault.makeFault(e);
131 fault.setFaultCode("Client.InvalidXMLDocument");
132 throw fault;
133 }
134
135
136
137
138
139 Log.trace("Webservice: Doing Ace wrapper call");
140 Element result = doSExtractorCall(soapBody);
141 Log.trace("Webservice: Done SExtractor call");
142
143 return makeVOTableReturn(result);
144
145
146 }
147
148 catch (Exception e)
149 {
150 throw AxisFault.makeFault(e);
151 }
152 }
153
154
155 protected Element[] makeVOTableReturn(Element result) throws Exception
156 {
157
158
159 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
160 factory.setNamespaceAware(false);
161 DocumentBuilder builder = factory.newDocumentBuilder();
162
163 Document responseDoc = builder.newDocument();
164
165 Element[] wsResult = new Element[1];
166 wsResult[0] = result;
167 return wsResult;
168 }
169
170 protected Element[] makeStatusReturn(Element result) throws Exception
171 {
172
173
174 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
175 factory.setNamespaceAware(true);
176 DocumentBuilder builder = factory.newDocumentBuilder();
177
178 Document responseDoc = builder.newDocument();
179
180 Element resRoot = responseDoc.createElementNS(
181 "http://www.astrogrid.org/namespace/SimpleReturnDoc",
182 "ReturnString");
183
184 String status = "";
185 if (result != null)
186 {
187 status = "SExtractor run complete - results in sexResults.xml";
188 }
189 else
190 {
191 status = "SExtractor run FAILED - null results node received";
192 }
193
194 Text eltText = responseDoc.createTextNode(status);
195 resRoot.appendChild(eltText);
196
197 Element[] wsResult = new Element[1];
198 wsResult[0] = resRoot;
199 return wsResult;
200 }
201
202
203 protected Element doSExtractorCall(Element soapBody) throws IOException
204 {
205 Ace ace = new Ace();
206 return ace.runApplication(soapBody);
207 }
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
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