0

SAAJ を使用して認証済み Web サービスを使用しようとしています。これは私がこれまでに持っているコードです:

import java.io.ByteArrayOutputStream;

import javax.xml.soap.*;
import biz.source_code.base64Coder.*;


public class Client {
    private static String endpoint = "https://example.com/xxx.php",
    username = "xxx", password = "xxx";

    private static SOAPMessage getRequest() throws Exception{
        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage message = factory.createMessage();

        //set authorization as a HTTP header
        String authorization = Base64Coder.encodeString(username + ":" + password);
        MimeHeaders hd = message.getMimeHeaders();
        hd.addHeader("Authorization", "Basic " + authorization);

        //Call getReportList operation


        return message;
    }


    public static void main(String[] args) throws Exception {
        SOAPConnectionFactory connFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = connFactory.createConnection();

        // create request message and give it content
        SOAPMessage request = Client.getRequest();

        // call the API endpoint with the request
        SOAPMessage response = connection.call(request, endpoint);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        response.writeTo(out);
        String strMsg = new String(out.toByteArray());
        System.out.println(strMsg);
    }

}

これを実行すると、次のように strMsg (Web サービスからの応答) が出力されます。

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>WSDL</faultcode><faultstring>SOAP-ERROR: Parsing WSDL: Couldn't load from '/www/example.wsdl' : failed to load external entity "/www/example.wsdl"
</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

私は自分自身を認証したと推測していますが、私のものではない Web サービスに問題がありました。しかし、私は完全にはわかりません。このエラー メッセージはあまり一般的ではないようです。

これは、提供した認証が正しくないか不十分だったということですか? または、Web サービスが SSL を使用しているため、SSL 証明書を提供する必要がありますか? はいの場合、SAAJ で SSL 証明書を使用する方法に関するチュートリアルはありますか?

4

1 に答える 1

0

問題は、「https://example.com/xxx.php?wsdl 」ではなく「 https://example.com/xxx.php をエンドポイントとして使用していたことです。そのため、wsdl ファイルをロードできませんでした。

于 2016-02-11T16:37:36.310 に答える