/*
* 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.soap.SOAPException;
// import org.apache.soap.Fault;
// import org.apache.soap.Constants;
// import org.apache.soap.rpc.Call;
// import org.apache.soap.rpc.Parameter;
// import org.apache.soap.rpc.Response;
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: 9874 $
* @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() {
// Set Encoding Style to standard SOAP encoding
//call_.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// set Encoding Style to use literal XML
//call_.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML);
}
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);
remote_site_address_ = site_elem.getAttribute(GSXML.ADDRESS_ATT);
if (remote_site_name_==null || remote_site_name_.equals("")) {
System.err.println("SOAPCommunicator: must have name attribute in site element");
return false;
}
if (remote_site_address_==null || remote_site_address_.equals("")) {
System.err.println("SOAPCommunicator: must have address attribute in site element");
return false;
}
try {
Service service = new Service();
call_ = (Call) service.createCall();
//call_.setTargetObjectURI(remote_site_name_);
//call_.setMethodName("process");
call_.setTargetEndpointAddress( new java.net.URL(remote_site_address_) );
// call_.setOperationStyle(org.apache.axis.enum.Style.MESSAGE_STR);
//call_.setOperationUse(org.apache.axis.enum.Use.LITERAL_STR);
//call_.setOperationName(new QName("http://soapinterop.org/", "process"));
} 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 = "";
//message = "";
Element request_elem = converter.getDOM(message).getDocumentElement();
Element response = comm.process(request_elem);
System.err.println("response was "+converter.getPrettyString(response));
}
/*
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;iFault Occurred. No greeting for you!"+GSXML.MESSAGE_ELEM+">").getDocumentElement();
}
} catch (SOAPException e) {
System.out.println("SOAP error:"+e.getMessage());
return null;
} catch (MalformedURLException e) {
System.out.println("URL error:"+e.getMessage());
return null;
}
}
*/
}