2

おはようございます、私は抽象 Java クラスを同じ名前の 2 つのメソッドで拡張しようとしています。しかし、そのうちの 1 つだけを検証する必要があります。

ここに私のJavaコードがあります:

public abstract class ClientHandler extends Handler implements SOAPHandler<SOAPMessageContext> {
    protected boolean disable = true;
    protected X509Certificate signatureCertificate;
    protected PrivateKey privateKey;
    protected Certificate[] signatureCertificationChain;

    //Constructeur 
    protected ClientHandler(boolean disable) {
        this.disable = disable;
    }

    private boolean handleMessage(VIHF vihf) {
        //This is the beginning of the method i am trying to redefine
        X509Certificate certificate = this.signatureCertificate
        String issuer = certificate.getSubjectDN().toString();
        //some code 
        ...
    }

    public boolean handleMessage(SOAPMessageContext smc) {
        //some code
    }
  }

ここに私のJRubyコードがあります

#To make parent attributes accessible from subclasses
class  ClientHandler
   field_accessor :disable, :signatureCertificate, :privateKey, :signatureCertificationChain
end

#first version referring to that post: <http://stackoverflow.com/questions/6238734/jruby-calls-  the-wrong-method>

module RubyClientHandler
  class RClientHandler < ClientHandler
    handleMessage =  ClientHandler.java_method :handleMessage,    java.lang.Class.for_name(Java::ComSubFolder::VIHF)]

    def handleMessage(vihf)
        super(self.disableSignature)  #is this line ok or note?

        certificate = self.signatureCertificate    #do i need to use the "self" or the "@" ?
        issuer = certificate.getSubjectDN().toString()
        ...
    end
   end
end

「java_method」を使用しようとすると、最初のバージョンで次のエラーが発生します。

次に、RClientHandler クラスのこの 2 番目のバージョンを試しました

2 番目のバージョン: その投稿を参照: http://www.ruby-forum.com/topic/216636

 module RubyClientHandler
    class RClientHandler < ClientHandler
     def handleMessage(vihf)
         super          #line causing the error 
         klass = vihf.class

         if(klass.eql?(Java::ComSubFolder::VIHF) )
            self.java_send :handleMessage,[VIHF], vihf

            certificate = self.signatureCertificate
            issuer = certificate.getSubjectDN().toString()
            ...
         end
     end
   end
 end

この2番目のバージョンでは、「handleMessage」の最初の行を指している次の例外を取得しています

HANDLER_RAISED_RUNTIME_EXCEPTION
org.jruby.exceptions.RaiseException: Native Exception: 'class java.lang.StackOverflowError';     Message: null; StackTrace: java.lang.StackOverflowError
at org.jruby.proxy.com.sub.folder.ClientHandler$Proxy0.__super$handleMessage(Unknown Source)

親クラスのコンストラクターまたは親の「handleMessage」メソッドを呼び出す「スーパー」を含むこの行はありますか? 親クラスのコンストラクターに従って、ここで「スーパー」を呼び出すときに引数が必要ですか?

JRuby で 1 つ (または 2 つ) の「handleMessage」メソッドのみをオーバーライドして、この「ClientHandler」クラスを拡張する方法を教えていただければ幸いです。よろしくお願いします。

4

1 に答える 1

1

最初のバージョンでは、Java クラスの名前を文字列として渡そうとしました:

java.lang.Class.for_name('Java::ComSubFolder::VIHF')

更新: 実際には、JRuby 名前空間なので、それは機能しませんよね? クラスへの Java パスが必要です。

例:

> java.lang.Class.for_name('java.lang.StringBuffer')
=> #<Java::JavaLang::Class:0x628d2280> 
> java.lang.Class.for_name('java.util.ArrayList')
=> #<Java::JavaLang::Class:0x5057f57f>
于 2012-04-24T14:16:29.853 に答える