有没有办法在500错误的情况下获取REST WS PUT请求中收到的原始JSON对象?
这是我的WS界面:
public interface VehicleConnectedMileageApi {
public Response updateConnectedVehiclemileage(@ApiParam(value = "vehicle" ,required=true ) Vehicle vehicle)
throws NotFoundException;
}
在我的application-context xml文件中,我使用以下命令来定义WS:
<!-- For VehicleConnectedMileage -->
<jaxrs:server id="VehicleConnectedMileageREST" address="/mileageManagement">
<jaxrs:serviceBeans>
<ref bean="VehicleConnectedMileageApiImpl" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="com.europcar.gwy.fleet.utils.error.RuntimeExceptionMapperHandler" />
<bean class="com.europcar.gwy.fleet.utils.error.MappingDataExceptionMapper" />
<bean id="jacksonObjectMapperProvider" class="com.europcar.gwy.fleet.utils.providers.JacksonObjectMapperProvider" />
<bean id="dateParameterConverterProvider" class="com.europcar.gwy.fleet.utils.providers.DateParamConverterProvider" />
<bean id="jacksonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
</jaxrs:providers>
</jaxrs:server>
但是在上面的那些提供者和映射器中,无法访问第一次收到的Vehicle对象。
这是使用的RuntimeExceptionMapper的一个示例:
@Provider
public class RuntimeExceptionMapperHandler implements ExceptionMapper<Exception>{
/** The invalid Data id. */
private String INTERNAL_SERVER_ERROR_ID = ""; // TODO which error Id
private String INTERNAL_SERVER_ERROR_MSG = ""; // TODO which error message
/** The invalid data or content desc. */
private String INTERNAL_SERVER_ERROR_DESC = "An error has occurred during the processing of your request"; // TODO which error desc
/* (non-Javadoc)
* @see javax.ws.rs.ext.ExceptionMapper#toResponse(java.lang.Throwable)
*/
@SuppressWarnings("unchecked")
@Override
public Response toResponse(Exception pEx) {
return ErrorResponseBuilder.prepareInternalServerErrorRequestResponse(INTERNAL_SERVER_ERROR_ID, INTERNAL_SERVER_ERROR_DESC,INTERNAL_SERVER_ERROR_MSG).build();
}
}
但在这里,没有办法让车辆首先收到
请帮忙!
答案 0 :(得分:0)
您可以创建一个简单的ContainerRequestFilter
并包含在您的提供商中。在过滤方法中,您可以获得请求。
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.ext.Provider;
@Provider
public class RequestInterceptor implements ContainerRequestFilter
{
@Override
public void filter(ContainerRequestContext requestContext) throws IOException
{
System.out.println("Filter executed.");
}
}