I am trying to migrate my application from tomcat to embedded jetty. I have created an entrypoint in web module following some guides (this, this, this and etc...). Resulting file is presented below:
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.webapp.WebAppContext
object EPILauncher extends App {
val server: Server = new Server(8080)
val coolWebApplication = new WebAppContext()
coolWebApplication.setResourceBase("warehouse/src/main/webapp/")
coolWebApplication.setContextPath("/api")
coolWebApplication.setDescriptor("warehouse/src/main/webapp/WEB-INF/web.xml")
coolWebApplication.setParentLoaderPriority(true)
server.start()
System.out.println("Started!")
server.join()
}
I have following servlet declaration in my web.xml
file
<servlet>
<servlet-name>CustomerApplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.xxxx.yyyy.warehouse.web.Root</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
io.swagger.jaxrs.listing,
org.owasp.csrfguard.servlet,
com.xxxx.yyyy.warehouse.resource
</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.scanning.recursive</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>jersey.config.servlet.filter.staticContentRegex</param-name>
<param-value>.*(html|css|js|eot|svg|ttf|woff)</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>CustomerApplication</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Package com.xxxx.yyyy.warehouse.resource
contains implementations, e.g.:
@Singleton
@Path("/settings")
@Api("/settings")
class SettingsResource @Inject()(config: Config) {
@GET
@Path("/version")
@Produces(Array(MediaType.APPLICATION_JSON))
def getBackendVersion(@Context servletContext: ServletContext): Response = {
val manifestStream = servletContext.getResourceAsStream("META-INF/MANIFEST.MF")
val version: String = Option(manifestStream)
.map(Utils.using(_) { is =>
val attrs = new java.util.jar.Manifest(is).getMainAttributes
val version = attrs.getOrDefault(new Attributes.Name("Specification-Version"), "local-version").toString
val build = attrs.getOrDefault(new Attributes.Name("Implementation-Version"), "local-build").toString
s"$version.$build"
}).getOrElse("local-version.local-build")
Response.ok(VersionInfo(version)).build()
}
}
So, when I run my app and navigate to localhost:8080/api/settings/version
, all I see is:
URI: /api/settings/version
STATUS: 404
MESSAGE: Not Found
SERVLET: -
So, I think that I don't understand some concepts properly. Should I explicitly point in my main
method, which servlets I want to use? Can they load automatically from web.xml
file?
Thanks.