为 http 和 https 配置 API Jersey
Configure API Jersey for http and https
可以通过 http 和 https 进行一些 API,例如:
localhost:8080/MyWebServices/api/getSomething
和另一个带 https 的 API,例如:
localhost:8443/MyWebServices/api/getB
我的API例子是:
@Path("/getSomething")
@GET
@ManagedAsync
@Produces(MediaType.APPLICATION_JSON)
public void getSomethingA(@Suspended final AsyncResponse response){
....
}
并且在 Tomcat 中,我有连接器端口 ="8080",例如:
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="c:\mkyongkeystore"
keystorePass="password" />
我必须配置 web.xml?或者在哪里?因为有这些特征
如果您的两个连接器都设置正确,您应该能够从端口 8080 和 8443 访问您的 API。
如果您想明确保护应用程序的不同部分,您可以在应用程序的 web.xml
中使用一个或多个安全约束
<security-constraint>
<web-resource-collection>
<web-resource-name>securedapp</web-resource-name>
<url-pattern>/whatever/</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
这将阻止任何非 SSL 请求(匹配 url 模式)访问 Web 应用程序。
可以通过 http 和 https 进行一些 API,例如:
localhost:8080/MyWebServices/api/getSomething
和另一个带 https 的 API,例如:
localhost:8443/MyWebServices/api/getB
我的API例子是:
@Path("/getSomething")
@GET
@ManagedAsync
@Produces(MediaType.APPLICATION_JSON)
public void getSomethingA(@Suspended final AsyncResponse response){
....
}
并且在 Tomcat 中,我有连接器端口 ="8080",例如:
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="c:\mkyongkeystore"
keystorePass="password" />
我必须配置 web.xml?或者在哪里?因为有这些特征
如果您的两个连接器都设置正确,您应该能够从端口 8080 和 8443 访问您的 API。
如果您想明确保护应用程序的不同部分,您可以在应用程序的 web.xml
中使用一个或多个安全约束<security-constraint>
<web-resource-collection>
<web-resource-name>securedapp</web-resource-name>
<url-pattern>/whatever/</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
这将阻止任何非 SSL 请求(匹配 url 模式)访问 Web 应用程序。