1

I'm using cxf and spring without web.xml to create a SOAP service. But for our bigIP system to work I need to serve a static HTML page with just the text OK at a given URI. I have tried to use the solution showed in https://stackoverflow.com/a/37276792/10717570 but it doesn't work for me. It just return a 404 error.

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>

Does anyone have any pointers on what I should do? And how I solve this? Thanks :)

1 Answers1

0

We found that Jetty can only have one handler, so we ended up using a ContextHandler adding it programmatically:

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

in the context you can add any servlet you want, we used it to set our webservice and health-check servlet and then set the context in a handler.

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

Hope this help you guys.