代码之家  ›  专栏  ›  技术社区  ›  deltascience

不能引发AuthenticationException类型的异常JAVA

  •  1
  • deltascience  · 技术社区  · 12 年前

    我正在尝试使用Java Class AuthenticationService向户外进行身份验证。代码如下:

    public void Authenticate() throws AuthenticationException {
    
    authenticationService.authenticateAsGuest();
    
    }
    

    问题是我不能运行这个函数,因为它说

    No exception of type AuthenticationException can be thrown; an exception type must be a subclass of Throwable
    

    我使用的是Alfresco 4.2。

    相关类从以下位置导入:

    import org.alfresco.repo.security.authentication.AuthenticationException;
    import org.alfresco.service.cmr.security.AuthenticationService;
    
    3 回复  |  直到 12 年前
        1
  •  2
  •   the_marcelo_r    12 年前

    分解 org.alfresco.repo.security.authentication.AuthenticationException 并检查。

    如果您想为Java类将引发的异常指定一个有意义的名称,可以编写自己的exception类。 http://www.java2novice.com/java_exception_handling_examples/create_custom_exception/

    如果您确实想使用该类,但怀疑您的JVM加载了错误的类,可以在下面的某个位置部署JSP代码(例如,将其部署在web应用程序的根文件夹中,作为'whereis.JSP'),启动Alfresco服务器,然后检查'wheresis.JSP'页面的结果:

    <%@ page import="java.security.*" %>
    <%@ page import="java.net.URL" %>
    <%
    Class cls = org.alfresco.repo.security.authentication.AuthenticationException.class;
    ProtectionDomain pDomain = cls.getProtectionDomain();
    CodeSource cSource = pDomain.getCodeSource();
    URL loc = cSource.getLocation();
    out.println(loc);
    // it should print something like "c:/jars/MyJar.jar"
    %>
    

    这将告诉您JVM正在加载的确切jar,这可能有助于您了解发生了什么。

        2
  •  0
  •   D.R.    12 年前

    异常说明了一切:不能仅仅因为类名这么说就抛出这样的异常 Exception 或至少实施 Throwable .

    编辑:关于框架,该类可能没有被设计成像正常的Java异常那样抛出。

    你…吗 Authenticate 方法

    编辑2:根据 http://dev.alfresco.com/resource/docs/java/datamodel/org/alfresco/repo/security/authentication/AuthenticationException.html 它确实实现了 可抛出 。你确定你不是在什么鬼地方吗?例如,可能在您的应用程序容器中运行不同的版本?

        3
  •  -1
  •   deltascience    12 年前

    我解决了这个问题。感谢Marcelor的帖子。 首先,我创建了一个类,在其中测试了这个:

    public class main {
    
    /**
     * @param args
     * @throws AuthenticationFault
     */
    public static void main(String[] args) throws AuthenticationFault {
      // TODO Auto-generated method stub
      Class cls = org.alfresco.repo.security.authentication.AuthenticationException.class;
      ProtectionDomain pDomain = cls.getProtectionDomain();
      CodeSource cSource = pDomain.getCodeSource();
      URL loc = cSource.getLocation();
      System.out.println(loc);
    }
    

    运行程序后,您将在库中获得丢失的类。此类由AuthenticationException使用。 我得到了错误:

     java.lang.ClassNotFoundException: org.alfresco.error.AlfrescoRuntimeException
    

    然后我将包含org.alfresco.error.AlfrescoRuntimeException的alfresco-core.jar添加到我的类路径中。 我又跑了一次班,一切都很好。

    我多次遇到这个错误,我用这个方法解决了它。

    希望有帮助!