|
From: <tr...@us...> - 2003-06-27 00:15:11
|
Update of /cvsroot/babeldoc/babeldoc/modules/soap/src/com/babeldoc/soap/pipeline/servlet In directory sc8-pr-cvs1:/tmp/cvs-serv19206/modules/soap/src/com/babeldoc/soap/pipeline/servlet 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/servlet/SoapPipelineFeeder.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SoapPipelineFeeder.java 22 May 2003 03:20:31 -0000 1.5 --- SoapPipelineFeeder.java 27 Jun 2003 00:14:56 -0000 1.6 *************** *** 1,22 **** ! /* ! * $Header$ ! * $DateTime: 2002/07/24 18:15:55 $ * * ! * 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.servlet; --- 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.servlet; *************** *** 25,30 **** --- 69,82 ---- import com.babeldoc.core.journal.JournalException; import com.babeldoc.core.journal.JournalFactory; + import com.babeldoc.soap.pipeline.util.SoapHelper; + import java.io.IOException; + + import java.util.Enumeration; + import java.util.Iterator; + import java.util.StringTokenizer; + import java.util.Vector; + import javax.servlet.ServletConfig; import javax.servlet.ServletException; *************** *** 33,42 **** import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.xml.soap.*; ! import java.io.IOException; ! import java.util.Enumeration; ! import java.util.Iterator; ! import java.util.StringTokenizer; ! import java.util.Vector; /** --- 85,91 ---- import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import javax.xml.soap.*; ! /** *************** *** 46,243 **** * @version 1.0 */ ! public class SoapPipelineFeeder ! extends HttpServlet { ! ! public final static String DOT_FEED = ".feed"; ! MessageFactory msgFactory; ! public void init(ServletConfig servletConfig) throws ServletException { ! super.init(servletConfig); ! try { ! msgFactory = MessageFactory.newInstance(); ! } catch (SOAPException ex) { ! throw new ServletException("Unable to create message factory" ! + ex.getMessage()); ! } ! } ! ! /** * doGet - this is illegal - must only accept posts. * * @param request * @param response */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ! com.babeldoc.core.LogService.getInstance().logWarn(com.babeldoc.core.I18n.get("017004")); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } ! /** ! * doPost This is where the action happens. Extract the soap envelope. ! * ! * @param request ! * @param response ! */ ! public void doPost(HttpServletRequest request, HttpServletResponse response) ! throws IOException, ServletException { ! //debugHeader(request); ! String pipeline = getPipeline(request); ! com.babeldoc.core.LogService.getInstance().logDebug( ! com.babeldoc.core.I18n.get("017006", pipeline)); ! if (pipeline != null) { ! if (request.getContentLength() > 0) { ! try { ! // Get all the headers from the HTTP request. ! MimeHeaders headers = getHeaders(request); ! // Get the body of the HTTP request. ! ServletInputStream is = request.getInputStream(); ! // Now internalize the contents of the HTTP request and ! // create a SOAPMessage ! SOAPMessage msg = msgFactory.createMessage(headers, is); ! // TODO create a real SOAP response ! IJournalTicket[] tickets = ! processSoapDocument(request, msg, pipeline); ! // if (tickets.length > 0) { ! StringBuffer buffer = new StringBuffer(); ! buffer.append("<tickets>\n"); ! for (int i = 0; i < tickets.length; ++i) { ! buffer.append( ! "<ticket>" + tickets[i].getId() + "</ticket>\n"); ! } ! buffer.append("</tickets>\n"); ! response.setStatus(HttpServletResponse.SC_OK); ! response.setContentType("text/xml"); ! // Need this to prevent Apache SOAP from gacking ! response.getWriter().write(buffer.toString()); ! // } else { ! // response.setStatus(HttpServletResponse.SC_NO_CONTENT); ! // } ! } catch (Exception e) { ! com.babeldoc.core.LogService.getInstance().logError(e); ! throw new ServletException( ! "JAXM POST failed " + e.getMessage(),e); ! } ! } else { ! // TODO send SOAPFault ! com.babeldoc.core.LogService.getInstance().logError( ! com.babeldoc.core.I18n.get("017001"), ! null); ! } ! } else { ! // TODO send SOAPFault ! com.babeldoc.core.LogService.getInstance().logError( ! com.babeldoc.core.I18n.get("017003"), ! null); ! } ! } /** ! * Get the pipeline name from the servlet request path * ! * @param request ! * @return ! * @throws javax.servlet.ServletException */ ! private String getPipeline(HttpServletRequest request) throws ServletException { ! String pipeline = request.getServletPath(); ! if (pipeline.endsWith(DOT_FEED)) { ! pipeline = pipeline.substring(1, pipeline.length() - DOT_FEED.length()); ! } else { ! throw new ServletException(com.babeldoc.core.I18n.get("012005")); } - return pipeline; } ! static MimeHeaders getHeaders(HttpServletRequest req) { ! Enumeration enum = req.getHeaderNames(); ! MimeHeaders headers = new MimeHeaders(); ! while (enum.hasMoreElements()) { ! String headerName = (String) enum.nextElement(); ! String headerValue = req.getHeader(headerName); ! StringTokenizer values = new StringTokenizer(headerValue, ","); ! while (values.hasMoreTokens()) ! headers.addHeader(headerName, values.nextToken().trim()); ! } ! return headers; ! } ! static void putHeaders(MimeHeaders headers, HttpServletResponse res) { ! Iterator it = headers.getAllHeaders(); ! while (it.hasNext()) { ! MimeHeader header = (MimeHeader) it.next(); ! String[] values = headers.getHeader(header.getName()); ! if (values.length == 1) ! res.setHeader(header.getName(), header.getValue()); ! else { ! StringBuffer concat = new StringBuffer(); ! int i = 0; ! while (i < values.length) { ! if (i != 0) ! concat.append(','); ! concat.append(values[i++]); ! } - res.setHeader(header.getName(), concat.toString()); - } - } - } - /** ! * Convert the dom document and and create a pipeline document and add it to the pipeline. * * @param request ! * @param doc ! * @param pipeline */ ! private IJournalTicket[] processSoapDocument(HttpServletRequest request, SOAPMessage msg, ! String pipeline) ! throws com.babeldoc.core.pipeline.PipelineException, JournalException, SOAPException, IOException { ! Vector vec = new Vector(); ! IJournalTicket[] tickets = null; ! ! for (Iterator it = SoapHelper.detachDocuments(msg); it.hasNext();) { ! ! com.babeldoc.core.pipeline.PipelineDocument pdoc = (com.babeldoc.core.pipeline.PipelineDocument)it.next(); ! ! // Apply the request parameters as document attributes ! for (Enumeration parms = request.getParameterNames(); parms.hasMoreElements();) { ! String name = (String) parms.nextElement(); ! String value = request.getParameter(name); ! pdoc.put(name, value); ! } ! try { ! // Get a ticket, add to vector and process ticket. ! IJournalTicket ticket = JournalFactory.getJournal().newTicket(); ! vec.add(ticket); ! com.babeldoc.core.pipeline.PipelineFactoryFactory.process(pipeline, pdoc, ticket, null); ! } catch (Exception e) { ! com.babeldoc.core.LogService.getInstance().logError("something went wrong",e); ! } } ! tickets = new IJournalTicket[vec.size()]; ! if (vec.size() > 0) { ! vec.copyInto((Object[]) tickets); ! } ! return tickets; } --- 95,268 ---- * @version 1.0 */ ! public class SoapPipelineFeeder extends HttpServlet { ! public static final String DOT_FEED = ".feed"; MessageFactory msgFactory; ! /** * doGet - this is illegal - must only accept posts. * * @param request * @param response + * + * @throws IOException DOCUMENT ME! + * @throws ServletException DOCUMENT ME! */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ! com.babeldoc.core.LogService.getInstance().logWarn(com.babeldoc.core.I18n.get( ! "017004")); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } ! /** ! * doPost This is where the action happens. Extract the soap envelope. ! * ! * @param request ! * @param response ! * ! * @throws IOException DOCUMENT ME! ! * @throws ServletException DOCUMENT ME! ! */ ! public void doPost(HttpServletRequest request, HttpServletResponse response) ! throws IOException, ServletException { ! //debugHeader(request); ! String pipeline = getPipeline(request); ! com.babeldoc.core.LogService.getInstance().logDebug(com.babeldoc.core.I18n.get( ! "017006", pipeline)); ! if (pipeline != null) { ! if (request.getContentLength() > 0) { ! try { ! // Get all the headers from the HTTP request. ! MimeHeaders headers = getHeaders(request); ! // Get the body of the HTTP request. ! ServletInputStream is = request.getInputStream(); ! // Now internalize the contents of the HTTP request and ! // create a SOAPMessage ! SOAPMessage msg = msgFactory.createMessage(headers, is); ! // TODO create a real SOAP response ! IJournalTicket[] tickets = processSoapDocument(request, msg, pipeline); ! // if (tickets.length > 0) { ! StringBuffer buffer = new StringBuffer(); ! buffer.append("<tickets>\n"); ! for (int i = 0; i < tickets.length; ++i) { ! buffer.append("<ticket>" + tickets[i].getId() + "</ticket>\n"); ! } ! buffer.append("</tickets>\n"); ! response.setStatus(HttpServletResponse.SC_OK); ! response.setContentType("text/xml"); ! // Need this to prevent Apache SOAP from gacking ! response.getWriter().write(buffer.toString()); ! ! // } else { ! // response.setStatus(HttpServletResponse.SC_NO_CONTENT); ! // } ! } catch (Exception e) { ! com.babeldoc.core.LogService.getInstance().logError(e); ! throw new ServletException("JAXM POST failed " + e.getMessage(), e); ! } ! } else { ! // TODO send SOAPFault ! com.babeldoc.core.LogService.getInstance().logError(com.babeldoc.core.I18n.get( ! "017001"), null); ! } ! } else { ! // TODO send SOAPFault ! com.babeldoc.core.LogService.getInstance().logError(com.babeldoc.core.I18n.get( ! "017003"), null); ! } ! } /** ! * DOCUMENT ME! * ! * @param servletConfig DOCUMENT ME! ! * ! * @throws ServletException DOCUMENT ME! */ ! public void init(ServletConfig servletConfig) throws ServletException { ! super.init(servletConfig); ! ! try { ! msgFactory = MessageFactory.newInstance(); ! } catch (SOAPException ex) { ! throw new ServletException("Unable to create message factory" + ! ex.getMessage()); } } + static MimeHeaders getHeaders(HttpServletRequest req) { + Enumeration enum = req.getHeaderNames(); + MimeHeaders headers = new MimeHeaders(); ! while (enum.hasMoreElements()) { ! String headerName = (String) enum.nextElement(); ! String headerValue = req.getHeader(headerName); ! StringTokenizer values = new StringTokenizer(headerValue, ","); ! while (values.hasMoreTokens()) { ! headers.addHeader(headerName, values.nextToken().trim()); ! } ! } ! return headers; ! } ! static void putHeaders(MimeHeaders headers, HttpServletResponse res) { ! Iterator it = headers.getAllHeaders(); ! while (it.hasNext()) { ! MimeHeader header = (MimeHeader) it.next(); ! String[] values = headers.getHeader(header.getName()); ! if (values.length == 1) { ! res.setHeader(header.getName(), header.getValue()); ! } else { ! StringBuffer concat = new StringBuffer(); ! int i = 0; ! ! while (i < values.length) { ! if (i != 0) { ! concat.append(','); ! } ! ! concat.append(values[i++]); ! } ! ! res.setHeader(header.getName(), concat.toString()); ! } ! } ! } /** ! * Get the pipeline name from the servlet request path * * @param request ! * ! * @return ! * ! * @throws ServletException */ ! private String getPipeline(HttpServletRequest request) ! throws ServletException { ! String pipeline = request.getServletPath(); ! if (pipeline.endsWith(DOT_FEED)) { ! pipeline = pipeline.substring(1, pipeline.length() - DOT_FEED.length()); ! } else { ! throw new ServletException(com.babeldoc.core.I18n.get("012005")); } ! return pipeline; } *************** *** 253,265 **** // Traverse the HTTP headers and show them on the screen ! for (Enumeration enum = request.getHeaderNames(); ! enum.hasMoreElements();) { String header = (String) enum.nextElement(); String value = request.getHeader(header); ! com.babeldoc.core.LogService.getInstance().logDebug(" " + header + " = " + value); } com.babeldoc.core.LogService.getInstance().logDebug("-----------------------"); } } --- 278,344 ---- // Traverse the HTTP headers and show them on the screen ! for (Enumeration enum = request.getHeaderNames(); enum.hasMoreElements();) { String header = (String) enum.nextElement(); String value = request.getHeader(header); ! com.babeldoc.core.LogService.getInstance().logDebug(" " + header + ! " = " + value); } com.babeldoc.core.LogService.getInstance().logDebug("-----------------------"); + } + + /** + * Convert the dom document and and create a pipeline document and add it to + * the pipeline. + * + * @param request + * @param msg + * @param pipeline + * + * @return DOCUMENT ME! + * + * @throws com.babeldoc.core.pipeline.PipelineException DOCUMENT ME! + * @throws JournalException DOCUMENT ME! + * @throws SOAPException DOCUMENT ME! + * @throws IOException DOCUMENT ME! + */ + private IJournalTicket[] processSoapDocument(HttpServletRequest request, + SOAPMessage msg, String pipeline) + throws com.babeldoc.core.pipeline.PipelineException, JournalException, + SOAPException, IOException { + Vector vec = new Vector(); + IJournalTicket[] tickets = null; + + for (Iterator it = SoapHelper.detachDocuments(msg); it.hasNext();) { + com.babeldoc.core.pipeline.PipelineDocument pdoc = (com.babeldoc.core.pipeline.PipelineDocument) it.next(); + + // Apply the request parameters as document attributes + for (Enumeration parms = request.getParameterNames(); + parms.hasMoreElements();) { + String name = (String) parms.nextElement(); + String value = request.getParameter(name); + pdoc.put(name, value); + } + + try { + // Get a ticket, add to vector and process ticket. + IJournalTicket ticket = JournalFactory.getJournal().newTicket(); + vec.add(ticket); + com.babeldoc.core.pipeline.PipelineFactoryFactory.process(pipeline, + pdoc, ticket, null); + } catch (Exception e) { + com.babeldoc.core.LogService.getInstance().logError("something went wrong", + e); + } + } + + tickets = new IJournalTicket[vec.size()]; + + if (vec.size() > 0) { + vec.copyInto((Object[]) tickets); + } + + return tickets; } } |