Advertisement
neo7bf

Untitled

May 25th, 2023
1,099
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.67 KB | Source Code | 0 0
  1. package it.codingspace.calculatorws.config;
  2.  
  3. import org.springframework.boot.web.servlet.ServletRegistrationBean;
  4. import org.springframework.context.ApplicationContext;
  5. import org.springframework.context.annotation.Bean;
  6. import org.springframework.context.annotation.Configuration;
  7. import org.springframework.core.io.ClassPathResource;
  8. import org.springframework.ws.config.annotation.EnableWs;
  9. import org.springframework.ws.transport.http.MessageDispatcherServlet;
  10. import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
  11. import org.springframework.xml.xsd.SimpleXsdSchema;
  12. import org.springframework.xml.xsd.XsdSchema;
  13.  
  14. @Configuration
  15. @EnableWs
  16. public class CalculatorwsConfig {
  17.  
  18.     @Bean
  19.     public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet (ApplicationContext context) {
  20.         MessageDispatcherServlet servlet = new MessageDispatcherServlet();
  21.         servlet.setApplicationContext(context);
  22.         servlet.setTransformSchemaLocations(true);
  23.        
  24.         return new ServletRegistrationBean<MessageDispatcherServlet>(servlet, "/ws/*" );
  25.     }
  26.    
  27.     @Bean(name = "calculatorws")
  28.     public DefaultWsdl11Definition defaultWsdl11Definition (XsdSchema schema) {
  29.         DefaultWsdl11Definition wsdl = new DefaultWsdl11Definition();
  30.         wsdl.setPortTypeName("Calculatorws");
  31.         wsdl.setLocationUri("/ws");
  32.         wsdl.setTargetNamespace("http://www.codingspace.it/calculatorws");
  33.         wsdl.setSchema(schema);
  34.         return wsdl;
  35.     }
  36.    
  37.     @Bean
  38.     public XsdSchema xsdSchema () {
  39.         return new SimpleXsdSchema(new ClassPathResource("calculatorws.xsd"));
  40.     }
  41. }
  42.  
  43. //Endpoint
  44.  
  45. package it.codingspace.calculatorws.endpoint;
  46.  
  47. import org.springframework.ws.server.endpoint.annotation.Endpoint;
  48. import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
  49. import org.springframework.ws.server.endpoint.annotation.RequestPayload;
  50. import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
  51.  
  52. import it.codingspace.calculatorws.infra.Add;
  53. import it.codingspace.calculatorws.infra.AddResponse;
  54.  
  55. @Endpoint
  56. public class CalculatorwsEndpoint {
  57.  
  58.     private static final String NAME_SPACE = "http://www.example.org/calculatorws";
  59.  
  60.     @PayloadRoot(namespace = NAME_SPACE, localPart = "Add")
  61.     @ResponsePayload
  62.     public AddResponse addAction(@RequestPayload Add request) {
  63.         AddResponse resp = new AddResponse();
  64.        
  65.         resp.setAddResult(request.getIntA()+request.getIntB());
  66.         return resp;
  67.     }
  68. }
  69.  
  70. //Beans
  71.  
  72. @XmlAccessorType(XmlAccessType.FIELD)
  73. @XmlType(name = "", propOrder = {
  74.     "addResult"
  75. })
  76. @XmlRootElement(name = "AddResponse")
  77. public class AddResponse {
  78.  
  79.     protected int addResult;
  80.  
  81.     /**
  82.      * Recupera il valore della proprietà addResult.
  83.      *
  84.      */
  85.     public int getAddResult() {
  86.         return addResult;
  87.     }
  88.  
  89.     /**
  90.      * Imposta il valore della proprietà addResult.
  91.      *
  92.      */
  93.     public void setAddResult(int value) {
  94.         this.addResult = value;
  95.     }
  96.  
  97. }
  98.  
  99. @XmlAccessorType(XmlAccessType.FIELD)
  100. @XmlType(name = "", propOrder = {
  101.     "intA",
  102.     "intB"
  103. })
  104. @XmlRootElement(name = "Add")
  105. public class Add {
  106.  
  107.     protected int intA;
  108.     protected int intB;
  109.  
  110.     /**
  111.      * Recupera il valore della proprietà intA.
  112.      *
  113.      */
  114.     public int getIntA() {
  115.         return intA;
  116.     }
  117.  
  118.     /**
  119.      * Imposta il valore della proprietà intA.
  120.      *
  121.      */
  122.     public void setIntA(int value) {
  123.         this.intA = value;
  124.     }
  125.  
  126.     /**
  127.      * Recupera il valore della proprietà intB.
  128.      *
  129.      */
  130.     public int getIntB() {
  131.         return intB;
  132.     }
  133.  
  134.     /**
  135.      * Imposta il valore della proprietà intB.
  136.      *
  137.      */
  138.     public void setIntB(int value) {
  139.         this.intB = value;
  140.     }
  141.  
  142. }
  143.  
  144.  
  145.  
  146.  
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement