我有一个非常简单的网络服务,它在Embedded 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服务调用设置root元素:
@ApplicationPath("root")
public class ApplicationConfig extends Application {
}
一切正常,但我想通过SSL保护这个GET方法。 我阅读了以下手册:this和this。我对配置Glassfish部分SSL连接不感兴趣(我知道该怎么做),我只是不想在 localhost:8080 / root / application.wadl 链接中看到我的GET方法(这样会意味着我的Web服务连接到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 中)我的网络服务URL连接到不安全的端口(8080而不是8181)。我尝试了很多其他方法,试图使我的代码正常工作。我根本没有成功。 我把这个网络服务打包成.war。在那之后,这个.war去了.ear。任何想法为什么我没有成功没有看到我的&#34;安全&#34; application.wadl 中的网络服务?