0

Enlisted は、ユーザーからの入力を検証するために、Guvnor からルールを読み取るために使用する方法です。 1. ユーザーの GUI を形成する Web アプリ (Tomcat v7.0 サーバー) 2. Web サービス (JBoss) EAP 6.0) は、drools API を使用して Guvnor からルールを読み取り、それらを Web サービスとして公開します。 3. ルールのリポジトリーとして機能する Guvnor (Jboss AS 7)。

フォーム (Web アプリ) を送信しようとすると、コンソールに次のエラーが表示されます:-

INFO  [stdout] (Thread-77) [2012:10:296 10:10:504:info] KnowledegAgent has started listening for ChangeSet notifications
10:52:17,800 INFO  [stdout] (http-localhost/127.0.0.1:8180-1) (null: 5, 174): cvc-elt.1: Cannot find the declaration of element 'change-set'.
10:52:17,831 INFO  [stdout] (http-localhost/127.0.0.1:8180-1) [2012:10:296 10:10:831:info] KnowledgAgent applying ChangeSet
10:52:17,831 INFO  [stdout] (http-localhost/127.0.0.1:8180-1) [2012:10:296 10:10:831:debug] KnowledgeAgent subscribing to resource=[UrlResource path='http://localhost:8080/jboss-brms/org.drools.guvnor.Guvnor/package/DroolsPackage/LATEST']
10:52:17,831 INFO  [stdout] (http-localhost/127.0.0.1:8180-1) [2012:10:296 10:10:831:debug] ResourceChangeNotification subscribing listener=org.drools.agent.impl.KnowledgeAgentImpl@295b9a to resource=[UrlResource path='http://localhost:8080/jboss-brms/org.drools.guvnor.Guvnor/package/DroolsPackage/LATEST']
10:52:17,831 INFO  [stdout] (http-localhost/127.0.0.1:8180-1) [2012:10:296 10:10:831:debug] ResourceChangeScanner subcribing notifier=org.drools.io.impl.ResourceChangeNotifierImpl@13d0493 to resource=[UrlResource path='http://localhost:8080/jboss-brms/org.drools.guvnor.Guvnor/package/DroolsPackage/LATEST']
10:52:17,831 INFO  [stdout] (http-localhost/127.0.0.1:8180-1) [2012:10:296 10:10:831:debug] KnowledgeAgent ChangeSet requires KnowledgeBuilder
10:52:17,831 INFO  [stdout] (http-localhost/127.0.0.1:8180-1) [2012:10:296 10:10:831:debug] KnowledgeAgent rebuilding KnowledgeBase using ChangeSet
10:52:17,831 INFO  [stdout] (http-localhost/127.0.0.1:8180-1) [2012:10:296 10:10:831:debug] KnowledgeAgent building resource=[UrlResource path='http://localhost:8080/jboss-brms/org.drools.guvnor.Guvnor/package/DroolsPackage/LATEST']
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1) [2012:10:296 10:10:955:exception]
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1) java.lang.RuntimeException: KnowledgeAgent exception while trying to deserialize KnowledgeDefinitionsPackage  
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:418)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:120)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:109)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at com.test.drools.ExposeDroolsWebService.checkedColor(ExposeDroolsWebService.java:50)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at java.lang.reflect.Method.invoke(Method.java:597)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:194)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:102)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:100)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:176)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:133)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
10:52:17,955 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
10:52:17,971 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
10:52:17,971 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679)
10:52:17,971 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931)
10:52:17,971 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at java.lang.Thread.run(Thread.java:662)
10:52:17,971 INFO  [stdout] (http-localhost/127.0.0.1:8180-1) Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost:8080/jboss-brms/org.drools.guvnor.Guvnor/package/DroolsPackage/LATEST 
10:52:17,971 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
10:52:17,971 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.drools.io.impl.UrlResource.getInputStream(UrlResource.java:76)
10:52:17,971 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   at org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:407)
10:52:17,971 INFO  [stdout] (http-localhost/127.0.0.1:8180-1)   ... 29 more

ルールにアクセスするために使用するコードは次のとおりです:-

Resource resource = ResourceFactory
            .newClassPathResource("com/test/rules/Color.xml");
    KnowledgeAgent kagent = KnowledgeAgentFactory
            .newKnowledgeAgent("kagent");
    kagent.monitorResourceChangeEvents(true);
    kagent.applyChangeSet(resource);
    KnowledgeBase kbase = kagent.getKnowledgeBase();
    kbase.getKnowledgePackages();
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    ksession.insert(colorBean);
    ksession.fireAllRules();
    System.out.println(colorBean.getColor());
    ksession.dispose();
    return colorBean;

誰かがこのエラーを解決するのを手伝ってくれますか?

4

2 に答える 2

1

HTTP エラー 401 は、その URL へのアクセスが許可されていないことを意味します。ユーザー名とパスワードを guvnor に提供する必要があります。

次のコードは、DRL を guvnor から String 変数に読み取ります。

private static final String AUTH = "guvnor:guvnor";
private static String readRulesFromGuvnor(URL url, String authString) {
    String returnStr = "";
    try {
        URLConnection urlConnection = url.openConnection();
        if (authString != null) {
            byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
            String authStringEnc = new String(authEncBytes);
            urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
        }
        returnStr = IOUtils.toString(urlConnection.getInputStream(), "UTF-8");
        LOGGER.info("Rules read from: {}", url.toString());
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
    }
        return returnStr;
    }
于 2012-10-23T12:15:19.323 に答える
0

Guvnor を使用している場合、パッケージ スナップショットの基本認証が必要です。変更セット xml のパッケージ URL にデフォルトで空のユーザー名とパスワードを追加します。

<resource source="http://127.0.0.1:8888/org.drools.guvnor.Guvnor/package/mortgages/LATEST" type="PKG" basicAuthentication="enabled" username="admin" password="admin" />

于 2013-01-25T21:58:18.780 に答える