简体   繁体   English

java.lang.ClassNotFoundException: org.junit.Assert / 使用文档化 API

[英]java.lang.ClassNotFoundException: org.junit.Assert / Working with docising API

I have encountered these errors when trying to implement the docusing embedded signature into my web app (java -eclipse).在尝试将文档嵌入签名实现到我的 Web 应用程序(java -eclipse)中时,我遇到了这些错误。

java.lang.ClassNotFoundException: org.junit.Assert
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1412)
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1220)
    com.uniquedeveloper.registration.test2.EmbeddedSigningTest(test2.java:94)
    com.uniquedeveloper.registration.test2.doPost(test2.java:79)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:681)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Here is my code for the test2 class:这是我的 test2 类的代码:


    package com.uniquedeveloper.registration;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.nio.file.Files;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.util.ArrayList;
    import java.util.Base64;
    import java.util.List;
    import java.util.stream.Collectors;
    
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.Part;
    import javax.servlet.jsp.PageContext;
    
    import org.apache.tomcat.util.http.fileupload.FileUpload;
    import static org.junit.Assert.*;
    
    import org.junit.Assert;
    import org.junit.Test;
    
    import com.docusign.esign.api.EnvelopesApi;
    import com.docusign.esign.client.ApiClient;
    import com.docusign.esign.client.ApiException;
    import com.docusign.esign.model.Document;
    import com.docusign.esign.model.EnvelopeDefinition;
    import com.docusign.esign.model.EnvelopeSummary;
    import com.docusign.esign.model.RecipientViewRequest;
    import com.docusign.esign.model.Recipients;
    import com.docusign.esign.model.SignHere;
    import com.docusign.esign.model.Signer;
    import com.docusign.esign.model.Tabs;
    import com.docusign.esign.model.ViewUrl;
    
    /**
     * Servlet implementation class test2
     */
    @WebServlet("/test2")
    public class test2 extends HttpServlet {
        private static final long serialVersionUID = 1L;
        
        
           
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String rEmail = request.getParameter("recipientem");
            String rName = request.getParameter("recipientname");
        /*Part file = request.getPart("file_upload");
            */
            
            /* String filePath = (String)request.getServletContext().getInitParameter("file_upload");*/
            
            /*Part filePart = request.getPart("file_upload");
            String fileName=filePart.getSubmittedFileName();
            for(Part part : request.getParts()) {
                part.write("C:\\Bureau\\"+ fileName);
            */
            
            /*Part filePart = request.getPart("file_upload");
            InputStream filecontent = filePart.getInputStream();
            
            if (filePart != null) {
                filecontent = filePart.getInputStream();
            }
            else {
                System.out.println("KHAWI");
            }*/
        
             String filePath = (String)request.getServletContext().getInitParameter("file_upload");
             System.out.println("ZWIN1");
            
                    EmbeddedSigningTest(rEmail, rName, filePath);
                
                  }
    
        @Test
        public void EmbeddedSigningTest(String rEmail, String rName, String filePath ) {
             String AccountId = "16501888";
            System.out.println("\nEmbeddedSigningTest:\n" + "===========================================");
            byte[] fileBytes = null;
            try {
                String currentDir = System.getProperty("user.dir");
    
                Path path = Paths.get(currentDir + filePath);
                fileBytes = Files.readAllBytes(path);
                
            } catch (IOException ioExcp) {
                Assert.assertNull(ioExcp);
            }
            System.out.println("ZWIN2");
            // create an envelope to be signed
            EnvelopeDefinition envDef = new EnvelopeDefinition();
            envDef.setEmailSubject("Please Sign my Java SDK Envelope (Embedded Signer)");
            envDef.setEmailBlurb("Hello, Please sign my Java SDK Envelope.");
    
            // add a document to the envelope
            Document doc = new Document();
            String base64Doc = Base64.getEncoder().encodeToString(fileBytes);
            doc.setDocumentBase64(base64Doc);
            doc.setName(filePath);
            doc.setDocumentId("1");
    
            List<Document> docs = new ArrayList<>();
            docs.add(doc);
            envDef.setDocuments(docs);
    
            // Add a recipient to sign the document
            Signer signer = new Signer();
            signer.setEmail(rEmail);
            String name = "Pat Developer";
            signer.setName(rName);
            signer.setRecipientId("1");
    
            // this value represents the client's unique identifier for the signer
            String clientUserId = "2adce842-15eb-4744-9807-5a82020cc313 ";
            signer.setClientUserId(clientUserId);
    
            // Create a SignHere tab somewhere on the document for the signer to
            // sign
            SignHere signHere = new SignHere();
            signHere.setDocumentId("1");
            signHere.setPageNumber("1");
            signHere.setRecipientId("1");
            signHere.setXPosition("100");
            signHere.setYPosition("100");
            signHere.setScaleValue("0.5");
    
            List<SignHere> signHereTabs = new ArrayList<>();
            signHereTabs.add(signHere);
            Tabs tabs = new Tabs();
            tabs.setSignHereTabs(signHereTabs);
            signer.setTabs(tabs);
    
            // Above causes issue
            envDef.setRecipients(new Recipients());
            envDef.getRecipients().setSigners(new ArrayList<>());
            envDef.getRecipients().getSigners().add(signer);
    
            // send the envelope (otherwise it will be "created" in the Draft folder
            envDef.setStatus("sent");
    
            try {
                EnvelopesApi envelopesApi = new EnvelopesApi();
                EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(AccountId, envDef);
    
                Assert.assertNotNull(envelopeSummary);
                Assert.assertNotNull(envelopeSummary.getEnvelopeId());
    
                System.out.println("EnvelopeSummary: " + envelopeSummary);
    
                String returnUrl = "http://localhost:8080/index/";
                RecipientViewRequest recipientView = new RecipientViewRequest();
                recipientView.setReturnUrl(returnUrl);
                recipientView.setClientUserId(clientUserId);
                recipientView.setAuthenticationMethod("email");
                recipientView.setUserName(name);
                recipientView.setEmail(rEmail);
    
                ViewUrl viewUrl = envelopesApi.createRecipientView(AccountId, 
             envelopeSummary.getEnvelopeId(), recipientView);
    
                Assert.assertNotNull(viewUrl);
                Assert.assertNotNull(viewUrl.getUrl());
                // This Url should work in an Iframe or browser to allow signing
                System.out.println("ViewUrl is " + viewUrl);
    
            } catch (ApiException ex) {
                Assert.fail("Exception: " + ex);
            } catch (Exception e) {
                Assert.fail("Exception: " + e.getLocalizedMessage());
            }
    
        }
    }

