解决jruby-ldap
跟Active Directory兼容问题的patch。
# config/initializers/jruby-ldap_patch.rb
require 'ldap'
module JrubyLdapPatches
module AddToHashToEntry
def to_hash
self
end
end
module AlwaysUseLdapCtxFactory
def self.included(base)
base.extend ClassMethods
base.class_eval do
class << self
alias_method_chain :configuration, :fixed_factory
end
end
end
module ClassMethods
def configuration_with_fixed_factory(attrs = {})
configuration_without_fixed_factory(attrs).update(javax.naming.Context::INITIAL_CONTEXT_FACTORY => 'com.sun.jndi.ldap.LdapCtxFactory')
end
end
end
module MoreInformationForWrappedErrors
def self.included(base)
base.extend ClassMethods
base.class_eval do
class << self
alias_method_chain :wrap, :more_information
end
end
end
module ClassMethods
def wrap_with_more_information(message, java_exception)
returning wrap_without_more_information(message, java_exception) do
show_cause(java_exception.cause) if $DEBUG || $VERBOSE_LDAP_ERRORS
end
end
def show_cause(exception)
unless exception.nil?
puts exception.to_s
show_cause(exception.cause)
end
end
end
end
end
LDAP::Entry.send :include, JrubyLdapPatches::AddToHashToEntry
LDAP.send :include, JrubyLdapPatches::AlwaysUseLdapCtxFactory
LDAP::Error.send :include, JrubyLdapPatches::MoreInformationForWrappedErrors
module LDAP
class SSLConn
# LDAP::SSLConn in jruby-ldap doesn't have the same arglist as ruby-ldap
# does, and activedirectory tries to create one with three arguments.
def initialize(host, port, *dontcare)
super(host, port)
@use_ssl = true
end
end
end
从这个patch也可以一窥ruby patch的设计:alias_method_chain和mixin。
分享到:
相关推荐
jruby安装包 和 jruby的lib库 JRuby是面向Ruby、基于Java虚拟机(JVM)的一种解释程序,它结合了Ruby语言的简易性和功能强大的JVM的执行机制,包括与Java库 全面集成。Rails彻底加快及简化了Web应用的开发,不过它让...
jruby是一个ruby的解析器,可将ruby解析为java文件,jruby作为ruby解析器时刻调用java代码
jruby-complete-1.7.19.jar,java版本的ruby解析器
jruby-1.3.1.jar包 解决org.jruby.exceptions.JumpException 等报错
本文介绍了JRuby的安装与配置。JRuby的安装需要JRuby以及JDK,本文使用的版本分别是JRuby 1.1.2以及Java 1.6。至于JRuby配置,文章主要介绍了测试JRuby安装的方法。
This book introduces you to three JRuby deployment strategies that give you the performance and scalability you need, while you use a language designed for rapid development. Explore common ...
jruby-src-1.0.zip
org.jruby.rar
jruby-bin-1.3.1.zip 用于jruby语言研发的必要工具
JRuby window X64 开发软件
jRuby On Rails WEB 2.0
jruby与java使用开发,听说jruby能是swing的调用变为更简单
JRuby语言实战技术,java下运用ruby
对于Jruby、Jython和Groovy三种动态语言,长期以来很多人犹豫于如何选择它们。本文提出一个非常有力的例证证明:如果你是一个基于Java虚拟机的开发者,那么请放弃Jruby和Jython。
Now you can bring the best of Ruby into the world of Java, with Using JRuby. Come to the source for the JRuby core team’s insights and insider tips. You’ll learn how to call Java objects seamlessly ...
jruby 1.9.6 win64
JRuby在Java测试中的应用,使用脚本语言,高效快进行Java程序测试。
jruby-1.5.5+OperaWatir+RSpec
jruby-dist-9.1.15.0-bin.zip JRuby是面向Ruby、基于Java虚拟机(JVM)的一种解释程序,它结合了Ruby语言的简易性和功能强大的JVM的执行机制,包括与Java库 全面集成。 截至2017.12.08最新稳定版 JRuby 官方更新说明:...
Ruby 、 Rails 、JRuby 都是令人兴奋的技术