簡體   English   中英

java.net.MalformedURLException:無協議

[英]java.net.MalformedURLException:no protocol

我有以下代碼

    String url = "http://e2e-soaservices:44000/3.1/StandardDocumentService?wsdl";
    //createSOAPRequest(); 
    SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);

在 createSOAPRequest 方法中:-

    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    File fXmlFile = new File("src/XML/gen_VDD7S0PLYPAS058_1409900400000_2.xml");
    String xmlStr=finalXmlString(fXmlFile);
    DocumentBuilderFactory docBuilderFactory=DocumentBuilderFactory.newInstance();
    docBuilderFactory.setNamespaceAware(true);   
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();   
    Document doc=docBuilder.parse(xmlStr);  
    System.out.println("dasdasdasd"+doc.toString());
    String serverURI = "http://www.aaancnuie.com/DCS/2012/01/DocumentCreation/IStandardDocumentService/CreateDocuments";
    
    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("example", serverURI);
    SOAPBody soapBody = envelope.getBody();
    soapBody.setTextContent(xmlStr);
    soapMessage.saveChanges();
    return soapMessage;

錯誤信息

Error occurred while sending SOAP Request to Server
java.net.MalformedURLException: no protocol: http%3A%2F%2Fe2e-soaservices%3A44000%2F3.1%2FStandardDocumentService%3Fwsdl
    at java.net.URL.<init>(URL.java:567)
    at java.net.URL.<init>(URL.java:464)
    at java.net.URL.<init>(URL.java:413)
    at SOAPCLIENTSAAJ.main(SOAPCLIENTSAAJ.java:36)

您需要對您的 URL 進行encode 必須轉義的特殊字符。

轉義示例:

String url = "http://e2e-soaservices:44000/3.1/StandardDocumentService?wsdl";
String yourURLStr = java.net.URLEncoder.encode(url, "UTF-8");
java.net.URL url = new java.net.URL(yourURLStr);

所以實際的問題是你試圖使用一個 URL,其中各種字符在它們不應該被轉義時被 % 轉義。

特別是,最初的http%3A%2F%2F實際上應該是http:// URL 解析器查找 initial : ... 當它找不到它時,它會抱怨(正確!)該 URL 沒有協議組件。

我注意到錯誤消息與您代碼中的 URL 不匹配。 我不知道那里發生了什么....但是如果錯誤消息中的 URL 是實際使用的,那么它需要被解碼(而不是編碼)。


如果這沒有意義,請提供一個適當的完整的最小可重現示例,以及您從執行該示例中獲得的堆棧跟蹤。

暫無
暫無

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

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