繁体   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