2

我有一个非常简单的网络服务,它在嵌入式 Glassfish 服务器上运行:

@Stateless
@Path("/id")
@Produces(MediaType.TEXT_HTML)
public class SimpleFacadeBean {

    @GET
    public String sayHello(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        return "Hello world!";
    }
}

以及相应的类,为所有 Web 服务调用设置根元素:

@ApplicationPath("root")
public class ApplicationConfig extends Application {
}

一切正常,但我想通过 SSL 保护这个 GET 方法。我已阅读以下手册:thisthis。我对配置 SSL 连接的 Glassfish 部分不感兴趣(我知道怎么做),我只是不想在localhost:8080/root/application.wadl链接中看到我的 GET 方法(这意味着我的网络服务是连接到 8181 安全 glassfish 端口,而不是默认不安全的 8080 端口)。为此,我编写了 web.xml 描述符并将其放在 webapp/WEB-INF 目录中。其中最有趣的部分如下所示:

<security-constraint>   
    <display-name>SecurityConstraint</display-name>   
    <web-resource-collection>   
        <web-resource-name>Secure Area</web-resource-name>   
        <url-pattern>/root/id</url-pattern>               
        <http-method>GET</http-method>   
    </web-resource-collection>             
    <user-data-constraint>   
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>   
    </user-data-constraint>   
</security-constraint>   

但在执行后,我再次看到(在application.wadl中)我的 Web 服务 URL 连接到不安全的端口(8080 而不是 8181)。我尝试了很多其他方法,试图让我的代码正常工作。我一点也不成功。我将此 Web 服务打包到 .war 中。之后,这个 .war 转到 .ear。有什么想法为什么我没有在application.wadl中看到我的“安全”网络服务?

4

0 回答 0