CXF提供静态HTML

问题描述 投票:1回答:1

我正在使用cxf和spring而不使用web.xml来创建SOAP服务。但是为了让我们的bigIP系统工作,我需要提供一个静态HTML页面,其中只有给定URI的文本OK。我试图使用https://stackoverflow.com/a/37276792/10717570中显示的解决方案,但它对我不起作用。它只返回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>

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

java spring cxf jax-ws
1个回答
0
投票

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

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

在上下文中,您可以添加任何所需的servlet,我们使用它来设置我们的webservice和health-check servlet,然后在处理程序中设置上下文。

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

希望这能帮到你们。

© www.soinside.com 2019 - 2024. All rights reserved.