source: trunk/gsdl3/src/java/org/greenstone/gsdl3/SOAPServer.java.in@ 8081

Last change on this file since 8081 was 8081, checked in by kjdon, 20 years ago

filenames from urls can contain %20 instead of spaces, so need to convert them back

  • Property svn:keywords set to Author Date Id Revision
File size: 2.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.w3c.dom.Element;
23import java.io.File;
24import java.io.BufferedReader;
25import java.io.FileReader;
26import java.net.URL;
27
28/**
29 * The server side of a SOAP connection
30 *
31 * @author <a href="mailto:[email protected]">Katherine Don</a>
32 * @version $Revision: 8081 $
33 * @see <a href="http://www.w3.org/TR/SOAP/">Simple Object Access Protocol (SOAP) 1.1 </a>
34 */
35
36public class SOAPServer
37 implements ModuleInterface {
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() {
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+"@sitename@";
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
69 /** Process a String request */
70 public String process(String xml_in) {
71 return mr_.process(xml_in);
72
73 }
74
75 /** Process an Element request */
76 public Element process(Element xml_in) {
77 return mr_.process(xml_in);
78 }
79
80 private String readInFile(URL url) {
81 String file_name = url.getFile();
82 // any spaces are encoded as %20
83 file_name = file_name.replaceAll("%20", " ");
84 try {
85 BufferedReader reader = new BufferedReader(new FileReader(file_name));
86 String line = reader.readLine();
87 line = line.trim();
88 return line;
89 } catch (Exception e) {
90 System.err.println("Exception occurred when reading in the file "+file_name+": "+e);
91 }
92 return null;
93 }
94
95}
96
Note: See TracBrowser for help on using the repository browser.