springbootsoap:如何将@webservice初始化到springboot应用程序中?

tyg4sfes  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(473)

我正在将一个web服务迁移到SpringBoot中。从wsdl我可以生成以下接口

  1. @WebService(targetNamespace = "http://tsb.hcl.com/terp/ws/v2", name = "Terp-v2")
  2. @XmlSeeAlso({com.hcl.psi.tsb.schema.common.ObjectFactory.class, com.hcl.psi.tsb.schema.offering.ObjectFactory.class, com.hcl.psi.kil.system.message.ObjectFactory.class, com.hcl.tsb.terp.ws.schema.ObjectFactory.class, com.hcl.psi.tsb.schema.task.ObjectFactory.class, com.hcl.psi.tsb.schema.servicecontract.ObjectFactory.class, com.hcl.psi.tsb.schema.project.ObjectFactory.class, com.hcl.tsb.tsb.ObjectFactory.class, com.hcl.psi.tsb.schema.customer.ObjectFactory.class})
  3. @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
  4. public interface TerpV2 {
  5. @WebMethod(operationName = "GetServiceContracts")
  6. @WebResult(name = "GetServiceContractsResponseType", targetNamespace = "http://tsb.hcl.com/terp/ws/schema", partName = "payload")
  7. public com.hcl.tsb.terp.ws.schema.GetServiceContractsResponseType getServiceContracts(
  8. @WebParam(partName = "payload", name = "GetServiceContractsType", targetNamespace = "http://tsb.hcl.com/terp/ws/schema")
  9. com.hcl.tsb.terp.ws.schema.GetServiceContractsType payload
  10. ) throws TerpServiceFault;

我不知道如何启动它在 Spring 启动申请表百东网站。我尝试实现以下代码:

  1. @EnableWs
  2. @Configuration
  3. public class WebServiceConfig extends WsConfigurerAdapter {
  4. @Bean
  5. public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
  6. MessageDispatcherServlet servlet = new MessageDispatcherServlet();
  7. servlet.setApplicationContext(applicationContext);
  8. servlet.setTransformWsdlLocations(true);
  9. return new ServletRegistrationBean(servlet, "/ws/*");
  10. }
  11. @Bean(name = "TerpService")
  12. public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
  13. DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
  14. wsdl11Definition.setPortTypeName("Terp-v2");
  15. wsdl11Definition.setLocationUri("/tsb/tone/ws/v2/TerpService/");
  16. wsdl11Definition.setTargetNamespace("http://www.baeldung.com/springsoap/gen");
  17. wsdl11Definition.setSchema(countriesSchema);
  18. return wsdl11Definition;
  19. }
  20. @Bean
  21. public XsdSchema countriesSchema() {
  22. return new SimpleXsdSchema(new ClassPathResource("countries.xsd"));
  23. }
  24. }

但我不知道如何启动上面的接口或者它的实现到spring引导上下文中?
我需要手动编写整个合同类吗?
有人能给我提供同样的指导吗。谢谢

falq053o

falq053o1#

我有一个类似的项目,它的工作。
尝试制作界面而不是

  1. @WebService(targetNamespace = "http://tsb.hcl.com/terp/ws/v2", name = "Terp-v2")
  2. @XmlSeeAlso({com.hcl.psi.tsb.schema.common.ObjectFactory.class, com.hcl.psi.tsb.schema.offering.ObjectFactory.class, com.hcl.psi.kil.system.message.ObjectFactory.class, com.hcl.tsb.terp.ws.schema.ObjectFactory.class, com.hcl.psi.tsb.schema.task.ObjectFactory.class, com.hcl.psi.tsb.schema.servicecontract.ObjectFactory.class, com.hcl.psi.tsb.schema.project.ObjectFactory.class, com.hcl.tsb.tsb.ObjectFactory.class, com.hcl.psi.tsb.schema.customer.ObjectFactory.class})
  3. @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
  4. public interface TerpV2 {
  5. @WebMethod(operationName = "GetServiceContracts")
  6. @WebResult(name = "GetServiceContractsResponseType", targetNamespace = "http://tsb.hcl.com/terp/ws/schema", partName = "payload")
  7. public com.hcl.tsb.terp.ws.schema.GetServiceContractsResponseType getServiceContracts(
  8. @WebParam(partName = "payload", name = "GetServiceContractsType", targetNamespace = "http://tsb.hcl.com/terp/ws/schema")
  9. com.hcl.tsb.terp.ws.schema.GetServiceContractsType payload
  10. ) throws TerpServiceFault;

这样地

  1. @Endpoint
  2. public class TerpV2 {
  3. private static final String NAMESPACE_URI = "Terp-v2";
  4. @PayloadRoot(namespace = NAMESPACE_URI, localPart = "GetServiceContractsType")
  5. @ResponsePayload
  6. public YourCustomResponseObject getServiceContracts(@RequestPayload GetServiceContractsType getServiceContractsType) {
  7. //this could be constructed in a service class
  8. YourCustomResponseObject response = new YourCustomResponseObject();
  9. return response;
  10. }

在您的配置中也是如此

  1. wsdl11Definition.setTargetNamespace("Terp-v2");

另外,在pom.xml中,按照以下方式配置构建

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.springframework.boot</groupId>
  5. <artifactId>spring-boot-maven-plugin</artifactId>
  6. <!-- Configuration excecutable=true i have added this to make the jar excecutable-->
  7. <configuration>
  8. <executable>true</executable>
  9. </configuration>
  10. <executions>
  11. <execution>
  12. <phase>install</phase>
  13. <goals>
  14. <goal>repackage</goal>
  15. </goals>
  16. <configuration>
  17. <!-- Configuration classifier=exec i have added this to force maven create one Fat
  18. excecutable jar but also another jar for the dependencies of the payload modules-->
  19. <!-- <classifier>exec</classifier>-->
  20. </configuration>
  21. </execution>
  22. </executions>
  23. </plugin>
  24. <plugin>
  25. <groupId>org.codehaus.mojo</groupId>
  26. <artifactId>jaxb2-maven-plugin</artifactId>
  27. <version>2.3</version>
  28. <executions>
  29. <execution>
  30. <id>xjc</id>
  31. <goals>
  32. <goal>xjc</goal>
  33. </goals>
  34. </execution>
  35. </executions>
  36. <configuration>
  37. <sources>
  38. <source>src/main/resources/countries.xsd</source>
  39. </sources>
  40. </configuration>
  41. </plugin>
  42. </plugins>
  43. </build>

在构建项目之后,它将编译xsd,并在target中生成一些dto类。这些dto类可以复制到项目中,并像实际的dto一样使用它们。这是将xsd转换为dto以供springboot使用的简单方法。
为此,必须在pom.xml中添加以下依赖项

  1. <dependency>
  2. <groupId>wsdl4j</groupId>
  3. <artifactId>wsdl4j</artifactId>
  4. </dependency>
展开查看全部

相关问题