I wonder if it is as hard as I currently try to achieve it. I use Some Interceptor for security in my RESTEasy application. The interceptor implements javax.ws.rs.container.ContainerRequestFilter
.
I use such a code to access request data:
if (((PostMatchContainerRequestContext) requestContext).getHttpRequest().getHttpMethod().equals("GET")) {
requestedId = Long.parseLong(requestContext.getUriInfo().getQueryParameters().get("id").get(0));
} else {
postDataMap = getPostData(requestContext);
}
and
private LinkedHashMap getPostData(ContainerRequestContext requestContext) {
Object obj = null;
try {
String result = IOUtils.toString(requestContext.getEntityStream());
ObjectMapper mapper = new ObjectMapper();
obj = mapper.readValue(result, Object.class);
System.out.println(obj);
} catch (IOException e) {
e.printStackTrace();
}
return (LinkedHashMap) obj;
}
But it seams ridiculous to access request data in such a way. Now I wanted to access DELETE-Request
data but couldn't find any solution. Is there a much proper way to achieve what I am currently doing?
By intercepting you mean to check data before it goes to the rest layer? I have achieved this with implementing Filter interface ( https://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/Filter.html ).
Hope it helps. Br, Dusan
您可以在标头中设置安全信息,获取如下值:
String logintoken = crc.getHeaderString("token");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.