mail@pastecode.io avatar
6 months ago
2.7 kB
Got it. Let's create a simple Spring Boot Maven project to send this SOAP request. 

1. Create a new Spring Boot project using Spring Initializr: https://start.spring.io/
   - Select Maven Project.
   - Set the Group and Artifact to your preference.
   - Add the dependencies: "Spring Web" and "Spring Web Services."

2. In your project, create a class for the SOAP client:

import org.springframework.ws.client.core.WebServiceTemplate;

public class SoapClient {

    private final WebServiceTemplate webServiceTemplate;

    public SoapClient(WebServiceTemplate webServiceTemplate) {
        this.webServiceTemplate = webServiceTemplate;

    public String sendSoapRequest() {
        // Replace the placeholder with your actual SOAP request
        String soapRequest = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
                "xmlns:if=\"http://ByblosUtility/IF_BYBCreateCust\">\n" +
                "   <!-- Your SOAP request here -->\n" +

        // Replace the endpoint with your actual service endpoint
        String serviceEndpoint = "";

        // Make the SOAP call
        Object response = webServiceTemplate.marshalSendAndReceive(serviceEndpoint, soapRequest);

        // Process the response as needed
        return response.toString();

3. Configure the WebServiceTemplate in a configuration class:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.ws.client.core.WebServiceTemplate;

public class SoapConfig {

    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        // Set the context path to the package where your generated JAXB classes are
        return marshaller;

    public WebServiceTemplate webServiceTemplate(Jaxb2Marshaller marshaller) {
        WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
        return webServiceTemplate;

Replace `"com.example.generated"` with the actual package of your JAXB-generated classes.

4. Run your Spring Boot application, and use the `SoapClient` to send the SOAP request.

Remember to customize the SOAP request and handle the response according to your specific requirements. Let me know if you have any questions or need further assistance!
Leave a Comment