cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r506384 - in /cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl: pom.xml src/main/java/org/apache/cocoon/generation/HttpProxyGenerator.java src/main/java/org/apache/cocoon/generation/WebServiceProxyGenerator.java
Date Mon, 12 Feb 2007 09:17:42 GMT
Author: cziegeler
Date: Mon Feb 12 01:17:42 2007
New Revision: 506384

URL: http://svn.apache.org/viewvc?view=rev&rev=506384
Log:
Update http client to 3.0.1

Modified:
    cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/pom.xml
    cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/src/main/java/org/apache/cocoon/generation/HttpProxyGenerator.java
    cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/src/main/java/org/apache/cocoon/generation/WebServiceProxyGenerator.java

Modified: cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/pom.xml?view=diff&rev=506384&r1=506383&r2=506384
==============================================================================
--- cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/pom.xml (original)
+++ cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/pom.xml Mon Feb 12 01:17:42 2007
@@ -43,7 +43,7 @@
     <dependency>
       <groupId>commons-httpclient</groupId>
       <artifactId>commons-httpclient</artifactId>
-      <version>2.0.2</version>
+      <version>3.0.1</version>
     </dependency>
     <dependency>
       <groupId>javax.servlet</groupId>

Modified: cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/src/main/java/org/apache/cocoon/generation/HttpProxyGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/src/main/java/org/apache/cocoon/generation/HttpProxyGenerator.java?view=diff&rev=506384&r1=506383&r2=506384
==============================================================================
--- cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/src/main/java/org/apache/cocoon/generation/HttpProxyGenerator.java
(original)
+++ cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/src/main/java/org/apache/cocoon/generation/HttpProxyGenerator.java
Mon Feb 12 01:17:42 2007
@@ -37,6 +37,7 @@
 import org.apache.commons.httpclient.HttpState;
 import org.apache.commons.httpclient.HttpURL;
 import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpVersion;
 import org.apache.commons.httpclient.NameValuePair;
 import org.apache.commons.httpclient.URIException;
 import org.apache.commons.httpclient.methods.GetMethod;
@@ -57,16 +58,20 @@
  */
 public class HttpProxyGenerator extends ServiceableGenerator implements Configurable {
 
+    /** The configured method. */
+    private String methodString;
     /** The HTTP method to use at request time. */
-    private HttpMethodBase method = null;
+    private HttpMethodBase method;
     /** The base HTTP URL for requests. */
-    private HttpURL url = null;
+    private HttpURL url;
     /** The list of request parameters for the request */
-    private ArrayList reqParams = null;
+    private ArrayList reqParams;
     /** The list of query parameters for the request */
-    private ArrayList qryParams = null;
+    private ArrayList qryParams;
     /** Wether we want a debug output or not */
     private boolean debug = false;
+    /** The host configuration. */
+    private HostConfiguration hostConfiguration;
 
     /**
      * Default (empty) constructor.
@@ -85,31 +90,25 @@
     public void configure(Configuration configuration)
     throws ConfigurationException {
 
-        /* Setup the HTTP method to use. */
-        String method = configuration.getChild("method").getValue("GET");
-        if ("GET".equalsIgnoreCase(method)) {
-            this.method = new GetMethod();
-        } else if ("POST".equalsIgnoreCase(method)) {
-            this.method = new PostMethod();
-            /* TODO: Is this still needed? Does it refer to a bug in bugzilla?
-             *       At least the handling in httpclient has completely changed.
-             * Work around a bug from the HttpClient library */
-            ((PostMethod) this.method).setRequestBody("");
-        } else {
+        // Setup the HTTP method to use.
+        this.methodString = configuration.getChild("method").getValue("GET");
+        if ( !this.methodString.equalsIgnoreCase("GET") && !this.methodString.equalsIgnoreCase("POST")
) {
             throw new ConfigurationException("Invalid method \"" + method + "\" specified"
                     + " at " + configuration.getChild("method").getLocation());
+            
         }
-
-        /* Create the base URL */
+        // Create the base URL.
         String url = configuration.getChild("url").getValue(null);
         try {
-            if (url != null) this.url = new HttpURL(url);
+            if (url != null) {
+                this.url = new HttpURL(url);
+            }
         } catch (URIException e) {
             throw new ConfigurationException("Cannot process URL \"" + url + "\" specified"
                     + " at " + configuration.getChild("url").getLocation());
         }
 
-        /* Prepare the base request and query parameters */
+        // Prepare the base request and query parameters.
         this.reqParams = this.getParams(configuration.getChildren("param"));
         this.qryParams = this.getParams(configuration.getChildren("query"));
     }
@@ -130,25 +129,30 @@
     public void setup(SourceResolver sourceResolver, Map objectModel,
             String source, Parameters parameters)
     throws ProcessingException, SAXException, IOException {
-        /* Do the usual stuff */
+        // Do the usual stuff
         super.setup(sourceResolver, objectModel, source, parameters);
 
-        /*
-         * Parameter handling: In case the method is a POST method, query
-         * parameters and request parameters will be two different arrays
-         * (one for the body, one for the query string, otherwise it's going
-         * to be the same one, as all parameters are passed on the query string
-         */
+        if ("GET".equalsIgnoreCase(this.methodString)) {
+            this.method = new GetMethod();
+        } else if ("POST".equalsIgnoreCase(this.methodString)) {
+            this.method = new PostMethod();
+        }
+        //
+        // Parameter handling: In case the method is a POST method, query
+        // parameters and request parameters will be two different arrays
+        // (one for the body, one for the query string, otherwise it's going
+        // to be the same one, as all parameters are passed on the query string
+        //
         ArrayList req = new ArrayList();
         ArrayList qry = req;
         if (this.method instanceof PostMethod) qry = new ArrayList();
         req.addAll(this.reqParams);
         qry.addAll(this.qryParams);
 
-        /*
-         * Parameter handling: complete or override the configured parameters with
-         * those specified in the pipeline.
-         */
+        //
+        // Parameter handling: complete or override the configured parameters with
+        // those specified in the pipeline.
+        //
         String names[] = parameters.getNames();
         for (int x = 0; x < names.length; x++) {
             String name = names[x];
@@ -170,7 +174,7 @@
             }
         }
 
-        /* Process the current source URL in relation to the configured one */
+        // Process the current source URL in relation to the configured one
         HttpURL src = (super.source == null ? null : new HttpURL(super.source));
         if (this.url != null) src = (src == null ? this.url : new HttpURL(this.url, src));
         if (src == null) throw new ProcessingException("No URL specified");
@@ -178,14 +182,13 @@
             throw new ProcessingException("Invalid URL \"" + src.toString() + "\"");
         }
 
