|
From: <tr...@us...> - 2003-06-27 00:15:11
|
Update of /cvsroot/babeldoc/babeldoc/modules/soap/src/com/babeldoc/soap/pipeline/command In directory sc8-pr-cvs1:/tmp/cvs-serv19206/modules/soap/src/com/babeldoc/soap/pipeline/command Modified Files: SoapPipelineFeeder.java Log Message: Updated the build system using an explicit modular ant task. This is better than the method previously employed which added "hidden" tasks to the build and clean etc targets. Additionally using a more robust module sorting algorithm. Index: SoapPipelineFeeder.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/soap/src/com/babeldoc/soap/pipeline/command/SoapPipelineFeeder.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** SoapPipelineFeeder.java 22 May 2003 03:20:31 -0000 1.8 --- SoapPipelineFeeder.java 27 Jun 2003 00:14:56 -0000 1.9 *************** *** 1,22 **** ! /* ! * $Header$ ! * $DateTime:$ * * ! * babeldoc: universal document processor * ! * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.babeldoc.soap.pipeline.command; --- 1,66 ---- ! /* ==================================================================== ! * The Apache Software License, Version 1.1 * + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. * ! * Redistribution and use in source and binary forms, with or without ! * modification, are permitted provided that the following conditions ! * are met: * ! * 1. Redistributions of source code must retain the above copyright ! * notice, this list of conditions and the following disclaimer. * ! * 2. Redistributions in binary form must reproduce the above copyright ! * notice, this list of conditions and the following disclaimer in ! * the documentation and/or other materials provided with the ! * distribution. ! * ! * 3. The end-user documentation included with the redistribution, ! * if any, must include the following acknowledgment: ! * "This product includes software developed by the ! * Apache Software Foundation (http://www.apache.org/)." ! * Alternately, this acknowledgment may appear in the software itself, ! * if and wherever such third-party acknowledgments normally appear. ! * ! * 4. The names "Apache" and "Apache Software Foundation" must ! * not be used to endorse or promote products derived from this ! * software without prior written permission. For written ! * permission, please contact ap...@ap.... ! * ! * 5. Products derived from this software may not be called "Apache", ! * nor may "Apache" appear in their name, without prior written ! * permission of the Apache Software Foundation. ! * ! * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ! * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ! * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ! * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ! * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ! * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ! * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ! * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ! * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ! * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ! * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! * SUCH DAMAGE. ! * ==================================================================== ! * ! * This software consists of voluntary contributions made by many ! * individuals on behalf of the Apache Software Foundation. For more ! * information on the Apache Software Foundation, please see ! * <http://www.apache.org/>. ! * ! * Portions of this software are based upon public domain software ! * originally written at the National Center for Supercomputing Applications, ! * University of Illinois, Urbana-Champaign. ! * ==================================================================== ! * ! * Babeldoc: The Universal Document Processor ! * ! * $Header$ ! * $DateTime$ ! * $Author$ * */ package com.babeldoc.soap.pipeline.command; *************** *** 24,42 **** import com.babeldoc.core.I18n; import com.babeldoc.core.LogService; import com.babeldoc.soap.pipeline.util.SoapHelper; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import javax.xml.messaging.URLEndpoint; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.soap.*; - import java.io.IOException; - import java.util.Enumeration; - import java.util.Hashtable; --- 68,92 ---- import com.babeldoc.core.I18n; import com.babeldoc.core.LogService; + import com.babeldoc.soap.pipeline.util.SoapHelper; + import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; + import org.w3c.dom.Document; + import org.xml.sax.InputSource; import org.xml.sax.SAXException; + import java.io.IOException; + + import java.util.Enumeration; + import java.util.Hashtable; + import javax.xml.messaging.URLEndpoint; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.soap.*; *************** *** 49,301 **** */ public class SoapPipelineFeeder extends com.babeldoc.core.BabeldocCommand { ! //~ Static variables/initializers ·········································· ! /* TODO should these things be configurable? how? */ ! /** constant: the uri */ ! public static final String URI = "urn:babeldoc"; ! /** constant: more of the uri */ ! public static final String CTX = "/babeldoc-soapfeed/"; ! /** constant: the dot feed */ ! public static final String DOT_FEED = ".feed"; ! /** constant: the soap action */ ! public static final String ACTION = ""; ! //~ Instance variables ····················································· ! /** instance: the host port */ ! private String hostport; ! /** instance: the pipeline to feed */ ! private String pipeline; ! /** instance: the attributes */ ! private Hashtable attributes; ! //~ Constructors ··························································· ! /** ! * Creates a new SoapPipelineFeeder object. ! * ! * @param args the command line arguments ! */ ! public SoapPipelineFeeder(String[] args) { ! super("soapfeed", I18n.get("soap.001"), args); ! } ! //~ Methods ································································ ! /** ! * Sets name of the pipeline to be used. ! * ! * @param pipeline the name of the pipeline ! */ ! public void setPipeline(String pipeline) { ! this.pipeline = pipeline; ! } ! /** ! * Gets the name of the pipeline that is used. ! * ! * @return the name of the pipeline ! */ ! public String getPipeline() { ! return pipeline; ! } ! /** ! * Sets the host and port part of the SOAP URL ! * ! * @param url a String in the form <host>:<port> ! */ ! public void setUrl(String url) { ! this.hostport = url; } ! /** ! * Gets the host and port part of the SOAP URL ! * ! * @return a String in the form <host>:<port> ! */ ! public String getUrl() { ! return hostport; } ! /** ! * execute the commandline. This must be overloaded to handle the command ! * line options ! * ! * @param commandLine the command line options that have been detectected ! */ ! public void execute(CommandLine commandLine) { ! super.execute(commandLine); ! ! String file = null; ! attributes = new Hashtable(); ! ! if (commandLine.hasOption('u')) { ! hostport = commandLine.getOptionValue('u'); ! } else { ! LogService.getInstance().logError(I18n.get("soap.005"), null); ! } ! ! if (commandLine.hasOption('f')) { ! file = commandLine.getOptionValue('f'); ! } else { ! LogService.getInstance().logError(I18n.get("soap.006"), null); ! } ! ! if (commandLine.hasOption('p')) { ! pipeline = commandLine.getOptionValue('p'); ! } else { ! LogService.getInstance().logError(I18n.get("soap.007"), null); ! } ! ! if (commandLine.hasOption('a')) { ! String namval = commandLine.getOptionValue('a'); ! String name = namval.substring(0, namval.indexOf('=')); ! String value = namval.substring(namval.indexOf('=') + 1); ! attributes.put(name, value); ! } ! ! run(file); } ! /** ! * Main routine ! * ! * @param args the command line arguments ! */ ! static public void main(String[] args) { ! new SoapPipelineFeeder(args); } ! /** ! * Run the soap client ! * ! * @param file ! */ ! public void run(String file) { ! try { ! // get soap body to include in the SOAP envelope ! InputSource xmlSource = new InputSource(com.babeldoc.core.ResourceLoader.getResourceStream( ! file)); ! run(xmlSource); ! } catch (Exception e) { ! e.printStackTrace(); ! } ! } ! /** ! * Run the soap client ! * ! * @param xmlSource ! */ ! public void run(InputSource xmlSource) ! throws SAXException, IOException, ParserConfigurationException, ! SOAPException { ! Document doc = getDocument(xmlSource); ! // create a message ! MessageFactory mf = MessageFactory.newInstance(); ! SOAPMessage message = mf.createMessage(); ! // add the document from the pipeline ! SoapHelper.attachDocument(message, doc); ! // this adds the standard headers ! if (message.saveRequired()) { ! message.saveChanges(); ! } ! // add the SOAPAction header ! MimeHeaders headers = message.getMimeHeaders(); ! headers.setHeader("SOAPAction", ACTION); ! // establish the connection ! String url = getSoapUrl(); ! URLEndpoint endPoint = new URLEndpoint(url); ! SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); ! SOAPConnection connection = scf.createConnection(); ! // send the message and write out the reply ! com.babeldoc.core.LogService.getInstance().logInfo(I18n.get("soap.003")); ! SOAPMessage reply = connection.call(message, endPoint); ! if (reply != null) { // just in case... ! reply.writeTo(System.out); ! System.out.println(); ! } ! com.babeldoc.core.LogService.getInstance().logInfo(I18n.get("soap.004")); ! // close the connection ! connection.close(); } ! /** ! * setup the options on the command line. ! * ! * @param options the options to access ! */ ! public void setupCommandLine(Options options) { ! super.setupCommandLine(options); ! options.addOption(OptionBuilder.isRequired().hasArg() ! .withDescription(com.babeldoc.core.I18n.get( ! "009007")).withLongOpt("pipeline").create('p')); ! options.addOption(OptionBuilder.isRequired().hasArg() ! .withDescription(com.babeldoc.core.I18n.get( ! "009008")).withLongOpt("file").create('f')); ! options.addOption(OptionBuilder.isRequired().hasArg() ! .withDescription(com.babeldoc.core.I18n.get( ! "009009")).withLongOpt("attribute").create('a')); ! options.addOption(OptionBuilder.isRequired().hasArg() ! .withDescription(com.babeldoc.core.I18n.get( ! "010007")).withLongOpt("hostport").create('u')); ! } ! /** ! * Return the document ! * ! * @param xmlSource ! * ! * @return document ! */ ! private Document getDocument(InputSource xmlSource) ! throws SAXException, IOException, ParserConfigurationException { ! DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); ! dfactory.setNamespaceAware(true); ! Document doc = dfactory.newDocumentBuilder().parse(xmlSource); ! return doc; ! } ! /** ! * Get the url to send the message ! * ! * @return the url ! */ ! private String getSoapUrl() { ! StringBuffer url = new StringBuffer("http://" + hostport + CTX + ! pipeline + DOT_FEED); ! if (attributes.size() > 0) { ! url.append("?"); ! for (Enumeration e = attributes.keys(); e.hasMoreElements();) { ! String name = (String) e.nextElement(); ! String value = (String) attributes.get(name); ! url.append(name + "=" + value + "&"); ! } ! url.append("dummy=dummy"); ! } ! return url.toString(); } } --- 99,352 ---- */ public class SoapPipelineFeeder extends com.babeldoc.core.BabeldocCommand { ! /* TODO should these things be configurable? how? */ ! /** constant: the uri */ ! public static final String URI = "urn:babeldoc"; ! /** constant: more of the uri */ ! public static final String CTX = "/babeldoc-soapfeed/"; ! /** constant: the dot feed */ ! public static final String DOT_FEED = ".feed"; ! /** constant: the soap action */ ! public static final String ACTION = ""; ! /** instance: the attributes */ ! private Hashtable attributes; ! /** instance: the host port */ ! private String hostport; ! /** instance: the pipeline to feed */ ! private String pipeline; ! /** ! * Creates a new SoapPipelineFeeder object. ! * ! * @param args the command line arguments ! */ ! public SoapPipelineFeeder(String[] args) { ! super("soapfeed", I18n.get("soap.001"), args); ! } ! /** ! * Sets name of the pipeline to be used. ! * ! * @param pipeline the name of the pipeline ! */ ! public void setPipeline(String pipeline) { ! this.pipeline = pipeline; ! } ! /** ! * Gets the name of the pipeline that is used. ! * ! * @return the name of the pipeline ! */ ! public String getPipeline() { ! return pipeline; ! } ! /** ! * Sets the host and port part of the SOAP URL ! * ! * @param url a String in the form <host>:<port> ! */ ! public void setUrl(String url) { ! this.hostport = url; ! } ! /** ! * Gets the host and port part of the SOAP URL ! * ! * @return a String in the form <host>:<port> ! */ ! public String getUrl() { ! return hostport; ! } ! /** ! * execute the commandline. This must be overloaded to handle the command ! * line options ! * ! * @param commandLine the command line options that have been detectected ! */ ! public void execute(CommandLine commandLine) { ! super.execute(commandLine); ! String file = null; ! attributes = new Hashtable(); ! if (commandLine.hasOption('u')) { ! hostport = commandLine.getOptionValue('u'); ! } else { ! LogService.getInstance().logError(I18n.get("soap.005"), null); } ! if (commandLine.hasOption('f')) { ! file = commandLine.getOptionValue('f'); ! } else { ! LogService.getInstance().logError(I18n.get("soap.006"), null); } ! if (commandLine.hasOption('p')) { ! pipeline = commandLine.getOptionValue('p'); ! } else { ! LogService.getInstance().logError(I18n.get("soap.007"), null); } ! if (commandLine.hasOption('a')) { ! String namval = commandLine.getOptionValue('a'); ! String name = namval.substring(0, namval.indexOf('=')); ! String value = namval.substring(namval.indexOf('=') + 1); ! attributes.put(name, value); } ! run(file); ! } ! /** ! * Main routine ! * ! * @param args the command line arguments ! */ ! public static void main(String[] args) { ! new SoapPipelineFeeder(args); ! } ! /** ! * Run the soap client ! * ! * @param file ! */ ! public void run(String file) { ! try { ! // get soap body to include in the SOAP envelope ! InputSource xmlSource = new InputSource(com.babeldoc.core.ResourceLoader.getResourceStream( ! file)); ! run(xmlSource); ! } catch (Exception e) { ! e.printStackTrace(); ! } ! } ! /** ! * Run the soap client ! * ! * @param xmlSource ! * ! * @throws SAXException DOCUMENT ME! ! * @throws IOException DOCUMENT ME! ! * @throws ParserConfigurationException DOCUMENT ME! ! * @throws SOAPException DOCUMENT ME! ! */ ! public void run(InputSource xmlSource) ! throws SAXException, IOException, ParserConfigurationException, ! SOAPException { ! Document doc = getDocument(xmlSource); ! // create a message ! MessageFactory mf = MessageFactory.newInstance(); ! SOAPMessage message = mf.createMessage(); ! // add the document from the pipeline ! SoapHelper.attachDocument(message, doc); ! // this adds the standard headers ! if (message.saveRequired()) { ! message.saveChanges(); ! } ! // add the SOAPAction header ! MimeHeaders headers = message.getMimeHeaders(); ! headers.setHeader("SOAPAction", ACTION); ! // establish the connection ! String url = getSoapUrl(); ! URLEndpoint endPoint = new URLEndpoint(url); ! SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance(); ! SOAPConnection connection = scf.createConnection(); ! // send the message and write out the reply ! com.babeldoc.core.LogService.getInstance().logInfo(I18n.get("soap.003")); ! SOAPMessage reply = connection.call(message, endPoint); ! if (reply != null) { // just in case... ! reply.writeTo(System.out); ! System.out.println(); } ! com.babeldoc.core.LogService.getInstance().logInfo(I18n.get("soap.004")); ! // close the connection ! connection.close(); ! } ! /** ! * setup the options on the command line. ! * ! * @param options the options to access ! */ ! public void setupCommandLine(Options options) { ! super.setupCommandLine(options); ! options.addOption(OptionBuilder.isRequired().hasArg() ! .withDescription(com.babeldoc.core.I18n.get( ! "009007")).withLongOpt("pipeline").create('p')); ! options.addOption(OptionBuilder.isRequired().hasArg() ! .withDescription(com.babeldoc.core.I18n.get( ! "009008")).withLongOpt("file").create('f')); ! options.addOption(OptionBuilder.isRequired().hasArg() ! .withDescription(com.babeldoc.core.I18n.get( ! "009009")).withLongOpt("attribute").create('a')); ! options.addOption(OptionBuilder.isRequired().hasArg() ! .withDescription(com.babeldoc.core.I18n.get( ! "010007")).withLongOpt("hostport").create('u')); ! } ! /** ! * Return the document ! * ! * @param xmlSource ! * ! * @return document ! * ! * @throws SAXException DOCUMENT ME! ! * @throws IOException DOCUMENT ME! ! * @throws ParserConfigurationException DOCUMENT ME! ! */ ! private Document getDocument(InputSource xmlSource) ! throws SAXException, IOException, ParserConfigurationException { ! DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); ! dfactory.setNamespaceAware(true); ! Document doc = dfactory.newDocumentBuilder().parse(xmlSource); ! return doc; ! } ! /** ! * Get the url to send the message ! * ! * @return the url ! */ ! private String getSoapUrl() { ! StringBuffer url = new StringBuffer("http://" + hostport + CTX + pipeline + ! DOT_FEED); ! if (attributes.size() > 0) { ! url.append("?"); ! for (Enumeration e = attributes.keys(); e.hasMoreElements();) { ! String name = (String) e.nextElement(); ! String value = (String) attributes.get(name); ! url.append(name + "=" + value + "&"); ! } ! ! url.append("dummy=dummy"); } + + return url.toString(); + } } |