Reputation: 1803
I'm currently trying to setup my first Java-EE (JDK8) Application and can't get the overriding of the Context Root to work with the @ApplicationPath
annotation.
The Application server in use is Wildfly 16.0.0.Final and I'm trying to use Resteasy as JAX-RS implementation.
Since I'm using gradle to deploy my application as a war this are my dependencies: ( It's a mess and I'm trying to figure out what I really need and what not, advices always welcome )
dependencies {
compileOnly 'org.jboss.logging:jboss-logging:3.3.0.Final'
compileOnly 'org.apache.logging.log4j:log4j-api:2.8.2'
compileOnly 'org.eclipse.persistence:javax.persistence:2.1.0'
compileOnly 'javax.inject:javax.inject:1'
compileOnly 'javax.transaction:javax.transaction-api:1.2'
compileOnly 'javax.enterprise:cdi-api:2.0'
compileOnly 'org.hibernate:hibernate-core:5.4.2.Final'
compileOnly 'org.hibernate:hibernate-envers:5.4.2.Final'
compileOnly 'com.fasterxml.jackson.core:jackson-core:2.9.8'
compileOnly 'com.fasterxml.jackson.core:jackson-annotations:2.9.8'
compileOnly 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
compileOnly 'javax.servlet:javax.servlet-api:3.1.0'
compile group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.6.3.Final'
compile group: 'org.jboss.resteasy', name: 'jaxrs-api', version: '3.0.12.Final'
}
I verified that wildfly is using an adequate version of resteasy and it is also using 3.6.3.
My Application config looks like this:
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
@ApplicationPath("rest/*")
public class ApplicationConfig extends Application {
// Intentionally empty. Just used to configure the application path for wildfly
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> s = new HashSet<>();
s.add(HelloWorldController.class);
return s;
}
}
Now I am currently able to successfully deploy my application but the context root is still being set to the name of my war file like this:
18:39:47,586 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 85) WFLYUT0021: Registered web context: '/Rest-Test-1.0' for server 'default-server'
When accessing the URL with the war name I can see my log entry of my WebFilter, but The filter is also not being able to correctly perform the chain in addressing it to the correct Class with a matching @Path
annotation.(Might this also be a Problem with CDI?)
Update 1: Changing the @ApplicationPath to "/rest" or "rest" doesn't change the context root registration either. It still takes the war name as context root.
TL;DR:
Why is my @ApplicationPath
annotation being ignored and why is my webfilter not being able to chain the request because of that?
Solution:
This removed the warning WELD-000167: Class org.jboss.resteasy.core.AsynchronousDispatcher is annotated with @RequestScoped but it does not declare an appropriate constructor therefore is not registered as a bean!
This made my URI register correctly as root and enabled for the WebFilter to perform the correct chain, since it now can distinct from each component in the URI.
With the jboss-web.xml like this:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web version="10.0"
xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_10_0.xsd">
<context-root>/api</context-root>
<security-domain>other</security-domain> <!-- Configure to the security domain used for your deployed application -->
<server-instance>default-server</server-instance>
<virtual-host>default-host</virtual-host>
</jboss-web>
I was able to override the context root to a much more beautiful one.
If your IDE states an error for the server-instance element you can ignore it, it will still work correctly.
Upvotes: 4
Views: 2404
Reputation: 1803
Before posting my solution I first want to credit ogulcan and Sebastian S, since the help of both made me find the correct solution.
Solution:
This removed the warning WELD-000167: Class org.jboss.resteasy.core.AsynchronousDispatcher is annotated with @RequestScoped but it does not declare an appropriate constructor therefore is not registered as a bean!
This made my URI register correctly as root and enabled for the WebFilter to perform the correct chain, since it now can distinct from each component in the URI.
With the jboss-web.xml like this:
http://www.jboss.org/j2ee/schema/jboss-web_10_0.xsd">
<context-root>/api</context-root>
<security-domain>other</security-domain> <!-- Configure to the security domain used for your deployed application -->
<server-instance>default-server</server-instance>
<virtual-host>default-host</virtual-host>
I was able to override the context root to a much more beautiful one.
If your IDE states an error for the server-instance element you can ignore it, it will still work correctly.
Upvotes: 2