You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2005/04/26 18:45:18 UTC
svn commit: r164823 - in
/cocoon/blocks/unsupported/proxy/trunk/java/org/apache/cocoon/generation:
GenericProxyGenerator.java HttpProxyGenerator.java
Author: vgritsenko
Date: Tue Apr 26 09:45:18 2005
New Revision: 164823
URL: http://svn.apache.org/viewcvs?rev=164823&view=rev
Log:
Use EMPTY_PROPERTIES
Modified:
cocoon/blocks/unsupported/proxy/trunk/java/org/apache/cocoon/generation/GenericProxyGenerator.java
cocoon/blocks/unsupported/proxy/trunk/java/org/apache/cocoon/generation/HttpProxyGenerator.java
Modified: cocoon/blocks/unsupported/proxy/trunk/java/org/apache/cocoon/generation/GenericProxyGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/proxy/trunk/java/org/apache/cocoon/generation/GenericProxyGenerator.java?rev=164823&r1=164822&r2=164823&view=diff
==============================================================================
--- cocoon/blocks/unsupported/proxy/trunk/java/org/apache/cocoon/generation/GenericProxyGenerator.java (original)
+++ cocoon/blocks/unsupported/proxy/trunk/java/org/apache/cocoon/generation/GenericProxyGenerator.java Tue Apr 26 09:45:18 2005
@@ -1,12 +1,12 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,6 +26,7 @@
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.xml.XMLUtils;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.http.HttpEnvironment;
import org.apache.cocoon.util.RequestForwardingHttpMethod;
@@ -40,18 +41,18 @@
import org.xml.sax.helpers.AttributesImpl;
/**
- * This is a generic HTTP proxy, designed to handle any possible HTTP method,
+ * This is a generic HTTP proxy, designed to handle any possible HTTP method,
* but with a particular bias towards WebDAV. As of now it's pretty unstable, but
* still it might be a good proof of concept towards a pure HTTP(++) proxy.
- *
- * TODO: doesn't handle authentication properly
- * TODO: doesn't handle (and doubt it'll ever will) HTTP/1.1 keep-alive
- *
+ *
+ * <br>TODO: doesn't handle authentication properly
+ * <br>TODO: doesn't handle (and doubt it'll ever will) HTTP/1.1 keep-alive
+ *
* @author <a href="mailto:gianugo@apache.org">Gianugo Rabellino</a>
- * @version $Id: GenericProxyGenerator.java,v 1.5 2004/03/05 13:02:20 bdelacretaz Exp $
+ * @version $Id$
*/
public class GenericProxyGenerator extends ServiceableGenerator {
-
+
/** The real URL to forward requests to */
HttpURL destination;
/** The current request */
@@ -64,7 +65,7 @@
/**
* Compose and get a SAX parser for further use.
- *
+ *
* @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
public void service(ServiceManager manager) throws ServiceException {
@@ -82,14 +83,14 @@
}
super.dispose();
}
-
+
/**
- * Setup this component by getting the (required) "url" parameter and the
+ * Setup this component by getting the (required) "url" parameter and the
* (optional) "path" parameter. If path is not specified, the request URI will
* be used and forwarded.
- *
+ *
* TODO: handle query string
- *
+ *
* @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
*/
public void setup(
@@ -109,69 +110,68 @@
if (path == null)
path = request.getRequestURI();
destination = new HttpURL(url);
-
+
}
-
-
+
+
/**
* Get the request data, pass them on to the forwarder and return the result.
- *
+ *
* TODO: much better header handling
- * TODO: handle non XML and bodyless responses (probably needs a smarter Serializer,
+ * TODO: handle non XML and bodyless responses (probably needs a smarter Serializer,
* since some XML has to go through the pipeline anyway.
- *
+ *
* @see org.apache.cocoon.generation.Generator#generate()
*/
public void generate()
throws IOException, SAXException, ProcessingException {
- RequestForwardingHttpMethod method =
+ RequestForwardingHttpMethod method =
new RequestForwardingHttpMethod(request, destination);
-
- // Build the forwarded connection
- HttpConnection conn = new HttpConnection(destination.getHost(), destination.getPort());
+
+ // Build the forwarded connection
+ HttpConnection conn = new HttpConnection(destination.getHost(), destination.getPort());
HttpState state = new HttpState();
- state.setCredentials(null, destination.getHost(),
+ state.setCredentials(null, destination.getHost(),
new UsernamePasswordCredentials(destination.getUser(), destination.getPassword()));
method.setPath(path);
-
+
// Execute the method
method.execute(state, conn);
-
+
// Send the output to the client: set the status code...
response.setStatus(method.getStatusCode());
-
- // ... retrieve the headers from the origin server and pass them on
+
+ // ... retrieve the headers from the origin server and pass them on
Header[] methodHeaders = method.getResponseHeaders();
for (int i = 0; i < methodHeaders.length; i++) {
// there is more than one DAV header
if (methodHeaders[i].getName().equals("DAV")) {
response.addHeader(methodHeaders[i].getName(), methodHeaders[i].getValue());
} else if (methodHeaders[i].getName().equals("Content-Length")) {
- // drop the original Content-Length header. Don't ask me why but there
+ // drop the original Content-Length header. Don't ask me why but there
// it's always one byte off
} else {
response.setHeader(methodHeaders[i].getName(), methodHeaders[i].getValue());
- }
+ }
}
-
+
// no HTTP keepalives here...
response.setHeader("Connection", "close");
// Parse the XML, if any
- if (method.getResponseHeader("Content-Type").getValue().startsWith("text/xml")) {
- InputStream stream = method.getResponseBodyAsStream();
+ if (method.getResponseHeader("Content-Type").getValue().startsWith("text/xml")) {
+ InputStream stream = method.getResponseBodyAsStream();
parser.parse(new InputSource(stream), this.contentHandler, this.lexicalHandler);
} else {
// Just send a dummy XML
this.contentHandler.startDocument();
- this.contentHandler.startElement("", "no-xml-content", "no-xml-content", new AttributesImpl());
+ this.contentHandler.startElement("", "no-xml-content", "no-xml-content", XMLUtils.EMPTY_ATTRIBUTES);
this.contentHandler.endElement("", "no-xml-content", "no-xml-content");
this.contentHandler.endDocument();
}
-
+
// again, no keepalive here.
conn.close();
-
}
}
Modified: cocoon/blocks/unsupported/proxy/trunk/java/org/apache/cocoon/generation/HttpProxyGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/proxy/trunk/java/org/apache/cocoon/generation/HttpProxyGenerator.java?rev=164823&r1=164822&r2=164823&view=diff
==============================================================================
--- cocoon/blocks/unsupported/proxy/trunk/java/org/apache/cocoon/generation/HttpProxyGenerator.java (original)
+++ cocoon/blocks/unsupported/proxy/trunk/java/org/apache/cocoon/generation/HttpProxyGenerator.java Tue Apr 26 09:45:18 2005
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -51,11 +51,11 @@
* The <code>HttpProxyGenerator</code> is a Cocoon generator using the
* <b>Jakarta Commons HTTPClient Library</b> to access an XML stream
* over HTTP.
- *
+ *
* @author <a href="mailto:ivelin@apache.org">Ivelin Ivanov</a>, June 2002
* @author <a href="mailto:tony@apache.org">Tony Collen</a>, December 2002
* @author <a href="mailto:pier@apache.org">Pier Fumagalli</a>, February 2003
- * @version CVS $Id: HttpProxyGenerator.java,v 1.7 2004/03/05 13:02:20 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class HttpProxyGenerator extends ServiceableGenerator implements Configurable {
@@ -293,19 +293,19 @@
if (this.method instanceof PostMethod) {
String body = ((PostMethod) this.method).getRequestBodyAsString();
- attributes = new AttributesImpl();
+ 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 = new AttributesImpl();
+ 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 = new AttributesImpl();
+ attributes.clear();
super.xmlConsumer.startElement("", "body", "body", attributes);
super.xmlConsumer.characters(body.toCharArray(), 0, body.length());
super.xmlConsumer.endElement("", "body", "body");
@@ -348,7 +348,7 @@
if (value != null) list.add(new NameValuePair(name, value));
}
}
-
+
return (list);
}