cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject cvs commit: cocoon-2.0/src/java/org/apache/cocoon/components/language/markup/xsp SOAPHelper.java
Date Thu, 21 Aug 2003 02:11:59 GMT
joerg       2003/08/20 19:11:59

  Modified:    src/java/org/apache/cocoon/components/language/markup/xsp
                        SOAPHelper.java
  Log:
  Updated HttpClient to the latest version 2.0 RC 1. Backported changes to SOAPHelper from
Cocoon 2.1.
  
  Revision  Changes    Path
  1.2       +42 -49    cocoon-2.0/src/java/org/apache/cocoon/components/language/markup/xsp/SOAPHelper.java
  
  Index: SOAPHelper.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.0/src/java/org/apache/cocoon/components/language/markup/xsp/SOAPHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SOAPHelper.java	9 Mar 2003 00:01:56 -0000	1.1
  +++ SOAPHelper.java	21 Aug 2003 02:11:59 -0000	1.2
  @@ -50,6 +50,11 @@
   */
   package org.apache.cocoon.components.language.markup.xsp;
   
  +import java.io.InputStreamReader;
  +import java.io.Reader;
  +import java.net.MalformedURLException;
  +import java.net.URL;
  +
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   
  @@ -62,13 +67,8 @@
   import org.apache.commons.httpclient.HttpConnection;
   import org.apache.commons.httpclient.HttpState;
   import org.apache.commons.httpclient.methods.PostMethod;
  -import org.xml.sax.InputSource;
   
  -import java.io.InputStreamReader;
  -import java.io.Reader;
  -import java.net.MalformedURLException;
  -import java.net.URL;
  -import java.util.HashMap;
  +import org.xml.sax.InputSource;
   
   /**
    * Helper for the SOAP logicsheet.
  @@ -115,51 +115,46 @@
                   conn = new HttpConnection(host, port);
               }
   
  -            PostMethod method = new PostMethod(url.getFile()) {
  -                protected String generateRequestBody(HashMap params) {
  -                    try {
  -                        StringBuffer bodyBuffer
  -                                = new StringBuffer(super.generateRequestBody(params));
  +            PostMethod method = new PostMethod(url.getFile());
  +            String request;
   
  -                        // Write the SOAP request body
  -                        if (xscriptObject instanceof XScriptObjectInlineXML) {
  -                            // Skip overhead
  -                            bodyBuffer.append(((XScriptObjectInlineXML) xscriptObject).getContent());
  -                        } else {
  -                            InputSource saxSource = xscriptObject.getInputSource();
  -
  -                            Reader r = null;
  -                            // Byte stream or character stream?
  -                            if (saxSource.getByteStream() != null) {
  -                                r = new InputStreamReader(saxSource.getByteStream());
  -                            } else {
  -                                r = saxSource.getCharacterStream();
  -                            }
  -
  -                            try {
  -                                char[] buffer = new char[1024];
  -                                int len;
  -                                while ((len = r.read(buffer)) > 0)
  -                                    bodyBuffer.append(buffer, 0, len);
  -                            } finally {
  -                                if (r != null) {
  -                                    r.close();
  -                                }
  -                            }
  -                        }
  +            try {
  +                // Write the SOAP request body
  +                if (xscriptObject instanceof XScriptObjectInlineXML) {
  +                    // Skip overhead
  +                    request = ((XScriptObjectInlineXML) xscriptObject).getContent();
  +                } else {
  +                    StringBuffer bodyBuffer = new StringBuffer();
  +                    InputSource saxSource = xscriptObject.getInputSource();
  +
  +                    Reader r = null;
  +                    // Byte stream or character stream?
  +                    if (saxSource.getByteStream() != null) {
  +                        r = new InputStreamReader(saxSource.getByteStream());
  +                    } else {
  +                        r = saxSource.getCharacterStream();
  +                    }
   
  -                        return bodyBuffer.toString();
  -                    } catch (Exception ex) {
  -                        // FIXME (VG): Will result in NPE in httpClient code
  -                        return null;
  +                    try {
  +                        char[] buffer = new char[1024];
  +                        int len;
  +                        while ((len = r.read(buffer)) > 0)
  +                            bodyBuffer.append(buffer, 0, len);
  +                    } finally {
  +                        if (r != null) {
  +                            r.close();
  +                        }
                       }
  +                    request = bodyBuffer.toString();
                   }
  -            };
  +            } catch (Exception ex) {
  +                throw new ProcessingException("Error assembling request", ex);
  +            }
   
               method.setRequestHeader(
                       new Header("Content-type", "text/xml; charset=\"utf-8\""));
               method.setRequestHeader(new Header("SOAPAction", action));
  -            method.setUseDisk(false);
  +            method.setRequestBody(request);
   
               method.execute(new HttpState(), conn);
   
  @@ -169,12 +164,10 @@
                   throw new ProcessingException("Invalid response - no xml");
               }
   
  -            return new XScriptObjectInlineXML(
  -                    xscriptManager,
  -                    ret.substring(startOfXML));
  +            return new XScriptObjectInlineXML(xscriptManager,
  +                                              ret.substring(startOfXML));
           } catch (Exception ex) {
  -            throw new ProcessingException("Error invoking remote service: " + ex,
  -                    ex);
  +            throw new ProcessingException("Error invoking remote service: " + ex, ex);
           } finally {
               try {
                   if (conn != null)
  
  
  

Mime
View raw message