Re: Custom URL handlers in Tomcat web app
Hi I've resolved this issue in this way: URLStreamHandlerFactoryImpl.termspecProtocolHandler = handlerClass; try { for (final Field field : URL.class.getDeclaredFields()) { if (factory.equalsIgnoreCase(field.getName()) ) { field.setAccessible(true); field.set(null, new URLStreamHandlerFactoryImpl((URLStreamHandlerFactory) field.get(null))); } } } catch (Throwable e) { logger.error(e); } -- View this message in context: http://old.nabble.com/Custom-URL-handlers-in-Tomcat-web-app-tp15629476p26636133.html Sent from the Tomcat - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Custom URL handlers in Tomcat web app
Hi Matt, Since I was working with legacy code, I don;t wanted to any code. I found that org.apache.catalina.loader.WebappLoader was setting the URL.setURLStreamHandlerFactory() with DirContextURLStreamHandlerFactory, basically jndi stream handler. I updated this file rebuild the class placed it in %TOMCAT_HOME%/server/classes directory so as to force classloader to load my class. Now my custom URLStreamHandler is getting picked up properly. Since WebAppLoader is using it for dealing with jndi://, I don't see any issues with that my app seems to work fine. Thanks, Praveen M. MK-24 wrote: Hi Praveen, pmanvi praveena.manvi at gmail.com writes: ... Do let me know if you find some solution to the same. actually, in the end I got it working using Christoph's suggestion to use the URL(scheme, host, port, path, handler) constructor. Unless that legacy system you're using unwraps and reconstructs your URL objects somewhere down the implementation (i.e., using the ctor that only takes a URL spec), this should work just fine. Of course it's still merely a workaround, because you have to manually detect custom schemes and construct an appropriate handler for those. You could obviously move this code to a factory, but you will effectively only be duplicating what URLStreamHandlerFactory already does/is supposed to do... this sort of shows how absurd this issue actually is... I'm kinda disappointed that it receives so few attention on the Java issue tracker. Anyway, HTH! Best, Matt - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Custom-URL-handlers-in-Tomcat-web-app-tp15629476p16118205.html Sent from the Tomcat - User mailing list archive at Nabble.com. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Praveen, pmanvi wrote: | I found that org.apache.catalina.loader.WebappLoader was setting the | URL.setURLStreamHandlerFactory() with DirContextURLStreamHandlerFactory, | basically jndi stream handler. | I updated this file rebuild the class placed it in | %TOMCAT_HOME%/server/classes directory so as to force classloader to load my | class. | | Now my custom URLStreamHandler is getting picked up properly. This is a great solution. For the benefit of those still reading this thread, could you post the changes you made to this class? It would be helpful for those searching the archives for solutions in the future. Thanks, - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkffy5EACgkQ9CaO5/Lv0PB+qgCfY+RV/FHipoKcKbIQNBp+hUvP E/sAn1/B02/xDHBSeVCQbdvjHaStgHM/ =9V55 -END PGP SIGNATURE- - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
Christopher Schultz chris at christopherschultz.net writes: Praveen, pmanvi wrote: | I found that org.apache.catalina.loader.WebappLoader was setting the | URL.setURLStreamHandlerFactory() with DirContextURLStreamHandlerFactory, | basically jndi stream handler. | I updated this file rebuild the class placed it in | %TOMCAT_HOME%/server/classes directory so as to force classloader to load my | class. | | Now my custom URLStreamHandler is getting picked up properly. This is a great solution. For the benefit of those still reading this thread, could you post the changes you made to this class? It would be helpful for those searching the archives for solutions in the future. Thanks, -chris +1 Plus, one could place a link to it from the ticket on the Java issue tracker, so that people coming from there have a solution at hand. I simply don't see this getting fixed anytime soon. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
Hi Matt, I am trying to port legacy JRun application to Tomcat facing same problem. I also tried out the listed options but without any luck. Do let me know if you are able to crack. Since I have legacy application, I do not want to introduce any new code to make it work. Thanks, Praveen M. MK-24 wrote: Hi everybody, I have the following problem: My Web application needs to handle Lotus Notes URLs which use the scheme notes. However, since Java does not know this protocol by default, it throws a MalformedUrlException when I construct a java.net.URL from a notes:// URL-string. So, I read up on custom URL handlers and as far as I understand, you have to code a custom URLStreamHandler class and a custom URLConnection class. Okay, no big deal. However, there are three ways to register your new handler: 1) put it in the sun.net.www.protocol.yourprotocol package 2) put it in a custom package and declare that package to the JRE using the java.protocol.handler.pkgs system property 3) register a custom URLStreamHandlerFactory using URL.setUrlStreamHandlerFactory problem is, none of these approaches work in Tomcat 5.5. For 1), this simply didn't have any effect for me. 2) neither, maybe Tomcat simply ignores that property? 3) doesn't work because Tomcat already registers its own factory, and for some reason I can't quite put my hands on you are not allowed to call that method twice per JVM instance. This issue is also discussed on Sun's Java issue tracker: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4648098 The ticket has been opened six years ago and still no fix! Does Tomcat meanwhile have some workaround for this? I mean, I don't even need an actual URL connection, I just want to pass custom URL strings, which should be perfectly fine if they are valid URLs, no?! I hope you can help! Best, Matt - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] :-(( -- View this message in context: http://www.nabble.com/Custom-URL-handlers-in-Tomcat-web-app-tp15629476p16045321.html Sent from the Tomcat - User mailing list archive at Nabble.com. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
Hi Matt, Today I was trying to port one legacy application from JRun to Tomcat facing same problem with URL. URL.setURLStreamHandlerFactory.java.lang.Error: factory already defined 1. I tried out setting -Djava.protocol.handler.pkgs=my.package pointing to where my CustomURLStreamHander is present in catalina.sh 2. Added the required jar common/lib other mentioned places As you have said both didn't help as java.protocol.handler.pkgs setting is not working. http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/naming/resources/jndi/Handler.html I also did not find anything about this is Tomcat configuration files. Do let me know if you find some solution to the same. Thanks, Praveen M. MK-24 wrote: Hi everybody, I have the following problem: My Web application needs to handle Lotus Notes URLs which use the scheme notes. However, since Java does not know this protocol by default, it throws a MalformedUrlException when I construct a java.net.URL from a notes:// URL-string. So, I read up on custom URL handlers and as far as I understand, you have to code a custom URLStreamHandler class and a custom URLConnection class. Okay, no big deal. However, there are three ways to register your new handler: 1) put it in the sun.net.www.protocol.yourprotocol package 2) put it in a custom package and declare that package to the JRE using the java.protocol.handler.pkgs system property 3) register a custom URLStreamHandlerFactory using URL.setUrlStreamHandlerFactory problem is, none of these approaches work in Tomcat 5.5. For 1), this simply didn't have any effect for me. 2) neither, maybe Tomcat simply ignores that property? 3) doesn't work because Tomcat already registers its own factory, and for some reason I can't quite put my hands on you are not allowed to call that method twice per JVM instance. This issue is also discussed on Sun's Java issue tracker: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4648098 The ticket has been opened six years ago and still no fix! Does Tomcat meanwhile have some workaround for this? I mean, I don't even need an actual URL connection, I just want to pass custom URL strings, which should be perfectly fine if they are valid URLs, no?! I hope you can help! Best, Matt - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/Custom-URL-handlers-in-Tomcat-web-app-tp15629476p16027888.html Sent from the Tomcat - User mailing list archive at Nabble.com. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Matthias, MK wrote: | Christopher Schultz chris at christopherschultz.net writes: | | As I'm reading more in the API, I can see that the URL class has a | constructor that takes a URLStreamHandler. Could you utilize this | constructor instead? | | that's a good idea actually (although it would require me to parse the incoming | URL strings on my own; a job which is otherwise done by the URL ctor itself, but | oh well). There is a URL constructor that accepts a URL and a spec (which is, in fact, the URL you want to parse). I didn't try it myself, yet, but it appears you could give the constructor an unrelated URL and it will ignore it. Something like this: static URL bogus = new URL(http://www.google.com/;); static URLStreamHandler nullHandler = new URLStreamHandler() { ~public URLConnection openConnection() ~{ ~return null; ~} }; URL myURL = new URL(bogus, notes://whatever, nullHandler); | However, unfortunately this still does not help, because it merely | moves the problem further down the implementation of that (somewhat obscure) API | I am using. The problem is that with this constructor, creating a URL object on | my side succeeds, but passing it to that API will still result in a MalformedUrl | somewhere down their implementation, maybe because they pack/unpack the wrapped | URL string to create other URL objects from it, dunno. Dang! I though I almost | had it :-) Fantastic. Hmm... I think you might have to start messing around with the Tomcat source... maybe look at how their URLStreamHandler works (the one Filip mentioned registers the jndi:// protocol. Perhaps there's a way to hook into that StreamHandler without too much trouble. Otherwise, you may have to hack the class to register your protocol as well (at least you don't have to /handle/ the protocol, too. | I will try rolling a jar from my protocol handler and put it in the places you | suggested. Maybe that'll work, I'll report back. That's your best bet so far, I think. I have one last trick up my sleeve if that doesn't work. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkfEJCIACgkQ9CaO5/Lv0PCewACgkbZ2CAEcod9c9u0Q3YqeOY5h gK4AmQGjgbkFGhSm6DCl2YsCbdvDMkEG =B1jD -END PGP SIGNATURE- - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Matthias, MK wrote: | actually I just realized that this is not gonna help if Tomcat does not honor | the java.protocol.handler.pkgs setting, because even if Tomcat can load the JAR | and knows where to look for it, it would still need to read this setting to load | the Handler class upon URL construction (because this happens through Tomcat's | URLStreamHandlerFactory), no? That depends on whether or not TC really ignores that system property. I would be willing to bet that it /is/ respecting that property, but that your handler wasn't in the system class path, so it was ignored. | Anywho, I just tried common/lib, common/endorsed and a custom location I added | manually to the classpath (which would make it available to the system | classloader right?). No. Setting the CLASSPATH on the command-line doesn't do anything for Tomcat. The first things that happens to the CLASSPATH in the startup scripts is to blank-out anything that's already there. | Didn't work. As a last-ditch effort, try putting your JAR file into the JVM's endorsed directory and see if that works. | Any ideas left that do not include the words Tomcat sources and modify? :D Yeah... always a scary proposition. | I still can't quite believe how a trivial operation such as constructing a | java.net.URL from a wellformed (!) URL can cause so much trouble in a Servlet | based environment. I must be missing something. I never knew it was this bad. I completely agree that creating a well-formed URL with an unknown protocol should be allowed. Oh, well. Okay, for my final trick, I have one last idea for you. If nothing else works, try this: Change all notes:// URLs into http:// URLs and pass them around, etc. When you're ready to display them on the screen, change the leading http://; to notes://. Okay, now I really /am/ all out of ideas. Good luck! - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkfEJTwACgkQ9CaO5/Lv0PD9JQCbBsKnpPY5o86fAqyMuM+qnslh BxsAn26aH7SeimNQLJ6uZvAIWG3pQH0f =ZQ4L -END PGP SIGNATURE- - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Matthias, MK wrote: | Christopher Schultz chris at christopherschultz.net writes: | | How did you set the [Java] property? | | I am running my web app inside an Eclipse WTP server container project. So I set | the property as a JVM argument in the Server project's Run dialog. I set it | like this: | | -Djava.protocol.handler.pkgs=my.protocol | | ...given that the Handler class is in package my.protocol.notes. | | am I missing something here? That should be alright. You can always verify by checking the value itself during runtime (say, during the startup of your webapp). I would recommend doing this just to make sure. | Actually I don't even call URL.openConnection, because I don't need it at all. | It's really just that the java.net.URL constructor requires that there exists an | object which implements this behavior just in case someone should try to open a | connection. Ah, I see. | My situation really is just that there is an API some methods of which take URL | objects instead of plain URL strings in order to link to documents from a web | page (intranet pages). Since notes:// links will open in the Lotus Notes client, | which everyone uses in this company, it should be fine to pass notes:// links if | they are wellformed. There are no calls to openConnection. Well, that's good -- at least you don't have to implement your own protocol or anything like that. | Throwing a MalformedUrl in the constructor if no connection handler is found for | the given protocol is simply a bad design decision IMHO (besides, what does | connection handling have to do with well-formed URLs). These things should really | be postponed to the time where someone actually tries to open a connection from | that URL. I completely agree with you. | But since I can neither change that API I use nor the JVM | implementation, I have to find another way to work around that problem :-) Where are you putting the implementation of the protocol handler? From the bug you mentioned in your original post, it looks like putting it into your webapp just isn't going to work. Instead, you'll have to install it into a ClassLoader that is higher-up in the chain. According to the bug comments, your implementation must be in the system classpath (that is, not loaded through any of the ClassLoaders that Tomcat creates). Which version of TC are you running? In TC 6, you should be able to use tomcat/lib. For TC 5.5, try tomcat/common/lib and then tomcat/common/endorsed. As a last resort, you could put your JAR file into the JRE's endorsed directory. Make sure you only have this library living in one place at a time, or other weird things might start happening. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkfC0NAACgkQ9CaO5/Lv0PD6QwCgpdOO7S49z6e/Ab4Bn10zJ2Bh HhEAmwb98Eyku/JXyhb0OTZkVOWWh8UB =Uygl -END PGP SIGNATURE- - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Matthias, Christopher Schultz wrote: | From the bug you mentioned in your original post, it looks like | putting it into your webapp just isn't going to work. Instead, you'll | have to install it into a ClassLoader that is higher-up in the chain. | According to the bug comments, your implementation must be in the | system classpath (that is, not loaded through any of the ClassLoaders | that Tomcat creates). Hmm... I just re-read this comment in the bug: | The given workaround will not work in a servlet container such as | tomcat which already sets the URLStreamHandlerFactory on | java.net.URL. This handler can only be registered once in the VM | (which is pretty silly btw.). If this is true, then you're going to have to hack the Tomcat source to get this to work. Maybe Tomcat's stream handler can be written to re-use the system protocol handler if it doesn't find a handler it likes for your URL. Also, this /was/ 2002-03, so perhaps things in Tomcat have changed since then. Try the system classpath (or endorsed directory) and we'll see what happens. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkfC058ACgkQ9CaO5/Lv0PD1dACeIwDCIIAcKeOyjNcbQZEk4W8S 3BsAn1H/BSlsevOAmZTP8Yq+StdjS9+U =jAcY -END PGP SIGNATURE- - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Matthias, MK wrote: | Actually I don't even call URL.openConnection, because I don't need it at all. | It's really just that the java.net.URL constructor requires that there exists an | object which implements this behavior just in case someone should try to open a | connection. As I'm reading more in the API, I can see that the URL class has a constructor that takes a URLStreamHandler. Could you utilize this constructor instead? - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkfC1N0ACgkQ9CaO5/Lv0PBs0QCeMZPNLumZzRLHn58GTv2aecA0 ulsAni4z1/0Z4EyFHlo3BxGzNWfK7cHu =c2QK -END PGP SIGNATURE- - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
Christopher, thanks a lot for your replies. Christopher Schultz chris at christopherschultz.net writes: MK wrote: | Actually I don't even call URL.openConnection, because I don't need it at all. | It's really just that the java.net.URL constructor requires that there exists an | object which implements this behavior just in case someone should try to open a | connection. As I'm reading more in the API, I can see that the URL class has a constructor that takes a URLStreamHandler. Could you utilize this constructor instead? that's a good idea actually (although it would require me to parse the incoming URL strings on my own; a job which is otherwise done by the URL ctor itself, but oh well). However, unfortunately this still does not help, because it merely moves the problem further down the implementation of that (somewhat obscure) API I am using. The problem is that with this constructor, creating a URL object on my side succeeds, but passing it to that API will still result in a MalformedUrl somewhere down their implementation, maybe because they pack/unpack the wrapped URL string to create other URL objects from it, dunno. Dang! I though I almost had it :-) as for the checking whether the JVM argument for my protocol package is properly set, I already had done that and I can assure you it is properly set. Tomcat really seems not to honor this value properly before registering its URLStreamHandlerFactory. I am using Tomcat 5.5 by the way. I will try rolling a jar from my protocol handler and put it in the places you suggested. Maybe that'll work, I'll report back. Regards, Matt - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
MK kaeppler.matthias at nts.ricoh.co.jp writes: [...] I am using Tomcat 5.5 by the way. I will try rolling a jar from my protocol handler and put it in the places you suggested. Maybe that'll work, I'll report back. actually I just realized that this is not gonna help if Tomcat does not honor the java.protocol.handler.pkgs setting, because even if Tomcat can load the JAR and knows where to look for it, it would still need to read this setting to load the Handler class upon URL construction (because this happens through Tomcat's URLStreamHandlerFactory), no? Anywho, I just tried common/lib, common/endorsed and a custom location I added manually to the classpath (which would make it available to the system classloader right?). Didn't work. Any ideas left that do not include the words Tomcat sources and modify? :D I still can't quite believe how a trivial operation such as constructing a java.net.URL from a wellformed (!) URL can cause so much trouble in a Servlet based environment. I must be missing something. Regards, Matt - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
Christopher Schultz chris at christopherschultz.net writes: [...] | problem is, none of these approaches work in Tomcat 5.5. For 1), this simply | didn't have any effect for me. 2) neither, maybe Tomcat simply ignores that | property? How did you set the property? I am running my web app inside an Eclipse WTP server container project. So I set the property as a JVM argument in the Server project's Run dialog. I set it like this: -Djava.protocol.handler.pkgs=my.protocol ...given that the Handler class is in package my.protocol.notes. am I missing something here? | Does Tomcat meanwhile have some workaround for this? I mean, I don't even need | an actual URL connection, I just want to pass custom URL strings, which should | be perfectly fine if they are valid URLs, no?! Do you have the opportunity to intercept these URL objects, or are they always handled somewhere that you can't inspect them. I'm wondering if you can convert a notes:// URL into, say, an http:// URL before attempting to call URL.openConnection. I don't know anything about notes://, so maybe it isn't even HTTP-compatible. I'm sure there's a way around this. Give us some more information and we'll see what we can do. Actually I don't even call URL.openConnection, because I don't need it at all. It's really just that the java.net.URL constructor requires that there exists an object which implements this behavior just in case someone should try to open a connection. My situation really is just that there is an API some methods of which take URL objects instead of plain URL strings in order to link to documents from a web page (intranet pages). Since notes:// links will open in the Lotus Notes client, which everyone uses in this company, it should be fine to pass notes:// links if they are wellformed. There are no calls to openConnection. Throwing a MalformedUrl in the constructor if no connection handler is found for the given protocol is simply a bad design decision IMHO (besides, what does connection handling have to do with wellformed URLs). These things should really be postponed to the time where someone actually tries to open a connection from that URL. But since I can neither change that API I use nor the JVM implementation, I have to find another way to work around that problem :-) Best, Matthias - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 MK, MK wrote: | I have the following problem: | My Web application needs to handle Lotus Notes URLs which use the scheme | notes. However, since Java does not know this protocol by default, it throws a | MalformedUrlException when I construct a java.net.URL from a notes:// URL-string. | | So, I read up on custom URL handlers and as far as I understand, you have to | code a custom URLStreamHandler class and a custom URLConnection class. You really only need a custom URLStreamHandler... if there's a URLConnection that you can re-use, you are welcome to do that. | Okay, no | big deal. However, there are three ways to register your new handler: | | 1) put it in the sun.net.www.protocol.yourprotocol package Don't do that. You probably can't do it anyway, since the JAR defining the package is likely to be sealed. | 2) put it in a custom package and declare that package to the JRE using the | java.protocol.handler.pkgs system property This is how I do it in my TestURLConnection package (http://sourceforge.net/projects/tuc). | 3) register a custom URLStreamHandlerFactory using URL.setUrlStreamHandlerFactory This might not work, since the javadoc says it may only be called once for a given JVM -- and Tomcat (or something else) might have don it before you get the chance to do so. | problem is, none of these approaches work in Tomcat 5.5. For 1), this simply | didn't have any effect for me. 2) neither, maybe Tomcat simply ignores that | property? How did you set the property? | 3) doesn't work because Tomcat already registers its own factory, and | for some reason I can't quite put my hands on you are not allowed to call that | method twice per JVM instance. Yeah, that's not surprising at all. | This issue is also discussed on Sun's Java issue tracker: | http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4648098 | | The ticket has been opened six years ago and still no fix! That is also not surprising. Bugs in Java seem to take forever to get fixed, if they ever get fixed. It's a shame, really. | Does Tomcat meanwhile have some workaround for this? I mean, I don't even need | an actual URL connection, I just want to pass custom URL strings, which should | be perfectly fine if they are valid URLs, no?! Do you have the opportunity to intercept these URL objects, or are they always handled somewhere that you can't inspect them. I'm wondering if you can convert a notes:// URL into, say, an http:// URL before attempting to call URL.openConnection. I don't know anything about notes://, so maybe it isn't even HTTP-compatible. I'm sure there's a way around this. Give us some more information and we'll see what we can do. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAke+9tYACgkQ9CaO5/Lv0PCu+QCfZR8fi+RMARH22QPpcZDjl4/o gUUAoL3sKYTDL6jznTmFu3QdOMZLX73N =Moqk -END PGP SIGNATURE- - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Custom URL handlers in Tomcat web app
Christopher Schultz [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 MK, MK wrote: | I have the following problem: | My Web application needs to handle Lotus Notes URLs which use the scheme | notes. However, since Java does not know this protocol by default, it throws a | MalformedUrlException when I construct a java.net.URL from a notes:// URL-string. | | So, I read up on custom URL handlers and as far as I understand, you have to | code a custom URLStreamHandler class and a custom URLConnection class. You really only need a custom URLStreamHandler... if there's a URLConnection that you can re-use, you are welcome to do that. | Okay, no | big deal. However, there are three ways to register your new handler: | | 1) put it in the sun.net.www.protocol.yourprotocol package Don't do that. You probably can't do it anyway, since the JAR defining the package is likely to be sealed. | 2) put it in a custom package and declare that package to the JRE using the | java.protocol.handler.pkgs system property This is how I do it in my TestURLConnection package (http://sourceforge.net/projects/tuc). | 3) register a custom URLStreamHandlerFactory using URL.setUrlStreamHandlerFactory This might not work, since the javadoc says it may only be called once for a given JVM -- and Tomcat (or something else) might have don it before you get the chance to do so. Yes, TC registers one early on in the init phase to handle jndi://. | problem is, none of these approaches work in Tomcat 5.5. For 1), this simply | didn't have any effect for me. 2) neither, maybe Tomcat simply ignores that | property? How did you set the property? | 3) doesn't work because Tomcat already registers its own factory, and | for some reason I can't quite put my hands on you are not allowed to call that | method twice per JVM instance. Yeah, that's not surprising at all. | This issue is also discussed on Sun's Java issue tracker: | http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4648098 | | The ticket has been opened six years ago and still no fix! That is also not surprising. Bugs in Java seem to take forever to get fixed, if they ever get fixed. It's a shame, really. | Does Tomcat meanwhile have some workaround for this? I mean, I don't even need | an actual URL connection, I just want to pass custom URL strings, which should | be perfectly fine if they are valid URLs, no?! Do you have the opportunity to intercept these URL objects, or are they always handled somewhere that you can't inspect them. I'm wondering if you can convert a notes:// URL into, say, an http:// URL before attempting to call URL.openConnection. I don't know anything about notes://, so maybe it isn't even HTTP-compatible. I'm sure there's a way around this. Give us some more information and we'll see what we can do. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAke+9tYACgkQ9CaO5/Lv0PCu+QCfZR8fi+RMARH22QPpcZDjl4/o gUUAoL3sKYTDL6jznTmFu3QdOMZLX73N =Moqk -END PGP SIGNATURE- - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]