-2

このコードを実行すると、コンテンツはプロローグで許可されていません。私のコードでは何が間違っていますか。ここにコードがあります。

    import java.io.*;
        import java.net.URL;
        import java.net.HttpURLConnection;
        import javax.xml.xpath.*;
        import org.xml.sax.InputSource;
        import org.w3c.dom.*;

        public class GetEnvelopeDoc
        {   
            // Enter your info:
            static String username = "*****";
            static String password = "*****";
            static String integratorKey = "******";
            static String envelopeId = "**************";
            static String envelopeUri = "/envelopes/" + envelopeId;

            public static void main(String[] args) throws Exception
            {   
                String url = "https://demo.docusign.net/restapi/v2/login_information";
                String baseURL = "";    // we will retrieve this
                String accountId = "";  // will retrieve

                String authenticateStr = 
                    "<DocuSignCredentials>" + 
                    "<Username>" + username + "</Username>" +
                    "<Password>" + password + "</Password>" + 
                    "<IntegratorKey>" + integratorKey + "</IntegratorKey>" +
                    "</DocuSignCredentials>";

                //
                // STEP 1 - Login
                //
                HttpURLConnection conn = (HttpURLConnection)new URL(url).openConnection();
                conn.setRequestProperty("X-DocuSign-Authentication", authenticateStr);
                conn.setRequestProperty("Content-Type", "application/xml");
                conn.setRequestProperty("Accept", "application/xml");
                int statusValue = conn.getResponseCode(); // side-effect of this call is to fire the request off
                if( statusValue != 200 )    // 200 = OK
                {
                    System.out.print("Error calling webservice, status is: " + statusValue);
                    System.exit(-1);
                }
                // we use xPath to get the baseUrl and accountId from the XML response body
                BufferedReader br = new BufferedReader(new InputStreamReader( conn.getInputStream() ));
                StringBuilder responseText = new StringBuilder();   String line = null;
                while ( (line = br.readLine()) != null)
                    responseText.append(line);
                String token1 = "//*[1]/*[local-name()='baseUrl']";
                String token2 = "//*[1]/*[local-name()='accountId']";
                XPath xPath = XPathFactory.newInstance().newXPath();
                baseURL = xPath.evaluate(token1, new InputSource(new StringReader(responseText.toString())));
                accountId = xPath.evaluate(token2, new InputSource(new StringReader(responseText.toString())));

                //--- display results
                System.out.println("baseUrl = " + baseURL + "\naccountId = " + accountId);

                //
                // STEP 2 - Get Info on Envelope's Document(s)
                //


> conn = (HttpURLConnection)new URL(baseURL + envelopeUri +
> "/documents/combined").openConnection();
>               conn.setRequestProperty("X-DocuSign-Authentication", authenticateStr);
>               conn.setRequestProperty("Content-Type", "application/json"); 
>               conn.setRequestProperty("Accept", "application/pdf"); 
>               statusValue = conn.getResponseCode(); // triggers the request

                if( statusValue != 200 )    
                {
                    System.out.println("Error calling webservice, status is: " + statusValue);
                    System.exit(-1);
                }
                // Read the response
                InputStreamReader isr = new InputStreamReader(new DataInputStream( conn.getInputStream() ));
                System.out.println(isr.toString());
                br = new BufferedReader(isr);
                StringBuilder response = new StringBuilder();
                while ( (line = br.readLine()) != null)
                response.append(line);
                XPathFactory factory = XPathFactory.newInstance();
                XPath xpath = factory.newXPath();
                XPathExpression expr = xpath.compile("//*[1]/*[local-name()='envelopeDocument']");
                Object result = expr.evaluate(new InputSource(new StringReader(response.toString())), XPathConstants.NODESET);

                //--- display results
                System.out.println("\nDocument List -->");
                int cnt = -1;
                NodeList documents = (NodeList) result;
                String[] docURIs = new String[documents.getLength()];
                for (int i = 0; i < documents.getLength(); i++) 
                {
                    Node node = documents.item( i );
                    if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
                        NodeList docNodes = node.getChildNodes();
                        for (int j = 0; j < docNodes.getLength(); j++)
                        {
                            if( docNodes.item(j).getLocalName().equals("documentId"))
                                System.out.print("documentId: " + docNodes.item(j).getTextContent());
                            if( docNodes.item(j).getLocalName().equals("name"))
                                System.out.print(", name: " + docNodes.item(j).getTextContent());
                            if( docNodes.item(j).getLocalName().equals("uri"))
                            {
                                docURIs[++cnt] = docNodes.item(j).getTextContent(); // store the uris for later
                                System.out.print(", uri: " + docURIs[cnt]);
                            }
                        }
                        System.out.println();
                    }
                }

                //
                // STEP 3 - Download the document(s)
                //
                for( int i = 0; i < docURIs.length; i++)
                {
                    // append document uri to url for each document
                    conn = (HttpURLConnection)new URL(baseURL + docURIs[i]).openConnection();
                    conn.setRequestProperty("X-DocuSign-Authentication", authenticateStr);
                    statusValue = conn.getResponseCode(); 
                    if( statusValue != 200 )    
                    {
                        System.out.println("Error calling webservice, status is: " + statusValue);
                        System.exit(-1);
                    }
                    // Grab the document data and write to a local file
                    isr = new InputStreamReader( conn.getInputStream() );
                    br = new BufferedReader(isr);
                    StringBuilder response2 = new StringBuilder();
                    while ( (line = br.readLine()) != null)
                        response2.append(line);
                    BufferedWriter out = new BufferedWriter(new FileWriter("document_" + i + ".pdf"));
                    out.write(response2.toString());
                    out.close();
                }
                System.out.println("\nDone downloading document(s)!");
            }
        } 
4

1 に答える 1

0

あなたの質問はあまり明確ではありません。「コンテンツはプロローグでは許可されていません」と言うときの意味がわかりませんが、コードに余分な文字が含まれているようです。この部分はコピペミスでしたか。これらの各行の前に > 記号があります。

> conn = (HttpURLConnection)new URL(baseURL + envelopeUri +
> "/documents/combined").openConnection();
>               conn.setRequestProperty("X-DocuSign-Authentication", authenticateStr);
>               conn.setRequestProperty("Content-Type", "application/json"); 
>               conn.setRequestProperty("Accept", "application/pdf"); 
>               statusValue = conn.getResponseCode(); // triggers the request
于 2013-09-13T16:44:46.517 に答える