ivelin 2002/12/16 20:09:36 Modified: src/java/org/apache/cocoon/generation WebServiceProxyGenerator.java Log: applied patch by [EMAIL PROTECTED] (Tony Collen) http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14916 Revision Changes Path 1.5 +40 -11 xml-cocoon2/src/java/org/apache/cocoon/generation/WebServiceProxyGenerator.java Index: WebServiceProxyGenerator.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/generation/WebServiceProxyGenerator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WebServiceProxyGenerator.java 5 Dec 2002 10:32:57 -0000 1.4 +++ WebServiceProxyGenerator.java 17 Dec 2002 04:09:36 -0000 1.5 @@ -50,6 +50,12 @@ */ package org.apache.cocoon.generation; +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Map; + import org.apache.avalon.excalibur.xml.Parser; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.parameters.Parameters; @@ -60,19 +66,15 @@ import org.apache.cocoon.environment.Session; import org.apache.cocoon.environment.SourceResolver; import org.apache.commons.httpclient.HttpMultiClient; +import org.apache.commons.httpclient.HttpUrlMethod; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.UrlGetMethod; +import org.apache.commons.httpclient.methods.UrlPostMethod; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceException; import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import java.io.IOException; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Map; - /** * * The WebServiceProxyGenerator is intended to: @@ -97,6 +99,8 @@ * * * @author <a href="mailto:[EMAIL PROTECTED]">Ivelin Ivanov</a>, June 30, 2002 + * @author <a href="mailto:[EMAIL PROTECTED]">Tony Collen</a>, December 2, 2002 + * */ public class WebServiceProxyGenerator extends ComposerGenerator { @@ -118,6 +122,8 @@ throw SourceUtil.handle("Unable to resolve " + super.source, se); } + configuredHttpMethod = par.getParameter("wsproxy-method", METHOD_GET); + httpClient = getHttpClient(); } @@ -189,10 +195,21 @@ { try { + - UrlGetMethod method = new UrlGetMethod( this.source ); - - method.setUseDisk(false); + // @todo: Write a log entry detailing which httpMethod was configured + + HttpUrlMethod method = null; + + // check which method (GET or POST) to use. + if ( this.configuredHttpMethod.equalsIgnoreCase( METHOD_POST ) ) + { + method = new UrlPostMethod( this.source ); + ((UrlPostMethod)method).setUseDisk(false); + } else { + method = new UrlGetMethod( this.source ); + ((UrlGetMethod)method).setUseDisk(false); + } // this should probably be exposed as a sitemap option method.setFollowRedirects( true ); @@ -233,8 +250,12 @@ int htcode = httpClient.executeMethod( method ); - // @todo: Maybe we should implement some // meaningful reaction to htcodes different than 200 + // @todo: We should probably be logging this, as well. + if (htcode >= 400) { + throw new ProcessingException( "The remote returned error " + htcode + " when attempting to access remote URL:" + method.getUrl() ); + } + // @todo: fix-me // This sleep() is a temporary workaround @@ -246,7 +267,7 @@ int startOfXML = ret.indexOf("<?xml"); if (startOfXML == -1) { // No xml?! - throw new ProcessingException("Invalid (non XML) response returned from: " + method.getUrl() ); + throw new ProcessingException("Invalid (non XML) response returned from remote URL: " + method.getUrl() ); } ret.substring(startOfXML); @@ -296,5 +317,13 @@ // private attributes section private static String HTTP_CLIENT = "HTTP_CLIENT"; private HttpMultiClient httpClient; + +// for GET/POST configurability +private static String METHOD_GET = "GET"; +private static String METHOD_POST = "POST"; + +// default to GET +private String configuredHttpMethod = METHOD_GET; + } // class
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]