cziegeler    01/10/12 08:16:38

  Modified:    src/org/apache/cocoon/components/language/markup/xsp
                        SOAPHelper.java
               src/org/apache/cocoon/components/xscript
                        XScriptObjectInlineXML.java
  Added:       lib      commons-httpclient-20011012.jar
  Log:
  Making SOAP logicsheet work again with httpclient from jakarta-commons
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/lib/commons-httpclient-20011012.jar
  
        <<Binary file>>
  
  
  1.3       +78 -63    
xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/SOAPHelper.java
  
  Index: SOAPHelper.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/SOAPHelper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SOAPHelper.java   2001/10/11 10:40:00     1.2
  +++ SOAPHelper.java   2001/10/12 15:16:37     1.3
  @@ -7,27 +7,26 @@
    
*****************************************************************************/
   package org.apache.cocoon.components.language.markup.xsp;
   
  -import java.net.URL;
  -import java.net.MalformedURLException;
  -import java.io.OutputStream;
  -import java.io.InputStreamReader;
  -import java.io.InputStream;
  -import java.io.IOException;
   import java.io.BufferedReader;
  -
  -import org.xml.sax.InputSource;
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.io.InputStreamReader;
  +import java.io.OutputStream;
  +import java.net.MalformedURLException;
  +import java.net.URL;
  +import java.util.HashMap;
  +import org.apache.avalon.framework.component.ComponentException;
  +import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.xscript.XScriptManager;
   import org.apache.cocoon.components.xscript.XScriptObject;
   import org.apache.cocoon.components.xscript.XScriptObjectInlineXML;
  -import org.apache.cocoon.ProcessingException;
  -
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.ComponentException;
   
  -//import HTTPClient.HTTPConnection;
  -//import HTTPClient.HttpOutputStream;
  -//import HTTPClient.HTTPResponse;
  -//import HTTPClient.NVPair;
  +import org.apache.commons.httpclient.Header;
  +import org.apache.commons.httpclient.HttpConnection;
  +import org.apache.commons.httpclient.HttpState;
  +import org.apache.commons.httpclient.methods.PostMethod;
  +import org.xml.sax.InputSource;
   
   /**
    * Helper for the SOAP logicsheet.
  @@ -39,71 +38,87 @@
   {
     XScriptManager xscriptManager;
     URL url;
  -  String method = "";
  +  String action = "";
     XScriptObject xscriptObject;
   
     public SOAPHelper(ComponentManager manager, String urlContext, String url,
  -                    String method, XScriptObject xscriptObject)
  +                    String action, XScriptObject xscriptObject)
       throws MalformedURLException, ComponentException
     {
       this.xscriptManager = 
(XScriptManager)manager.lookup(XScriptManager.ROLE);
       URL context = new URL(urlContext);
       this.url = new URL(context, url);
  -    this.method = method;
  +    this.action = action;
       this.xscriptObject = xscriptObject;
     }
   
     public XScriptObject invoke()
       throws ProcessingException
     {
  -  /*  try {
  -      if (method == null || method.equals(""))
  -        method = "\"\"";
  -
  -      HTTPConnection conn = new HTTPConnection(url);
  -      NVPair[] headers = new NVPair[] {
  -        new NVPair("Content-type", "text/xml; charset=\"utf-8\""),
  -        new NVPair("SOAPAction", method)
  -      };
  -      HttpOutputStream out = new HttpOutputStream();
  -
  -      HTTPResponse response = conn.Post(url.getPath(), out, headers);
  -
  -      // Write the SOAP request
  -      InputSource saxInputStream = xscriptObject.getInputSource();
  -      InputStream is = saxInputStream.getByteStream();
  -      byte[] buffer = new byte[1024];
  -      int len;
  -      while ((len = is.read(buffer)) > 0)
  -        out.write(buffer, 0, len);
  -      is.close();
  -      out.flush();
  -      out.close();
  -
  -      // Read the results from the server
  -      InputStreamReader isr = new 
InputStreamReader(response.getInputStream());
  -      BufferedReader br = new BufferedReader(isr);
  -      StringBuffer resultBuffer = new StringBuffer();
  +    HttpConnection conn = null;
   
  -      char[] cbuffer = new char[1024];
  +    try {
  +      if (action == null || action.equals(""))
  +        action = "\"\"";
  +
  +      String host = url.getHost();
  +      int port = url.getPort();
  +
  +      if (System.getProperty("http.proxyHost") != null) {
  +        String proxyHost = System.getProperty("http.proxyHost");
  +        int proxyPort = 
Integer.parseInt(System.getProperty("http.proxyPort"));
  +        conn = new HttpConnection(proxyHost, proxyPort, host, port);
  +     }
  +      else
  +        conn = new HttpConnection(host, port);
  +
  +      PostMethod method = new PostMethod(url.getFile()) {
  +          protected String generateRequestBody(HashMap params)
  +          {
  +            try {
  +              StringBuffer bodyBuffer
  +                = new StringBuffer(super.generateRequestBody(params));
  +              bodyBuffer.append("\n");
  +
  +              // Write the SOAP request
  +              InputSource saxInputStream = xscriptObject.getInputSource();
  +              InputStream is = saxInputStream.getByteStream();
  +              InputStreamReader isr = new InputStreamReader(is);
  +
  +              char[] buffer = new char[1024];
  +              int len;
  +              while ((len = isr.read(buffer)) > 0)
  +                bodyBuffer.append(buffer, 0, len);
  +              isr.close();
  +              is.close();
  +              return bodyBuffer.toString();
  +            }
  +            catch (Exception ex) {
  +              return null;
  +            }
  +          }
  +        };
  +
  +        method.setRequestHeader(
  +                new Header("Content-type", "text/xml; charset=\"utf-8\""));
  +        method.setRequestHeader(new Header("SOAPAction", action));
  +        method.setUseDisk(false);
  +
  +        method.execute(new HttpState(), conn);
  +        return new XScriptObjectInlineXML(xscriptManager,
  +                                          method.getResponseBodyAsString());
  +    }
  +    catch (Exception ex) {
  +      throw new ProcessingException("Error invoking remote service: " + ex,
  +                                    ex);
  +    }
  +    finally {
         try {
  -        while ((len = br.read(cbuffer)) > 0)
  -          resultBuffer.append(cbuffer, 0, len);
  -        br.close();
  -        isr.close();
  -        is.close();
  +        if (conn != null)
  +          conn.close();
         }
  -      catch (IOException ex) {
  -        if (resultBuffer.length() == 0)
  -          throw ex;
  +      catch (Exception ex) {
         }
  -
  -      return new XScriptObjectInlineXML(xscriptManager, resultBuffer);
  -    }
  -    catch (Exception ex) {
  -      throw new ProcessingException(ex);
       }
  -      */
  -      return null;
     }
   }
  
  
  
  1.2       +7 -0      
xml-cocoon2/src/org/apache/cocoon/components/xscript/XScriptObjectInlineXML.java
  
  Index: XScriptObjectInlineXML.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/xscript/XScriptObjectInlineXML.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XScriptObjectInlineXML.java       2001/10/10 20:53:56     1.1
  +++ XScriptObjectInlineXML.java       2001/10/12 15:16:38     1.2
  @@ -48,6 +48,13 @@
       streamHandler = new StringBufferContentHandler(stringBuffer);
     }
   
  +  public XScriptObjectInlineXML(XScriptManager manager, String string)
  +  {
  +    super(manager);
  +    this.stringBuffer = new StringBuffer(string);
  +    streamHandler = new StringBufferContentHandler(stringBuffer);
  +  }
  +
     public InputStream getInputStream()
       throws ProcessingException, IOException
     {
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to