Created
April 17, 2016 19:01
-
-
Save jnh5y/1739baa42466d66e383fa26ffd7235ca to your computer and use it in GitHub Desktop.
Bean to register Hadoop URL StreamHandlerFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.URL | |
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory | |
import org.apache.naming.resources.DirContextURLStreamHandlerFactory | |
class HadoopURLFactoryRegister { | |
println("Trying to register the Hadoop URL handlers.") | |
val factory = new FsUrlStreamHandlerFactory | |
try { | |
println("Trying to call the general URL method") | |
URL.setURLStreamHandlerFactory(factory) | |
} catch { | |
case e: Error => println("Caught an exception; falling back to Tomcat specific approach", e) | |
try { | |
println("Trying the Tomcat/Catalina specific method.") | |
DirContextURLStreamHandlerFactory.addUserFactory(factory) | |
} catch { | |
case e: Exception => println("Caught an exception: ", e) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment