簡體   English   中英

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

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

在嘗試將文檔嵌入簽名實現到我的 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)

這是我的 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());
            }
    
        }
    }

我(很確定)認為這與文件沒有正確上傳(null)有關。 請幫忙 !

該錯誤告訴您類org.junit.Assert不在類路徑中。 這意味着 JUnit 庫丟失或范圍錯誤(如果您使用的是 Maven 或 Gradle 等構建工具)。

整個類有幾個問題,我懷疑您正在嘗試在 Tomcat 上部署 servlet,並且缺少 JUnit 依賴項。 您應該重新設計它並將測試與 servlet 分開。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM