Object entity = null;
Object[] args = msg.getBody();
URI uri = URI.create(binding.getURI());
UriBuilder uriBuilder = UriBuilder.fromUri(uri);
Method method = ((JavaOperation)operation).getJavaMethod();
if (method.isAnnotationPresent(Path.class)) {
// Only for resource method
uriBuilder.path(method);
}
if (!JAXRSHelper.isResourceMethod(method)) {
// This is RPC over GET
uriBuilder.replaceQueryParam("method", method.getName());
}
Map<String, Object> pathParams = new HashMap<String, Object>();
Map<String, Object> matrixParams = new HashMap<String, Object>();
Map<String, Object> queryParams = new HashMap<String, Object>();
Map<String, Object> headerParams = new HashMap<String, Object>();
Map<String, Object> formParams = new HashMap<String, Object>();
Map<String, Object> cookieParams = new HashMap<String, Object>();
for (int i = 0; i < method.getParameterTypes().length; i++) {
boolean isEntity = true;
Annotation[] annotations = method.getParameterAnnotations()[i];
PathParam pathParam = getAnnotation(annotations, PathParam.class);
if (pathParam != null) {
isEntity = false;
pathParams.put(pathParam.value(), args[i]);
}
MatrixParam matrixParam = getAnnotation(annotations, MatrixParam.class);
if (matrixParam != null) {
isEntity = false;
matrixParams.put(matrixParam.value(), args[i]);
}
QueryParam queryParam = getAnnotation(annotations, QueryParam.class);
if (queryParam != null) {
isEntity = false;
queryParams.put(queryParam.value(), args[i]);
}
HeaderParam headerParam = getAnnotation(annotations, HeaderParam.class);
if (headerParam != null) {
isEntity = false;
headerParams.put(headerParam.value(), args[i]);
}
FormParam formParam = getAnnotation(annotations, FormParam.class);
if (formParam != null) {
isEntity = false;
formParams.put(formParam.value(), args[i]);
}
CookieParam cookieParam = getAnnotation(annotations, CookieParam.class);
if (cookieParam != null) {
isEntity = false;
cookieParams.put(cookieParam.value(), args[i]);
}
if (isEntity) {
entity = args[i];
}
}
for (Map.Entry<String, Object> p : queryParams.entrySet()) {
uriBuilder.replaceQueryParam(p.getKey(), p.getValue());
}
for (Map.Entry<String, Object> p : matrixParams.entrySet()) {
uriBuilder.replaceMatrixParam(p.getKey(), p.getValue());
}
uri = uriBuilder.buildFromMap(pathParams);
Resource resource = restClient.resource(uri);
for (Map.Entry<String, Object> p : headerParams.entrySet()) {
resource.header(p.getKey(), String.valueOf(p.getValue()));
}