Yes, it is possible and it includes configuration of WildFly to listen on two http ports and a bit of Java EE programming.
Wildfly configuration
Create socket for alternative port
<socket-binding-group ...>
...
<socket-binding name="http" port="${jboss.http.port:8080}"/>
<!-- add this one -->
<socket-binding name="http-alternative" port="${jboss.http.port:8888}"/>
...
</socket-binding-group>
Define http-listener on alternative port
<subsystem xmlns="urn:jboss:domain:undertow:1.2">
...
<server name="default-server">
<http-listener name="default" socket-binding="http"/>
<!-- add this one -->
<http-listener name="http-alt" socket-binding="http-alternative"/>
...
</server>
</subsystem>
Check ports in JAX-RS
For this I used Java EE @Interceptors. I defined 2 endpoints (Endpoint1, Endpoint2) within one application App. Every invocation of methods of endpoints is intercepted by PortDetectionInterceptor which checks if the endpoint is called from predefined ports.
App.java
package net.stankay.test;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/rest")
public class App extends Application {}
Endpoint1.java
package net.stankay.test;
import javax.interceptor.Interceptors;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Interceptors(PortDetectionInterceptor.class)
@Path("/endpoint1")
public class Endpoint1 {
@GET
public String hi() {
return "hi";
}
}
Endpoint2.java
package net.stankay.test;
import javax.interceptor.Interceptors;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Interceptors(PortDetectionInterceptor.class)
@Path("/endpoint2")
public class Endpoint2 {
@GET
public String hello() {
return "hello";
}
}
PortDetectionInterceptor.java
package net.stankay.test;
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import javax.servlet.http.HttpServletRequest;
public class PortDetectionInterceptor {
@Inject
private HttpServletRequest httpRequest;
@AroundInvoke
public Object detectPort(InvocationContext ctx) throws Exception {
try {
String restEndpoint = ctx.getTarget().getClass().getName();
int restPort = httpRequest.getLocalPort();
if (restEndpoint.contains("Endpoint1") && restPort != 8080) {
throw new RuntimeException("Please access Endpoint1 only via port 8080");
}
if (restEndpoint.contains("Endpoint2") && restPort != 8888) {
throw new RuntimeException("Please access Endpoint2 only via port 8888");
}
return ctx.proceed();
} catch (Exception e) {
return String.format("{ \"error\" : \"%s\" }", e.getMessage());
}
}
}