Web services 是否可以在WildFly服务器的不同端口上部署单个web应用程序的不同web服务?

Web services 是否可以在WildFly服务器的不同端口上部署单个web应用程序的不同web服务?,web-services,deployment,configuration,wildfly-8,ports,Web Services,Deployment,Configuration,Wildfly 8,Ports,我的问题场景:我有一个JEE7 web应用程序WAR,在两个截然不同的应用程序路径上提供RestEasy JAX-RS web服务(针对不同类型的客户端)。我正在使用WildFly-8.2.0.Final进行部署。一切都很好 问题:我想在WildFly server的单个实例的两个互斥端口上部署两种截然不同的JAX-RS web服务,比如在端口9555上部署类型A_web_服务,在端口10888上部署类型B_web_服务,而在端口80上部署web应用程序(或者可能在8080上)。我不希望TYPE

我的问题场景:我有一个JEE7 web应用程序WAR,在两个截然不同的应用程序路径上提供RestEasy JAX-RS web服务(针对不同类型的客户端)。我正在使用WildFly-8.2.0.Final进行部署。一切都很好


问题:我想在WildFly server的单个实例的两个互斥端口上部署两种截然不同的JAX-RS web服务,比如在端口9555上部署类型A_web_服务,在端口10888上部署类型B_web_服务,而在端口80上部署web应用程序(或者可能在8080上)。我不希望TYPE_A_WEB_服务和TYPE_B_WEB_服务在WEB应用程序的端口80(或可能在8080上)都可用。这种配置在WildFly的单个实例上可行吗?

是的,它包括WildFly在两个http端口上侦听的配置和一些Java EE编程

野蝇配置
  • 为备用端口创建套接字

    <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>
    
    <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>
    
    Endpoint1.java

    Endpoint2.java

    PortDetectionInterceptor.java

     package net.stankay.test;
    
     import javax.ws.rs.ApplicationPath;
     import javax.ws.rs.core.Application;
    
     @ApplicationPath("/rest")
     public class App extends Application {}
    
    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";
        }
    }
    
     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";
        }
     }
    
     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());
            }
        }
     }