简体   繁体   English

java.net.MalformedURLException:无协议

[英]java.net.MalformedURLException:no protocol

I've the following code我有以下代码

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

in the createSOAPRequest Method:-在 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;

The error message错误信息

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)

You need to encode your URL.您需要对您的 URL 进行encode Special character which have to be escaped.必须转义的特殊字符。

Escaping example:转义示例:

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);

So the actual problem is that you are trying to use a URL where various characters have been %-escaped when they shouldn't be.所以实际的问题是你试图使用一个 URL,其中各种字符在它们不应该被转义时被 % 转义。

In particular, the initial http%3A%2F%2F should actually be http:// .特别是,最初的http%3A%2F%2F实际上应该是http:// The URL parser looks for initial : ... and when it can't find it, it complains (correctly!) that there is no protocol component to the URL. URL 解析器查找 initial : ... 当它找不到它时,它会抱怨(正确!)该 URL 没有协议组件。

I note that the error message does not match the URL in your code.我注意到错误消息与您代码中的 URL 不匹配。 I don't know what is going on there .... but if the URL in the error message is what is actually being used, then it needs to be decoded (not encoded).我不知道那里发生了什么....但是如果错误消息中的 URL 是实际使用的,那么它需要被解码(而不是编码)。


If this is not making sense, please provide a proper complete minimal reproducible example , AND the stack trace that you get from executing that example.如果这没有意义,请提供一个适当的完整的最小可重现示例,以及您从执行该示例中获得的堆栈跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM