/* * SOAPCommunicator.java * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.greenstone.gsdl3.comms; import org.greenstone.gsdl3.util.*; import org.greenstone.gsdl3.core.*; // classes needed for SOAP stuff import java.net.URL; import java.net.MalformedURLException; import java.util.Vector; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.message.SOAPBodyElement; import javax.xml.namespace.QName; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Document; import org.w3c.dom.Element; /* * The Client side of a SOAP Connection * * @author Katherine Don * @version $Revision: 11022 $ * @see Simple Object Access Protocol (SOAP) 1.1 */ public class SOAPCommunicator extends Communicator { /** address of site to connect to */ protected String remote_site_address_=null; /** the call object that does the SOAP talking */ private Call call_ = null; /** The no-args constructor */ public SOAPCommunicator() { } public boolean configure(Element site_elem) { String type = site_elem.getAttribute(GSXML.TYPE_ATT); if (!type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) { System.err.println("SOAPCommunicator: wrong type of site"); return false; } remote_site_name_ = site_elem.getAttribute(GSXML.NAME_ATT); if (remote_site_name_.equals("")) { System.err.println("SOAPCommunicator: must have name attribute in site element"); return false; } remote_site_address_ = site_elem.getAttribute(GSXML.ADDRESS_ATT); String local_site_name = site_elem.getAttribute(GSXML.LOCAL_SITE_ATT); if (remote_site_address_.equals("") && local_site_name.equals("")) { System.err.println("SOAPCommunicator: must have address or localSite attributes in site element"); return false; } if (remote_site_address_.equals("")) { remote_site_address_ = GlobalProperties.getGSDL3WebAddress()+"/services/"+local_site_name; } try { Service service = new Service(); call_ = (Call) service.createCall(); call_.setTargetEndpointAddress( new java.net.URL(remote_site_address_) ); } catch (Exception e) { System.err.println("SOAPCommunicator.configure() Error: Exception occurred "+e); return false; } return true; } public Element process(Element message) { NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM); if (requests.getLength()==0) { // no requests return null; } // if the communicator is part of a site, it needs to edit the to and from fields, otherwise it just passes the message on, as is // for now, use local_site_name_ as the flag. if (local_site_name_!=null) { // no local site for (int i=0;i"; Element site_elem = converter.getDOM(message).getDocumentElement(); comm.configure(site_elem); message = ""; Element request_elem = converter.getDOM(message).getDocumentElement(); Element response = comm.process(request_elem); System.err.println("response was "+converter.getPrettyString(response)); } }