Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package it.codingspace.calculatorws.config;
- import org.springframework.boot.web.servlet.ServletRegistrationBean;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.core.io.ClassPathResource;
- import org.springframework.ws.config.annotation.EnableWs;
- import org.springframework.ws.transport.http.MessageDispatcherServlet;
- import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
- import org.springframework.xml.xsd.SimpleXsdSchema;
- import org.springframework.xml.xsd.XsdSchema;
- @Configuration
- @EnableWs
- public class CalculatorwsConfig {
- @Bean
- public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet (ApplicationContext context) {
- MessageDispatcherServlet servlet = new MessageDispatcherServlet();
- servlet.setApplicationContext(context);
- servlet.setTransformSchemaLocations(true);
- return new ServletRegistrationBean<MessageDispatcherServlet>(servlet, "/ws/*" );
- }
- @Bean(name = "calculatorws")
- public DefaultWsdl11Definition defaultWsdl11Definition (XsdSchema schema) {
- DefaultWsdl11Definition wsdl = new DefaultWsdl11Definition();
- wsdl.setPortTypeName("Calculatorws");
- wsdl.setLocationUri("/ws");
- wsdl.setTargetNamespace("http://www.codingspace.it/calculatorws");
- wsdl.setSchema(schema);
- return wsdl;
- }
- @Bean
- public XsdSchema xsdSchema () {
- return new SimpleXsdSchema(new ClassPathResource("calculatorws.xsd"));
- }
- }
- //Endpoint
- package it.codingspace.calculatorws.endpoint;
- import org.springframework.ws.server.endpoint.annotation.Endpoint;
- import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
- import org.springframework.ws.server.endpoint.annotation.RequestPayload;
- import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
- import it.codingspace.calculatorws.infra.Add;
- import it.codingspace.calculatorws.infra.AddResponse;
- @Endpoint
- public class CalculatorwsEndpoint {
- private static final String NAME_SPACE = "http://www.example.org/calculatorws";
- @PayloadRoot(namespace = NAME_SPACE, localPart = "Add")
- @ResponsePayload
- public AddResponse addAction(@RequestPayload Add request) {
- AddResponse resp = new AddResponse();
- resp.setAddResult(request.getIntA()+request.getIntB());
- return resp;
- }
- }
- //Beans
- @XmlAccessorType(XmlAccessType.FIELD)
- @XmlType(name = "", propOrder = {
- "addResult"
- })
- @XmlRootElement(name = "AddResponse")
- public class AddResponse {
- protected int addResult;
- /**
- * Recupera il valore della proprietà addResult.
- *
- */
- public int getAddResult() {
- return addResult;
- }
- /**
- * Imposta il valore della proprietà addResult.
- *
- */
- public void setAddResult(int value) {
- this.addResult = value;
- }
- }
- @XmlAccessorType(XmlAccessType.FIELD)
- @XmlType(name = "", propOrder = {
- "intA",
- "intB"
- })
- @XmlRootElement(name = "Add")
- public class Add {
- protected int intA;
- protected int intB;
- /**
- * Recupera il valore della proprietà intA.
- *
- */
- public int getIntA() {
- return intA;
- }
- /**
- * Imposta il valore della proprietà intA.
- *
- */
- public void setIntA(int value) {
- this.intA = value;
- }
- /**
- * Recupera il valore della proprietà intB.
- *
- */
- public int getIntB() {
- return intB;
- }
- /**
- * Imposta il valore della proprietà intB.
- *
- */
- public void setIntB(int value) {
- this.intB = value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement