in gui/jaxrs/jaxrs-client/src/main/java/org/apache/batchee/jaxrs/client/BatchEEJAXRS2Client.java [101:150]
protected Response doInvoke(final Method jaxrsMethod, final Method method, final Object[] args) {
final Map<String, Object> templates = new HashMap<String, Object>();
final Map<String, Object> queryParams = new HashMap<String, Object>();
Object body = null;
if (args != null) {
final Class<?>[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length == 1 && JobInstance.class.equals(parameterTypes[0])) { // getJobExecutions
final JobInstance ji = JobInstance.class.cast(args[0]);
templates.put("id", ji.getInstanceId());
templates.put("name", ji.getJobName());
} else {
final Annotation[][] parameterAnnotations = jaxrsMethod.getParameterAnnotations();
for (int i = 0; i < parameterAnnotations.length; i++) {
final Class<?> type = method.getParameterTypes()[i];
boolean found = false;
for (final Annotation a : parameterAnnotations[i]) {
final Class<? extends Annotation> at = a.annotationType();
if (PathParam.class.equals(at)) {
templates.put(PathParam.class.cast(a).value(), convertParam(args[i], type));
found = true;
} else if (QueryParam.class.equals(at)) {
queryParams.put(QueryParam.class.cast(a).value(), convertParam(args[i], type));
found = true;
}
}
if (!found) {
body = convertParam(args[i], type);
}
}
}
}
WebTarget resolvedTarget = target.path(jaxrsMethod.getAnnotation(Path.class).value());
for (final Map.Entry<String, Object> qp : queryParams.entrySet()) {
resolvedTarget = resolvedTarget.queryParam(qp.getKey(), qp.getValue());
}
final Invocation.Builder request = resolvedTarget.resolveTemplates(templates).request(findType(method.getReturnType()));
if (jaxrsMethod.getAnnotation(GET.class) != null) {
return request.get();
} else if (jaxrsMethod.getAnnotation(HEAD.class) != null) {
return request.head();
} else if (jaxrsMethod.getAnnotation(POST.class) != null) {
return request.post(Entity.entity(body, MediaType.APPLICATION_JSON_TYPE));
}
throw new IllegalArgumentException("Unexpected http method");
}