-        /* Configure the method with the resolved URL */
-        HostConfiguration hc = new HostConfiguration();
-        hc.setHost(src);
-        this.method.setHostConfiguration(hc);
+        // Configure the method with the resolved URL
+        this.hostConfiguration = new HostConfiguration();
+        this.hostConfiguration.setHost(src);
         this.method.setPath(src.getPath());
         this.method.setQueryString(src.getQuery());
 
-        /* And now process the query string (from the parameters above) */
+        // And now process the query string (from the parameters above)
         if (qry.size() > 0) {
             String qs = this.method.getQueryString();
             NameValuePair nvpa[] = new NameValuePair[qry.size()];
@@ -195,14 +198,14 @@
             }
         }
 
-        /* Finally process the body parameters */
+        // Finally process the body parameters
         if ((this.method instanceof PostMethod) && (req.size() > 0)) {
             PostMethod post = (PostMethod) this.method;
             NameValuePair nvpa[] = new NameValuePair[req.size()];
             post.setRequestBody((NameValuePair []) req.toArray(nvpa));
         }
 
-        /* Check the debugging flag */
+        // Check the debugging flag
         this.debug = parameters.getParameterAsBoolean("debug", false);
     }
 
@@ -215,14 +218,13 @@
      * @see #generate()
      */
     public void recycle() {
-        /* Recycle the method */
-        this.method.recycle();
-        /* TODO: Is this still needed? Does it refer to a bug in bugzilla?
-         *       At least the handling in httpclient has completely changed.
-         *  Work around a bug from the HttpClient library */
-        if (this.method instanceof PostMethod) ((PostMethod) this.method).setRequestBody("");
+        this.hostConfiguration = null;
+        if ( this.method != null ) {
+            this.method.releaseConnection();
+            this.method = null;
+        }
 
-        /* Clean up our parent */
+        // Clean up our parent.
         super.recycle();
     }
 