I (pretty sure ) think it has something to do with the file not being uplaoded properly ( null).我(很确定)认为这与文件没有正确上传(null)有关。 Please help !请帮忙 !

The error is telling you that the class org.junit.Assert is not on the classpath.该错误告诉您类org.junit.Assert不在类路径中。 Meaning that the JUnit library is missing or it has the wrong scope (if you are using a building tool like Maven or Gradle).这意味着 JUnit 库丢失或范围错误(如果您使用的是 Maven 或 Gradle 等构建工具)。

The whole class has several problems, I suspect you are trying to deploy the servlet on Tomcat and there the JUnit dependency is missing.整个类有几个问题,我怀疑您正在尝试在 Tomcat 上部署 servlet,并且缺少 JUnit 依赖项。 You should redesign it and keep the test separated from the servlet.您应该重新设计它并将测试与 servlet 分开。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java org.junit.Assert 线程安全吗? - Is Java org.junit.Assert thread safe? JUnit 5 migration - how to solve java.lang.ClassNotFoundException: org.junit.jupiter.api.extension.ReflectiveInvocationContext - JUnit 5 migration - how to solve java.lang.ClassNotFoundException: org.junit.jupiter.api.extension.ReflectiveInvocationContext 为什么自动依赖是错误版本?(java.lang.ClassNotFoundException: org.junit.jupiter.api.MethodOrdererContext) - why auto dependency is error version?(java.lang.ClassNotFoundException: org.junit.jupiter.api.MethodOrdererContext) org.junit.Assert本身的JUnit NoClassDefFoundError - JUnit NoClassDefFoundError on org.junit.Assert itself 无法识别Java文件中的“导入org.junit.Assert” - Cannot recognise “import org.junit.Assert” in a java file java.lang.ClassNotFoundException:org.junit.runners.BlockJUnit4ClassRunner - java.lang.ClassNotFoundException: org.junit.runners.BlockJUnit4ClassRunner 导入org.junit.Assert时出错 - Error with import of org.junit.Assert JUnit 测试失败 | 引起:java.lang.ClassNotFoundException:org.junit.runner.JUnitCore - JUnit test failure | Caused by: java.lang.ClassNotFoundException: org.junit.runner.JUnitCore java.lang.ClassNotFoundException: org.junit.platform.engine.ConfigurationParameters Junit5 与 eclipse - java.lang.ClassNotFoundException: org.junit.platform.engine.ConfigurationParameters Junit5 with eclipse 带有ant + Junit的java.lang.classnotfoundexception - java.lang.classnotfoundexception with ant + Junit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM