我正在使用不带web.xml的cxf和spring创建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>
有人对我应该做什么有任何建议吗? 我该如何解决呢? 谢谢:)
答案 0 :(得分:0)
我们发现Jetty只能有一个处理程序,因此我们最终使用了ContextHandler以编程方式添加它:
Server server = new Server(8896);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
在上下文中,您可以添加所需的任何servlet,我们使用它来设置Web服务和运行状况检查servlet,然后在处理程序中设置上下文。
ContextHandlerCollection handlers = new ContextHandlerCollection();
handlers.setHandlers(new Handler[] {context, new DefaultHandler()});
server.setHandler(handlers);
server.start();
System.out.println("Server ready...");
server.join();
希望对您有帮助。