2011-04-26 65 views
2

我上滴料工作,我下面的代碼401例外在Java代碼中

import org.drools.RuleBase; 
import org.drools.agent.RuleAgent; 
import org.drools.definition.type.FactType; 

public class MortgageApplicationTest { 
    /** 
    * @param args 
    * @throws IllegalAccessException 
    * @throws InstantiationException 
    */ 
    public static void main(String[] args) throws InstantiationException, IllegalAccessException { 

     RuleAgent agent = RuleAgent.newRuleAgent("/mortgageapproval.properties"); 
     RuleBase rb = agent.getRuleBase(); 

     FactType appType = rb.getFactType("mortgages.LoanApplication"); 
     FactType incomeType = rb.getFactType("mortgages.IncomeSource"); 

     Object application = appType.newInstance(); 
     Object income = incomeType.newInstance(); 

     appType.set(application, "amount", 25000); 
     appType.set(application, "deposit", 1500); 
     appType.set(application, "lengthYears", 20); 

     incomeType.set(income, "type", "Job"); 
     incomeType.set(income, "amount", 65000); 


     rb.newStatelessSession().execute(new Object[] {application, income}); 

     System.out.println(application); 
    } 

} 

以下是我mortgageapproval.properties文件

url=http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/mortgages/LATEST 
userName=admin 
password=admin 

這整個代碼設置拋出下面的401錯誤

RuleAgent(default) INFO (Tue Apr 26 11:03:25 IST 2011): Configuring with newInstance=true, secondsToRefresh=-1 
RuleAgent(default) INFO (Tue Apr 26 11:03:25 IST 2011): Configuring package provider : URLScanner monitoring URLs: http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/mortgages/LATEST 
RuleAgent(default) EXCEPTION (Tue Apr 26 11:03:25 IST 2011): Server returned HTTP response code: 401 for URL: http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/mortgages/LATEST. Stack trace should follow. 
java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/mortgages/LATEST 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1403) 
    at org.drools.agent.HttpClientImpl.fetchPackage(HttpClientImpl.java:50) 
    at org.drools.agent.URLScanner.readPackage(URLScanner.java:148) 
    at org.drools.agent.URLScanner.getChangeSet(URLScanner.java:120) 
    at org.drools.agent.URLScanner.loadPackageChanges(URLScanner.java:96) 
    at org.drools.agent.RuleAgent.checkForChanges(RuleAgent.java:410) 
    at org.drools.agent.RuleAgent.refreshRuleBase(RuleAgent.java:362) 
    at org.drools.agent.RuleAgent.configure(RuleAgent.java:347) 
    at org.drools.agent.RuleAgent.init(RuleAgent.java:247) 
    at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:187) 
    at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:147) 
    at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:256) 
    at com.notidiots.MortgageApplicationTest.main(MortgageApplicationTest.java:19) 
Exception in thread "main" java.lang.NullPointerException 

....我僅在tomcat的component.xml文件中給出了身份驗證,如下所示小號

<role rolename="manager-gui"/> 
<user username="tomcat" password="tomcat" roles="manager-gui"/> 

<role rolename="admin"/> 
<user username="admin" password="admin" roles="admin"/> 

在我滴料component.xml文件下面一行顯示我沒有給任何認證

<!-- NO authentication. This will bypass the login screen when you hit the app. Everyone is "guest" --> 

<security:identity authenticate-method="#{nilAuthenticator.authenticate}"/> 

請幫我,因爲不會有太多的Drools開發人員在那裏......我不是獲得所需的幫助....

在此先感謝

+0

對不起,發佈了錯誤信息msg – 2011-04-26 05:31:17

回答

1

你得到響應一個404錯誤,當它試圖獲取您已經在配置文件設置:http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/mortgages/LATEST

做抵押包和您指向的特定文件存在?

+0

@Shane Madden對不起,這是我的錯誤,我發佈了錯誤的錯誤信息..我糾正它.. – 2011-04-26 05:35:19

+0

這改變了事情!你的'login-config'和'security-constraint'塊如何在web.xml中(或者它們被定義的任何地方)查找? – 2011-04-26 05:46:35