简体   繁体   中英

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:-

    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. 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.

In particular, the initial http%3A%2F%2F should actually be 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.

I note that the error message does not match the URL in your code. 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).


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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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