[5974] | 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 | package org.greenstone.gsdl3;
|
---|
| 20 |
|
---|
| 21 | import org.greenstone.gsdl3.core.*;
|
---|
| 22 | import org.w3c.dom.Element;
|
---|
[7859] | 23 | import java.io.File;
|
---|
| 24 | import java.io.BufferedReader;
|
---|
| 25 | import java.io.FileReader;
|
---|
| 26 | import java.net.URL;
|
---|
| 27 |
|
---|
[5974] | 28 | /**
|
---|
| 29 | * The server side of a SOAP connection
|
---|
| 30 | *
|
---|
| 31 | * @author <a href="mailto:[email protected]">Katherine Don</a>
|
---|
| 32 | * @version $Revision: 7859 $
|
---|
| 33 | * @see <a href="http://www.w3.org/TR/SOAP/">Simple Object Access Protocol (SOAP) 1.1 </a>
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | public class SOAPServer
|
---|
| 37 | implements ModuleInterface {
|
---|
| 38 |
|
---|
[7859] | 39 | private String config_file_name = "SOAPServer.cfg";
|
---|
| 40 |
|
---|
[5974] | 41 | /** The message router we're talking to */
|
---|
| 42 | MessageRouter mr_=null;
|
---|
| 43 |
|
---|
| 44 | /** The no-args constructor */
|
---|
| 45 | public SOAPServer() {
|
---|
[7859] | 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 | }
|
---|
[5974] | 63 | mr_ = new MessageRouter();
|
---|
| 64 | mr_.setSiteHome(site_home);
|
---|
| 65 | mr_.configure();
|
---|
[7859] | 66 | }
|
---|
[5974] | 67 |
|
---|
[7859] | 68 |
|
---|
[5974] | 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 | }
|
---|
[7859] | 79 |
|
---|
| 80 | private String readInFile(URL url) {
|
---|
| 81 |
|
---|
| 82 | try {
|
---|
| 83 | BufferedReader reader = new BufferedReader(new FileReader(url.getFile()));
|
---|
| 84 | String line = reader.readLine();
|
---|
| 85 | line = line.trim();
|
---|
| 86 | return line;
|
---|
| 87 | } catch (Exception e) {
|
---|
| 88 | System.err.println("Exception occurred when reading in the file "+url.getFile()+": "+e);
|
---|
| 89 | }
|
---|
| 90 | return null;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[5974] | 93 | }
|
---|
| 94 |
|
---|