source: greenstone3/trunk/resources/java/SOAPServer.java.in@ 16756

Last change on this file since 16756 was 16756, checked in by ak19, 13 years ago

Since greenstone3 core ModuleInterface.process() now takes a Node and RETURNS a Node, have copied the XMLConverter.nodeToElement() into here to convert the Node back into the Element version of the response.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/*
2 * SOAPServer.java.in: a template for a new SOAPServer
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20package org.greenstone.gsdl3;
21
22import org.greenstone.gsdl3.core.MessageRouter;
23import org.greenstone.gsdl3.util.GlobalProperties;
24import org.greenstone.gsdl3.util.GSFile;
25import org.greenstone.gsdl3.util.GSXML;
26import org.w3c.dom.Element;
27import org.w3c.dom.Node;
28import org.w3c.dom.Document;
29import java.io.File;
30
31/**
32 * The server side of a SOAP connection
33 *
34 * @author <a href="mailto:kjdon@cs.waikato.ac.nz">Katherine Don</a>
35 * @see <a href="http://www.w3.org/TR/SOAP/">Simple Object Access Protocol (SOAP) 1.1 </a>
36 */
37
38public class SOAPServer@sitename@
39{
40
41 /** The message router we're talking to */
42 protected MessageRouter mr=null;
43 /** the name of the site we are serving */
44 protected String site_name = "@sitename@";
45
46 /** The no-args constructor */
47 public SOAPServer@sitename@() {
48 String gsdl3_home = GlobalProperties.getGSDL3Home();
49 if (gsdl3_home == null || gsdl3_home.equals("")) {
50 System.err.println("Couldn't access GSDL3Home from GlobalProerties.getGSDL3HOME, can't initialize the SOAP Server.");
51 return;
52 }
53 String site_home = GSFile.siteHome(gsdl3_home, this.site_name);
54
55 File site_file = new File(site_home);
56 if (!site_file.isDirectory()) {
57 System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialize the SOAP Server.");
58 return;
59 }
60 mr = new MessageRouter();
61 mr.setSiteName(this.site_name);
62 mr.configure();
63 }
64
65
66 public Element [] process (Element [] xml_in) {
67 Element [] result = new Element[xml_in.length];
68 for (int i=0; i<xml_in.length; i++) {
69 Element req = xml_in[i];
70 // get rid of the obligatory namespace that axis needs
71 String tag_name = req.getTagName();
72 String namespace="";
73 if (tag_name.indexOf(':')!= -1) {
74 namespace = tag_name.substring(0, tag_name.indexOf(':'));
75 tag_name = tag_name.substring(tag_name.indexOf(':')+1);
76 }
77 Element new_req = GSXML.duplicateWithNewName(req.getOwnerDocument(), req, tag_name, true);
78 Element r = nodeToElement(mr.process(new_req));
79 // add the namespace back on
80 //Element new_res = r;
81 //if (!namespace.equals("")) {
82 // new_res = GSXML.duplicateWithNewName(r.getOwnerDocument(), r, namespace+r.getTagName(), true);
83 //}
84 result[i] = r;
85 }
86 return result;
87 }
88
89 protected Element nodeToElement(Node node)
90 {
91 short nodeType = node.getNodeType();
92
93 if (nodeType == Node.DOCUMENT_NODE) {
94 Document docNode = (Document)node;
95 return docNode.getDocumentElement() ;
96 }
97 else if (nodeType == Node.ELEMENT_NODE) {
98 return (Element)node;
99 }
100 else {
101 System.err.println("Expecting Document or Element node type but got " + node.getNodeName());
102 System.err.println("Returning null");
103 return null;
104 }
105 }
106}
107
Note: See TracBrowser for help on using the repository browser.