6 Replies Latest reply on Aug 15, 2008 12:27 PM by jaikiran pai

    javax.crypto.Mac

    Rob Staveley (Tom) Newbie

      If I try to get an instance of a javax.crypto.Mac, usingjavax.crypto.Mac mac = javax.crypto.Mac.getInstance("HmacSHA1");, I get a NoClassDefFoundError.

      I've looked at the JRE (Sun 1.5.0.10), and see jce.jar in the lib directory and sure enough javax.crypto.Mac.class is in that jar, so I wonder why it isn't loading in JBoss and how to make it do so.

        • 1. Re: javax.crypto.Mac
          Rob Staveley (Tom) Newbie

          I'm getting this LinkageError with 4.2.2GA with default settings on Debian Linux. When you install JBoss via apt-get on Debian Linux, this is the default version.

          It doesn't happen on a 4.0.2 installation, which I have access to on a Sun server.

          Here's a simple JSP to reproduce the problem.


          <%

          try {
          javax.crypto.Mac mac = javax.crypto.Mac.getInstance("HmacSHA1");
          if (mac == null) {
          out.print("No Mac found for HmacSHA1");
          }
          else {
          java.security.Provider provider = mac.getProvider();
          out.print("Mac instance: "+mac.getClass().getName()+"\r\n");
          out.print("Provider: "+provider.getClass().getName()+" - "+provider.getInfo()+"\r\n");
          out.print("Algorithm: "+mac.getAlgorithm()+"\r\n");
          }
          }
          catch (Exception e) {
          out.print("Exception thrown, while inspecting crypto for HmacSHA1\n"+e.getMessage()+"\r\n");
          }
          catch (LinkageError le) {
          out.print("Linkage error in javax.crypto.Mac\r\n"+le.getMessage()+"\r\n");
          }
          %>

          • 2. Re: javax.crypto.Mac
            jaikiran pai Master

            Please post the entire exception stacktrace.

            • 3. Re: javax.crypto.Mac
              Rob Staveley (Tom) Newbie

              Here's a full dump:

              Linkage error in javax.crypto.Mac
              java.lang.NoClassDefFoundError
              at javax.crypto.Mac.getInstance(DashoA12275)
              at org.apache.jsp.test_jsp._jspService(test_jsp.java:66)
              at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
              at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
              at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
              at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
              at java.lang.Thread.run(Thread.java:595)

              Using...


              <%!
              public static String getStackTrace(Throwable e) {
              final java.io.Writer result = new java.io.StringWriter();
              final java.io.PrintWriter writer = new java.io.PrintWriter(result);
              e.printStackTrace(writer);
              return result.toString();
              }
              %>
              <%

              try {
              javax.crypto.Mac mac = javax.crypto.Mac.getInstance("HmacSHA1");
              if (mac == null) {
              out.print("No Mac found for HmacSHA1");
              }
              else {
              java.security.Provider provider = mac.getProvider();
              out.print("Mac instance: "+mac.getClass().getName()+"\r\n");
              out.print("Provider: "+provider.getClass().getName()+" - "+provider.getInfo()+"\r\n");
              out.print("Algorithm: "+mac.getAlgorithm()+"\r\n");
              }
              }
              catch (Exception e) {
              out.print("Exception thrown, while inspecting crypto for HmacSHA1\n"+e.getMessage()+"\r\n");
              }
              catch (LinkageError le) {
              out.print("Linkage error in javax.crypto.Mac\r\n"+getStackTrace(le).replace("\n","")+"\r\n");
              }

              %>

              • 4. Re: javax.crypto.Mac
                Rob Staveley (Tom) Newbie

                jaikiran, I just look a look at http://jaitechwriteups.blogspot.com/ and followed your advice about setting up jboss-web.xml and have fixed my problem as a consequence. [And sorted out logging properly in the process.]

                • 5. Re: javax.crypto.Mac
                  Rob Staveley (Tom) Newbie

                  Many thanks!

                  • 6. Re: javax.crypto.Mac
                    jaikiran pai Master

                    Great! :)