You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by di...@apache.org on 2001/07/13 16:15:53 UTC
cvs commit: xml-cocoon2/src/org/apache/cocoon/components/source URLSource.java
dims 01/07/13 07:15:52
Modified: src/org/apache/cocoon/components/source Tag:
cocoon_20_branch URLSource.java
Log:
Use Reflection to call getUserInfo - still keep compatability with JDK1.2.2
Carsten,
Can you check if this works for you.
Thanks,
dims
Revision Changes Path
No revision
No revision
1.1.2.5 +21 -7 xml-cocoon2/src/org/apache/cocoon/components/source/URLSource.java
Index: URLSource.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/URLSource.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- URLSource.java 2001/07/13 11:26:46 1.1.2.4
+++ URLSource.java 2001/07/13 14:15:44 1.1.2.5
@@ -15,6 +15,7 @@
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Reader;
+import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;
import org.apache.avalon.framework.component.ComponentException;
@@ -31,7 +32,7 @@
* Description of a source which is described by an URL.
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.1.2.4 $ $Date: 2001/07/13 11:26:46 $
+ * @version CVS $Revision: 1.1.2.5 $ $Date: 2001/07/13 14:15:44 $
*/
public final class URLSource
@@ -90,12 +91,11 @@
try {
if (this.connection == null) {
this.connection = this.url.openConnection();
- /* The following requires a jdk 1.3
- String userInfo = this.url.getUserInfo();
+ /* The following requires a jdk 1.3 */
+ String userInfo = this.url.getUserInfo();
if (this.url.getProtocol().startsWith("http") == true && userInfo != null) {
this.connection.setRequestProperty("Authorization","Basic "+this.encodeBASE64(userInfo));
}
- */
}
this.lastModificationDate = this.connection.getLastModified();
this.contentLength = this.connection.getContentLength();
@@ -136,15 +136,29 @@
} else {
if (this.connection == null) {
this.connection = this.url.openConnection();
- /* The following requires a jdk 1.3
- String userInfo = this.url.getUserInfo();
+ /* The following requires a jdk 1.3 */
+ String userInfo = getUserInfo(url);
if (this.url.getProtocol().startsWith("http") == true && userInfo != null) {
this.connection.setRequestProperty("Authorization","Basic "+encodeBASE64(userInfo));
}
- */
}
return this.connection.getInputStream();
}
+ }
+
+ private String getUserInfo(URL url)
+ {
+ try {
+ //System.out.println(">>>> getUserInfo: " + url);
+ Class paramTypes[] = new Class[0];
+ Object params[] = new Object[0];
+ Method method = URL.class.getMethod("getUserInfo",paramTypes);
+ return (String) method.invoke(url,params);
+ } catch (Exception e){
+ //System.out.println("Exception in getUserInfo (likely to happen on JDK-1.2.2 and below):" + e);
+ //e.printStackTrace();
+ }
+ return null;
}
/**
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org
AW: cvs commit: xml-cocoon2/src/org/apache/cocoon/components/source URLSource.java
Posted by Carsten Ziegeler <cz...@sundn.de>.
Hi Dims,
yes, this works great!
I just updated the logic so that the result of the reflection
test is cached.
Carsten
> -----Ursprüngliche Nachricht-----
> Von: dims@apache.org [mailto:dims@apache.org]
> Gesendet: Freitag, 13. Juli 2001 16:16
> An: xml-cocoon2-cvs@apache.org
> Betreff: cvs commit: xml-cocoon2/src/org/apache/cocoon/components/source
> URLSource.java
>
>
> dims 01/07/13 07:15:52
>
> Modified: src/org/apache/cocoon/components/source Tag:
> cocoon_20_branch URLSource.java
> Log:
> Use Reflection to call getUserInfo - still keep compatability
> with JDK1.2.2
>
> Carsten,
> Can you check if this works for you.
>
> Thanks,
> dims
>
> Revision Changes Path
> No revision
>
>
> No revision
>
>
> 1.1.2.5 +21 -7
> xml-cocoon2/src/org/apache/cocoon/components/source/URLSource.java
>
> Index: URLSource.java
> ===================================================================
> RCS file:
> /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/URLS
> ource.java,v
> retrieving revision 1.1.2.4
> retrieving revision 1.1.2.5
> diff -u -r1.1.2.4 -r1.1.2.5
> --- URLSource.java 2001/07/13 11:26:46 1.1.2.4
> +++ URLSource.java 2001/07/13 14:15:44 1.1.2.5
> @@ -15,6 +15,7 @@
> import java.io.InputStreamReader;
> import java.io.IOException;
> import java.io.Reader;
> +import java.lang.reflect.Method;
> import java.net.URL;
> import java.net.URLConnection;
> import org.apache.avalon.framework.component.ComponentException;
> @@ -31,7 +32,7 @@
> * Description of a source which is described by an URL.
> *
> * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
> - * @version CVS $Revision: 1.1.2.4 $ $Date: 2001/07/13 11:26:46 $
> + * @version CVS $Revision: 1.1.2.5 $ $Date: 2001/07/13 14:15:44 $
> */
>
> public final class URLSource
> @@ -90,12 +91,11 @@
> try {
> if (this.connection == null) {
> this.connection = this.url.openConnection();
> - /* The following requires a jdk 1.3
> - String userInfo = this.url.getUserInfo();
> + /* The following requires a
> jdk 1.3 */
> + String userInfo = this.url.getUserInfo();
> if
> (this.url.getProtocol().startsWith("http") == true && userInfo != null) {
>
> this.connection.setRequestProperty("Authorization","Basic
> "+this.encodeBASE64(userInfo));
> }
> - */
> }
> this.lastModificationDate =
> this.connection.getLastModified();
> this.contentLength =
> this.connection.getContentLength();
> @@ -136,15 +136,29 @@
> } else {
> if (this.connection == null) {
> this.connection = this.url.openConnection();
> - /* The following requires a jdk 1.3
> - String userInfo = this.url.getUserInfo();
> + /* The following requires a jdk 1.3 */
> + String userInfo = getUserInfo(url);
> if (this.url.getProtocol().startsWith("http")
> == true && userInfo != null) {
>
> this.connection.setRequestProperty("Authorization","Basic
> "+encodeBASE64(userInfo));
> }
> - */
> }
> return this.connection.getInputStream();
> }
> + }
> +
> + private String getUserInfo(URL url)
> + {
> + try {
> + //System.out.println(">>>> getUserInfo: " + url);
> + Class paramTypes[] = new Class[0];
> + Object params[] = new Object[0];
> + Method method =
> URL.class.getMethod("getUserInfo",paramTypes);
> + return (String) method.invoke(url,params);
> + } catch (Exception e){
> + //System.out.println("Exception in getUserInfo
> (likely to happen on JDK-1.2.2 and below):" + e);
> + //e.printStackTrace();
> + }
> + return null;
> }
>
> /**
>
>
>
>
> ----------------------------------------------------------------------
> In case of troubles, e-mail: webmaster@xml.apache.org
> To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-cvs-help@xml.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org