0
votes

I am testing an API which is supposed to fetch a document from an envelope. Here is the example code:

@RestController
@Controller
@RequestMapping(value = "DocuSign")
public class DocusignController extends CoreController {

@RequestMapping(value = "/FetchPDF", method = RequestMethod.GET)
@ResponseBody
public MessageItem downloadDocument(Model model) throws ApiException, IOException {

    WorkArguments args = new WorkArguments();
    args.setAccountId("1e8dce91-c5....");
    args.setDocumentId("1");
    args.setEnvelopeId("ec1f77....");

    String accessToken = "eyJ0eXAiOiJNVCIsImFsZyI6I.....";
    String baseUrl = "https://demo.docusign.net/restapi";

    JSONObject obj = doWork(args, null, accessToken, baseUrl);

    MessageItem msg = new MessageItem();

    msg.setMsg("Done!");
    return msg;
}

protected JSONObject doWork(WorkArguments args, ModelMap model,
        String accessToken, String basePath) throws ApiException, IOException {

    // Data for this method
    // accessToken    (argument)
    // basePath       (argument)
    String accountId = args.getAccountId();
    String envelopeId = args.getEnvelopeId();
    String documentId = args.getDocumentId();

    ApiClient apiClient = new ApiClient(basePath);
    apiClient.addDefaultHeader("Authorization", "Bearer " + accessToken);
    EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);

    System.out.println("--->Checking if anything is null...");
    if(envelopesApi == null )
        System.out.println("Enveloper API is null!");

    if(apiClient == null)
        System.out.println("The apiClient is null!");
    // Step 1. EnvelopeDocuments::get.
    // Exceptions will be caught by the calling function
   byte[] results = envelopesApi.getDocument(accountId, envelopeId, documentId);

    String mimetype = ".pdf";
    String docName = "success"; 
    ... etc.

When I go and test it with my rest client, I keep getting the following error:

Type Exception Report

Message Request processing failed; nested exception is com.sun.jersey.api.client.ClientHandlerException

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.sun.jersey.api.client.ClientHandlerException org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) Root Cause

com.sun.jersey.api.client.ClientHandlerException com.docusign.esign.client.auth.OAuth.updateAccessToken(OAuth.java:111) com.docusign.esign.client.auth.OAuth.applyToParams(OAuth.java:99) com.docusign.esign.client.ApiClient.updateParamsForAuth(ApiClient.java:1209) com.docusign.esign.client.ApiClient.getAPIResponse(ApiClient.java:1094) com.docusign.esign.client.ApiClient.invokeAPI(ApiClient.java:1158) com.docusign.esign.api.EnvelopesApi.getDocument(EnvelopesApi.java:2624) com.docusign.esign.api.EnvelopesApi.getDocument(EnvelopesApi.java:2556) delaware.gov.dti.ice.esignprototypev1.controller.DocusignController.doWork(DocusignController.java:82) delaware.gov.dti.ice.esignprototypev1.controller.DocusignController.downloadDocument(DocusignController.java:52) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) Root Cause

java.lang.NullPointerException com.docusign.esign.client.auth.OAuth.updateAccessToken(OAuth.java:109) com.docusign.esign.client.auth.OAuth.applyToParams(OAuth.java:99) com.docusign.esign.client.ApiClient.updateParamsForAuth(ApiClient.java:1209) com.docusign.esign.client.ApiClient.getAPIResponse(ApiClient.java:1094) com.docusign.esign.client.ApiClient.invokeAPI(ApiClient.java:1158) com.docusign.esign.api.EnvelopesApi.getDocument(EnvelopesApi.java:2624) com.docusign.esign.api.EnvelopesApi.getDocument(EnvelopesApi.java:2556) delaware.gov.dti.ice.esignprototypev1.controller.DocusignController.doWork(DocusignController.java:82) delaware.gov.dti.ice.esignprototypev1.controller.DocusignController.downloadDocument(DocusignController.java:52) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

I am using docusign-esign-java version 3.2.0, which is cucrently the latest. I am able to fetch the doucment when using the rest client, so I know that at least my account id, access token and document id (and template id) are correct. Also I am basing my solution from the following DocuSign refrence page Downloading Envelope Documents and using the provided downloaded code just for to doubleche to see if I am missing anything.

Furthermore I checked to see if the apiClient or the envelopesApi objects are null and they are not so I am getting the problem on the

byte[] results = envelopesApi.getDocument(accountId, envelopeId, documentId);

which for some reason, seems to give a null pointer exception. Any idea as to why?

1

1 Answers

0
votes

I updated existing example without Spring to test 3.2.0 version, and it seems to work fine for me and it is not throwing any exception. If it is working w/o Spring then it will work with Spring as well, so does not look like any issue in SDK.

public void listDocuments(String envelopeId) throws ApiException, IOException {

        this.checkToken();
        EnvelopesApi envelopeApi = new EnvelopesApi(this.apiClient);

        EnvelopeDocumentsResult envelopeDocumentsResult = envelopeApi.listDocuments(this.getAccountId(), envelopeId);
        List<EnvelopeDocument> envelopeDocuments = envelopeDocumentsResult.getEnvelopeDocuments();

        for (EnvelopeDocument envelopeDocument : envelopeDocuments) {

            System.out.println("documentId " + envelopeDocument.getDocumentId());
            envelopeApi.getDocument(this.getAccountId(), envelopeId, envelopeDocument.getDocumentId());
        }

    }