1

There is a service endpoint and an xsd file for SOAP request. But, there is no wsdl file. How can I generate soap request (xml request as a string ) manually from this and send it to the service endpoint?

I found similar answer on SO. But it's for C# and .NET. Any idea for Java will be highly appreciated.

2
  • possible duplicate of SOAP request to WebService with java Commented Jul 30, 2014 at 19:24
  • 1
    It's not duplicate as I wanted to create the request manually without using SAAJ. Commented Jul 30, 2014 at 19:35

2 Answers 2

2

Take a look at [JAXB]: https://jaxb.java.net/ It does stuff like you are asking. It generates java classes if needed:

the command xjc is the key for generation

Sign up to request clarification or add additional context in comments.

5 Comments

I want to create the xml request manually. I don't want to add class files to access the remote methods.
I do not understand why someone is not willing to use the features your Environment provides you. Which jdk version are you using?
It's given from a third party. Only the xsd file and service endpoint have been given.
what version of JDK are you using?
JAXB is part of JDK since 1.6 so please try: xjc -p yourJavaPackage xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd It will generate you a bunch of classes you can directly use. All part of java standard none additional jar
1

Here is an example from an old project of mine connecting to a SharePoint web service. It should show you all the basics that you need.

try {
    URL sharepoint = new URL("http://server.com/_vti_bin/Lists.asmx");
    URLConnection sharepoint_connection = sharepoint.openConnection();

    String body = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
        "  <soap:Body>" +
        "  </soap:Body>" +
        "</soap:Envelope>";
    System.out.println("~~~~~ Roadmap: " + body);

    sharepoint_connection.setRequestProperty("Man", "POST /_vti_bin/Lists.asmx HTTP/1.1");
    sharepoint_connection.setRequestProperty("Host", "server.com");
    sharepoint_connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
    sharepoint_connection.setRequestProperty("Content-Length", Integer.toString(body.length()));
    sharepoint_connection.setRequestProperty("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems");

    // Write request body to SharePoint
    sharepoint_connection.setDoOutput(true);
    OutputStreamWriter writer = new OutputStreamWriter(sharepoint_connection.getOutputStream());
    writer.write(body);
    writer.close();

    //sharepoint_connection.connect();

    // Read result from SharePoint
    BufferedReader reader = new BufferedReader(new InputStreamReader(sharepoint_connection.getInputStream()));
    String inputLine;
    while ((inputLine = reader.readLine()) != null)
        xmltext += inputLine;
    reader.close();
} catch (MalformedURLException e) {     // new URL() failed
} catch (IOException e) {               // openConnection() failed
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.