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