CXF 服务静态 html

CXF serve static html

我正在使用没有 web.xml 的 cxf 和 spring 创建 SOAP 服务。但是为了让我们的 bigIP 系统正常工作,我需要提供一个静态 HTML 页面,在给定的 URI 上只包含文本 OK。 我尝试使用 中显示的解决方案,但它对我不起作用。它只是 return 一个 404 错误。

public class ClasspathResourceResolver {
private String resourceLocation;

private static final Logger LOG = LoggerFactory.getLogger(SFWebPort.class.getName());

public String getPath() {
    if (!StringUtils.isEmpty(resourceLocation)) {
        try {
            Path currentRelativePath = Paths.get("");
            String s = currentRelativePath.toAbsolutePath().toString();
            LOG.debug("Current relative path is: " + s);

            String ret = new ClassPathResource(resourceLocation).getFile().getCanonicalPath();

            LOG.debug("returning: " + ret);

            return ret;
        }
        catch (Exception e) {
            LOG.warn("Unable to resolve classpath as canonical path", e);
        }
    }
    return null;
}

public void setResourceLocation(String resourceLocation) {
    this.resourceLocation = resourceLocation;

}

    <bean name="contextHandler" class="org.eclipse.jetty.server.handler.ContextHandler">
    <property name="contextPath" value="/sentralforskrivning/hsjekk"/>
    <property name="handler" ref="resourceHandler"/>
</bean>

<bean id="resourceHandler" class="org.eclipse.jetty.server.handler.ResourceHandler">
    <property name="resourceBase" value="#{classpathResourceResolver.path}"/>
    <property name="directoriesListed" value="true"/>
</bean>

<bean id="classpathResourceResolver" class="com.webservice.sf.ClasspathResourceResolver">
    <property name="resourceLocation" value="hsjekk.html"/>
</bean>

<jaxws:endpoint id="sfEndpoint"
                bus="cxf"
                implementor="com.webservice.sf.sfWebPort"                
                address="http://localhost:${sfm.port}/sf/sfWebServiceSoapHttpPort">
    <jaxws:inInterceptors>
        <ref bean="jwtInInterceptor"/>
    </jaxws:inInterceptors>
</jaxws:endpoint>

有没有人对我应该做什么有任何指示? 我如何解决这个问题? 谢谢:)

我们发现 Jetty 只能有一个处理程序,所以我们最终使用 ContextHandler 以编程方式添加它:

Server server = new Server(8896);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");

在上下文中你可以添加任何你想要的 servlet,我们用它来设置我们的网络服务和健康检查 servlet,然后在处理程序中设置上下文。

ContextHandlerCollection handlers = new ContextHandlerCollection();
    handlers.setHandlers(new Handler[] {context, new DefaultHandler()});
    server.setHandler(handlers);
    server.start();
    System.out.println("Server ready...");
    server.join();

希望对大家有所帮助。