top of page

Subscribe to Wisdom

Thanks for Subscribing!

Writer's picturePuru Uttam

Spring Boot Microservice - SOAP

Yes, I read right , you can use spring boot to create SOAP base services. Actually you can expose the service implementation both as REST & SOAP. It just need a small tweak to your existing REST service. This small tweak will enable existing REST service to be exposed as SOAP services as well.

Follow the below steps to achieve the same

  • Add the following dependency in your pom.xml


<dependency>
	<groupId>org.apache.cxf</groupId>
	<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
	<version>${version.org.apache.cxf}</version>
	<exclusions>
		<exclusion>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
		</exclusion>
		<exclusion>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</exclusion>
		<exclusion>
			<groupId>javax.validation</groupId>
			<artifactId>validation-api</artifactId>
		</exclusion>
	</exclusions>
</dependency>

  • Create a new Implementation of service as below (service performing addition of 2 numbers). Your main service class & RestController class remains same.


@Service
@WebService(portName = "AddPort", name = "AddEndpoint", serviceName = "AddService", targetNamespace = "http://jp.com/add/ws")
public class AddServiceSOAPImpl
{

//<editor-fold defaultstate="collapsed" desc="Logger">
private final Logger logger = LoggerFactory.getLogger(AddServiceImpl.class);
//</editor-fold>

public AddServiceResponse sum(@WebParam(name = "addServiceRequest") AddServiceRequest addServiceRequest)
{
logger.info("Recieved two numbers --> {},{}", addServiceRequest.getNumberOne(), addServiceRequest.getNumberTwo());
int sum = addServiceRequest.getNumberOne() + addServiceRequest.getNumberTwo();
AddServiceResponse addServiceResponse =new AddServiceResponse();
addServiceResponse.setTransactionId(CommonUtil.generateTXN("AddService"));addServiceResponse.setSum(sum);
logger.debug("Sum of two numbers is hahah--> " + sum);
addServiceResponse.setResponseStatus(ResponseStatus.SUCCESS.value);
logger.info("Sum of two numbers is --> " + sum);
return addServiceResponse;
}
}

  • Introduce a new class by the name WebServiceConfig.java. This class is responsible for bootstrapping SOAP end point


@Configuration
@EnableAutoConfiguration
public class WebServiceConfig
{

@Autowired
private Bus bus;

@Autowired
private AddServiceSOAPImpl addServiceSOAPImpl;

@Bean
public Endpoint endpoint()
{
EndpointImpl endpoint = new EndpointImpl(bus, addServiceSOAPImpl);
endpoint.publish("/v1/");
return endpoint;
}
}

  • Run the service & access WSDL - http://localhost:8080/services/v1/

Any queries relating this topic, do write comments below & I will help you developing the same

16 views0 comments

Recent Posts

See All

Comments


Modern Digital Watch
bottom of page