@@ -236,14 +238,14 @@
      */
     public void generate()
     throws ResourceNotFoundException, ProcessingException, SAXException, IOException {
-        /* Do the boring stuff in case we have to do a debug output (blablabla) */
+        // Do the boring stuff in case we have to do a debug output
         if (this.debug) {
             this.generateDebugOutput();
             return;
         }
 
-        /* Call up the remote HTTP server */
-        HttpConnection connection = new HttpConnection(this.method.getHostConfiguration());
+        // Call up the remote HTTP server
+        HttpConnection connection = new HttpConnection(this.hostConfiguration);
         HttpState state = new HttpState();
         this.method.setFollowRedirects(true);
         int status = this.method.execute(state, connection);
@@ -256,7 +258,7 @@
         }
         InputStream response = this.method.getResponseBodyAsStream();
 
-        /* Let's try to set up our InputSource from the response output stream and to parse
it */
+        // Let's try to set up our InputSource from the response output stream and to parse
it
         SAXParser parser = null;
         try {
             InputSource inputSource = new InputSource(response);
@@ -285,28 +287,15 @@
         attributes.addAttribute("", "method", "method", "CDATA", this.method.getName());
         attributes.addAttribute("", "url", "url", "CDATA", this.method.getURI().toString());
         attributes.addAttribute("", "protocol", "protocol", "CDATA",
-                (this.method.isHttp11() ? "HTTP/1.1" : "HTTP/1.0"));
+                (method.getParams().getVersion().compareTo(HttpVersion.HTTP_1_1) == 0 ? "HTTP/1.1"
: "HTTP/1.0"));
         super.xmlConsumer.startElement("", "request", "request", attributes);
 
         if (this.method instanceof PostMethod) {
-            String body = ((PostMethod) this.method).getRequestBodyAsString();
-
             attributes.clear();
             attributes.addAttribute("", "name", "name", "CDATA", "Content-Type");
             attributes.addAttribute("", "value", "value", "CDATA", "application/x-www-form-urlencoded");
             super.xmlConsumer.startElement("", "header", "header", attributes);
             super.xmlConsumer.endElement("", "header", "header");
-
-            attributes.clear();
-            attributes.addAttribute("", "name", "name", "CDATA", "Content-Length");
-            attributes.addAttribute("", "value", "value", "CDATA", Integer.toString(body.length()));
-            super.xmlConsumer.startElement("", "header", "header", attributes);
-            super.xmlConsumer.endElement("", "header", "header");
-
-            attributes.clear();
-            super.xmlConsumer.startElement("", "body", "body", attributes);
-            super.xmlConsumer.characters(body.toCharArray(), 0, body.length());
-            super.xmlConsumer.endElement("", "body", "body");
         }
 
         super.xmlConsumer.endElement("", "request", "request");

Modified: cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/src/main/java/org/apache/cocoon/generation/WebServiceProxyGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/src/main/java/org/apache/cocoon/generation/WebServiceProxyGenerator.java?view=diff&rev=506384&r1=506383&r2=506384
==============================================================================
--- cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/src/main/java/org/apache/cocoon/generation/WebServiceProxyGenerator.java
(original)
+++ cocoon/trunk/blocks/cocoon-proxy/cocoon-proxy-impl/src/main/java/org/apache/cocoon/generation/WebServiceProxyGenerator.java
Mon Feb 12 01:17:42 2007
@@ -28,7 +28,6 @@
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.URI;
 import org.apache.commons.httpclient.URIException;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.PostMethod;
@@ -42,6 +41,8 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Map;
@@ -225,7 +226,11 @@
              * connection regardless of whether the server returned an error or not.
              * {@link http://jakarta.apache.org/commons/httpclient/tutorial.html}
              */
-            response = method.getResponseBody();
+            try {
+                response = method.getResponseBody();
+            } catch (IOException e) {
+                // ignore
+            }
             method.releaseConnection();
         }
 
@@ -236,7 +241,7 @@
      * Create one per client session. 
      */
     protected HttpClient getHttpClient() throws ProcessingException {
-        URI uri = null;
+        URL uri = null;
         String host = null;
         Request request = ObjectModelHelper.getRequest(objectModel);
         Session session = request.getSession(true);
@@ -258,10 +263,10 @@
              * here need to be resolved before being set in the HostConfiguration?
              */
             try {
-                uri = new URI(this.source);
+                uri = new URL(this.source);
                 host = uri.getHost();
-                config.setHost(uri);
-            } catch (URIException ex) {
+                config.setHost(uri.getHost());
+            } catch (MalformedURLException ex) {
                 throw new ProcessingException("URI format error: " + ex, ex);
             }
 



Mime
View raw message