source: trunk/gsdl3/src/java/org/greenstone/gsdl3/SOAPServerlocalsite.java@ 9886

Last change on this file since 9886 was 9874, checked in by kjdon, 19 years ago

merged from branch ant-install-branch: merge 1

  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/*
2 * SOAPServer.java
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 */
19package org.greenstone.gsdl3;
20
21import org.greenstone.gsdl3.core.*;
22import org.greenstone.gsdl3.util.GSXML;
23import org.w3c.dom.Element;
24import java.io.File;
25import java.io.BufferedReader;
26import java.io.FileReader;
27import java.net.URL;
28
29/**
30 * The server side of a SOAP connection
31 *
32 * @author <a href="mailto:[email protected]">Katherine Don</a>
33 * @version $Revision: 9874 $
34 * @see <a href="http://www.w3.org/TR/SOAP/">Simple Object Access Protocol (SOAP) 1.1 </a>
35 */
36
37public class SOAPServerlocalsite
38 //implements ModuleInterface {
39{
40 private String config_file_name = "SOAPServer.cfg";
41
42 /** The message router we're talking to */
43 MessageRouter mr_=null;
44
45 /** The no-args constructor */
46 public SOAPServerlocalsite() {
47 // find out gsdl3home
48 URL url = ClassLoader.getSystemResource(config_file_name);
49 if (url == null) {
50 System.err.println("Couldn't find the config file "+config_file_name+". Can't initialise the SOAP server");
51 return;
52 }
53 String gsdl3_home = readInFile(url);
54 if (gsdl3_home == null || gsdl3_home.equals("")) {
55 return;
56 }
57 String site_home=gsdl3_home+File.separator+"web"+File.separator+"sites"+File.separator+"localsite";
58
59 File site_file = new File(site_home);
60 if (!site_file.isDirectory()) {
61 System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialsie the SOAP server.");
62 return;
63 }
64 mr_ = new MessageRouter();
65 mr_.setSiteHome(site_home);
66 mr_.configure();
67 }
68
69
70 /** Process a String request */
71// public String process(String xml_in) {
72// return mr_.process(xml_in);
73
74// }
75
76// /** Process an Element request */
77// public Element process(Element xml_in) {
78// return mr_.process(xml_in);
79// }
80
81 public Element [] process (Element [] xml_in) {
82 Element [] result = new Element[xml_in.length];
83 for (int i=0; i<xml_in.length; i++) {
84 Element req = xml_in[i];
85 // get rid of the obligatory namespace that axis needs
86 String tag_name = req.getTagName();
87 String namespace="";
88 if (tag_name.indexOf(':')!= -1) {
89 System.err.println("old tag name="+tag_name);
90 namespace = tag_name.substring(0, tag_name.indexOf(':'));
91 tag_name = tag_name.substring(tag_name.indexOf(':')+1);
92 System.err.println("new tag name="+tag_name);
93
94 }
95 Element new_req = GSXML.duplicateWithNewName(req.getOwnerDocument(), req, tag_name, true);
96 Element r = mr_.process(new_req);
97 // add the namespace back on
98 //Element new_res = r;
99 //if (!namespace.equals("")) {
100 // new_res = GSXML.duplicateWithNewName(r.getOwnerDocument(), r, namespace+r.getTagName(), true);
101 //}
102 result[i] = r;
103 }
104 return result;
105 }
106
107 private String readInFile(URL url) {
108 String file_name = url.getFile();
109 // any spaces are encoded as %20
110 file_name = file_name.replaceAll("%20", " ");
111 try {
112 BufferedReader reader = new BufferedReader(new FileReader(file_name));
113 String line = reader.readLine();
114 line = line.trim();
115 return line;
116 } catch (Exception e) {
117 System.err.println("Exception occurred when reading in the file "+file_name+": "+e);
118 }
119 return null;
120 }
121
122}
123
Note: See TracBrowser for help on using the repository browser.