当使用AD配置的Guvnor作为端点时,Guvnor执行服务器获得401

时间:2012-06-19 15:48:05

标签: drools

我们正在使用:

•Drools Drools 5.0.x附带的Execution Server •Drools配置了活动目录的Guvnor 5.2

执行服务器和guvnor在同一个Tomcat上运行并使用相同的端口。

使用执行服务器,您可以为配置文件中的每个包提供一个侦听器。我有两个这样的文件,from-file-system.properties指向手动部署drools二进制包的本地目录。这很好。

但我尝试使用with-guvnor.properties,它指向5.3 Guvnor上的包二进制文件。这是文件:

name=ndipiazza
newInstance=true
# Absolute path of the directory containing pc.drl: placeholder replaced by Ant.
url=http://localhost:9109/drools-guvnor/rest/packages/NDD_Test/binary
poll=10

我收到以下错误:

RuleAgent(ndipiazza) INFO (Mon Jun 18 18:11:32 EDT 2012): Configuring package provider : URLScanner monitoring URLs:  http://localhost:9109/drools-guvnor/rest/packages/NDD_Test/binary
RuleAgent(ndipiazza) WARNING (Mon Jun 18 18:11:34 EDT 2012): Was an error contacting http://localhost:9109/drools-guvnor/rest/packages/NDD_Test/binary. Reponse header: {null=[HTTP/1.1 401 Unauthorized]

某种授权错误很可能与Guvnor 5.2中的活动目录配置有关。 对于我们来说,这对于我们来说只是对早期版本的Guvnor很好。

如何解决此问题?

1 个答案:

答案 0 :(得分:2)

所以我们今天就解决了这个问题。 Drools Server 5.0.x在具有任何类型的身份验证时无法支持URL端点。

我报告了一个错误:https://issues.jboss.org/browse/JBRULES-3554

如果没有这些更改,这将无效。

drools-core的org/drools/agent/HttpClientImpl.java

这两种方法需要添加身份验证(由START和END NDD标记),并且显然需要使用您的用户名/密码进行切换。

public LastUpdatedPing checkLastUpdated(URL url) throws IOException {
        URLConnection con = url.openConnection();
        HttpURLConnection httpCon = (HttpURLConnection) con;
        try {
// **** START NDD ***** 
            BASE64Encoder enc = new sun.misc.BASE64Encoder();
            String userpassword = "ad-user" + ":" + "ad-password";
            String encodedAuthorization = enc.encode( userpassword.getBytes() );
            httpCon.setRequestProperty("Authorization", "Basic "+
                  encodedAuthorization);
            // **** END NDD *****             



            httpCon.setRequestMethod( "HEAD" );            


            String lm = httpCon.getHeaderField( "lastModified" );
            LastUpdatedPing ping = new LastUpdatedPing();

            ping.responseMessage = httpCon.getHeaderFields().toString();

            if ( lm != null ) {
                ping.lastUpdated = Long.parseLong( lm );
            } else {
                long httpLM = httpCon.getLastModified();
                if ( httpLM > 0 ) {
                    ping.lastUpdated = httpLM;
                }
            }

            return ping;
        } finally {
            httpCon.disconnect();
        }

    }

    public Package fetchPackage(URL url) throws IOException,
                                        ClassNotFoundException {
        URLConnection con = url.openConnection();
        HttpURLConnection httpCon = (HttpURLConnection) con;
        try {

            // **** START NDD ***** 
            BASE64Encoder enc = new sun.misc.BASE64Encoder();
            String userpassword = "ad-user" + ":" + "ad-password";
            String encodedAuthorization = enc.encode( userpassword.getBytes() );
            httpCon.setRequestProperty("Authorization", "Basic "+
                  encodedAuthorization);
            // **** END NDD *****             




            httpCon.setRequestMethod( "GET" );

            Object o = DroolsStreamUtils.streamIn( httpCon.getInputStream() );

            if ( o instanceof KnowledgePackageImp ) {
                return ((KnowledgePackageImp) o).pkg;
            } else {
                return (Package) o;
            }
        } finally {
            httpCon.disconnect();
        }
    }

神秘解决了。