Reputation: 511
I have a REST interface defined as below
public interface UserService {
@GZIP
@POST
Response createUser(@HeaderParam("hostName") String hostName, User user);
}
I want to read two more headers - addToCache
and useCache
. The obvious solution is to add the headers in the above signature.
While that would work for explicit HTTP calls over rest clients, modifying the interface signature breaks the backward compatibility in functional test codebase which already connect to the above service using REST proxy service.
The only way out I see is to pass the two params inside the User
object. Is there another way out?
Upvotes: 0
Views: 304
Reputation: 351
You can inject header params as fields in the implementation class:
public interface UserService {
Response createUser(String hostName, User user);
}
@Path("/userservice")
public class UserServiceRestImpl implements UserService{
@HeaderParam("addToCache")
private String addToCache;
@HeaderParam("useCache")
private String useCache;
@GZIP
@POST
Response createUser(@HeaderParam("hostName") String hostName, User user){
System.out.println(addToCache);
System.out.println(useCache);
}
}
UPDATED: try to disable auto scan and specify the resource explicitly:
<!-- disabled auto scanning
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
-->
<context-param>
<param-name>resteasy.resources</param-name>
<param-value>com.yourpackage.UserServiceRestImpl</param-value>
</context-param>
UPDATED2: Also you can try to inject @Context HttpHeaders instead of @HeaderParam:
private @Context HttpHeaders headers;
...
String addToCache = headers.getHeaderString("addToCache");
Upvotes: 1