繁体   English   中英

Vaadin 与 Apache CXF SOAP 服务

[英]Vaadin with Apache CXF SOAP service

我是 Vaadin 的新手,刚刚在 Vaadin web 站点中生成了应用程序并在本地构建了它。 Then I added Apache CXF SOAP service to it, but I am unable to use the Tomcat that Vaadin is using, but instead I load SOAP in Jetty using:

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http-jetty</artifactId>
    <version>${cxf.version}</version>
    <scope>compile</scope>
</dependency>

我的 Vaadin 应用程序是:

@SpringBootApplication
@Theme(value = "iciclient", variant = Lumo.DARK)
@PWA(name = "ICI Client", shortName = "ICI Client", offlineResources = {"images/logo.png"})
public class Application extends SpringBootServletInitializer implements AppShellConfigurator {

    public static void main(String[] args) {
        LaunchUtil.launchBrowserInDevelopmentMode(SpringApplication.run(Application.class, args));
        try {
            System.out.println("Starting IciEventClient");
            Object implementor = new IciEventServiceSoap12Impl();
            String address = "http://localhost:8081/ici/IciEventService";
            Endpoint.publish(address, implementor);
            // http://localhost:8081/ici/IciEventService?WSDL
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

虽然这可行,但我想摆脱单独的 Jetty 依赖并在 Vaadin Tomcat (localhost:8080) 中运行 SOAP 服务。 应该很简单,但我不知道该怎么做。 我认为它需要一个单独的 servlet 和路由,但我不知道如何添加它们。 例如,在 Vaadin 应用程序中没有 web.xml。

我不熟悉 Apache CXF,但基于CXF 文档示例项目,我认为我可以使用它。

我从 start.vaadin.com 下载了一个新的 Vaadin 14/Java 8 项目,并执行了以下操作:

  1. 添加了依赖

    <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>3.4.3</version> </dependency>
  2. 创建了一个 web 服务

    import javax.jws.WebMethod; import javax.jws.WebService; @WebService public class Test { @WebMethod public String test() { return "This works"; } }
  3. 在我的Application class 中将其作为 bean 公开

    import javax.xml.ws.Endpoint; import org.apache.cxf.Bus; import org.apache.cxf.jaxws.EndpointImpl; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.Bean; import org.vaadin.artur.helpers.LaunchUtil; import org.vaadin.erik.endpoint.Test; @SpringBootApplication public class Application extends SpringBootServletInitializer { public static void main(String[] args) { LaunchUtil.launchBrowserInDevelopmentMode(SpringApplication.run(Application.class, args)); } @Bean public Endpoint test(Bus bus) { EndpointImpl endpoint = new EndpointImpl(bus, new Test()); endpoint.publish("/Test"); return endpoint; } }

就是这样! 至少我现在可以在 http://localhost:8080/services/Test?wsdl 列出服务定义

第一个文档链接列出了您可以执行的一些配置,例如更改/services路径。 如果需要,示例项目显示了如何配置 Spring 执行器指标。

您可能希望为您的所有服务@Bean定义创建一个单独的@Configuration -annotated class。

如果您不想使用 starter 依赖项,这篇 Baeldung 文章看起来很有希望。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM