【问题标题】:How to set the mappings of a servlet so that it listens on the same path as CXF?如何设置 servlet 的映射,使其侦听与 CXF 相同的路径?
【发布时间】:2020-03-25 14:41:14
【问题描述】:

来自我的 pom 的依赖项:

2.2.5.RELEASE for Spring 3.3.5 用于 CXF

  • spring-boot-starter
  • spring-boot-starter-actuator
  • spring-boot-starter-web
  • spring-boot-devtools
  • spring-boot-configuration-processor
  • spring-boot-starter-tomcat
  • spring-boot-starter-test
  • cxf-spring-boot-starter-jaxws
  • cxf-rt-features-logging

这是在 application.yml 中定义的服务器设置:

server:
 port: 8080
 servlet:
  context-path: /cs

第一个 Servlet 是一个 CXF JAXWS 端点,配置如下:

// https://github.com/apache/cxf

@Bean(name=Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
    return new SpringBus();
}

@Bean
public IFileNetWSSoap documentService() {
    return new DocumentServiceEndpoint();
}

@Bean
public Endpoint endpoint() {
    EndpointImpl endpoint = new EndpointImpl(springBus(), documentService());
    endpoint.setServiceName(fileNetWS().getServiceName());
    endpoint.setWsdlLocation(fileNetWS().getWSDLDocumentLocation().toString());
    endpoint.publish(properties.getDocumentEndpoint());
    Binding binding = endpoint.getBinding();
    ((SOAPBinding)binding).setMTOMEnabled(true);
    return endpoint;
}

目前在这个地址收听:http://localhost:8080/cs/services/document-service_1.0

第二个Servlet是javax.servlet.http.HttpServlet(现在是TomCat):

    @WebServlet(urlPatterns = {"/image-service_1.0"})
    public class ImageServiceEndpoint extends HttpServlet {

    @Autowired
    private BusinessService businessServices;

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) {
        this.businessServices.imageRetrieval(request, response);
    }
}

目前在这个地址收听:http://localhost:8080/cs/image-service_1.0

最后,还有 Spring-Boot Actuator Servlet。

目前在这个地址收听:http://localhost:8080/cs/actuator

我的问题是“如何配置 WebServlet 以在不破坏所有内容的情况下侦听 CXF 段?”例如http://localhost:8080/cs/services/image-service_1.0

我注意到,也许我应该使用 Spring MVC 控制器来代替 Servlet。我对此端点 id 的唯一要求是接收查询字符串参数并将二进制内容流回调用者。

【问题讨论】:

  • 你没有。单个映射适用于单个 servlet,而不适用于多个。
  • @M.Deinum 有什么建议看起来有点相似吗?到目前为止,您的建议已经到位,谢谢。
  • @M.Deinum 想知道我是否可以用 cxf 做到这一点?第二个服务只需能够将查询字符串解析为参数并将图像流回。
  • 为什么要它们相似?它们已经共享上下文路径,其余的它们是不同的端点。我还想知道你为什么要在 servlet 中包装控制器(假设是 @Controller)?这超出了控制器和 Springs 调度程序 servlet 的目的。
  • @M.Deinum 啊,这就是我想听到的。我选择了一个 servlet,因为我最初能够将它映射到一个旧的 .NET aspx 页面。我可以使用 MVC 或 REST 服务,它们也擅长绑定参数。

标签: java spring spring-boot cxf spring-ws


【解决方案1】:

您不能接管与 CXF WS Endpoint 相同的路径(默认:/services)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-21
    • 2011-04-09
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多