我有一个奇怪的问题,目前无法重现。 我有以下端点:
@Path("/v1/")
@Produces(MediaType.APPLICATION_JSON)
public class EndpointVersion1Base
{
private BackendRestClient restClient;
@EJB
public void setRestClient(BackendRestClient restClient)
{
this.restClient = restClient;
}
@Path("/dataprivacy/")
public Object getDataPrivacy()
{
return new DataPrivacyEndpoint(restClient);
}
@Path("/crashreporting/")
public Object getCrashReport()
{
return new CrashReportEndpoint(restClient);
}
}
端点崩溃报告具有基本身份验证。端点dataprivacy没有身份验证。数据隐私端点如下所示:
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public class DataPrivacyEndpoint
{
private BackendRestClient restClient;
private Logger logger = LoggerFactory.getLogger(getClass());
public DataPrivacyEndpoint(BackendRestClient restClient)
{
this.restClient = restClient;
}
public DataPrivacyEndpoint()
{
}
@POST
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
public Response storeConsent(
@NotNull(message = ErrorCodes.ERR_QUERY_PARAM_NULL) @Valid String consentInputBo) throws ForbiddenException, BadRequestException
{
//some code
}
}
我通过以下web.xml获得了崩溃报告端点的基本身份验证
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>publicapi</display-name>
<security-constraint>
<web-resource-collection>
<web-resource-name>Crash reporting</web-resource-name>
<description>crash reporting service</description>
<url-pattern>/v1/crashreporting/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>publicapi</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>UserRoles simple realm</realm-name>
</login-config>
<security-role>
<role-name>publicapi</role-name>
</security-role>
</web-app>
和jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<context-root>publicapi</context-root>
<security-domain>other</security-domain>
</jboss-web>
昨天所有这些都奏效了。今天,我开始了服务。突然,当我通过 http://192.168.0.80:8080/publicapi/v1/dataprivacy/ 向数据隐私端点发送POST请求时,我收到HTTP错误响应“ 此方法不允许HTTP POST ”。 我想知道为什么会这样,因为它昨天起作用了。重新启动服务后,它突然又恢复正常了?!。这里发生了什么?为什么有时有效,有时却无效? (当前我无法复制它)。我在这里是否有一些配置错误,可能导致某些奇怪的行为?恐怕这也可能在我的LIVE系统上发生。