use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class ResourceUtils method createConstructorArguments.
public static Object[] createConstructorArguments(Constructor<?> c, Message m, boolean perRequest, Map<Class<?>, Object> contextValues) {
if (m == null) {
m = new MessageImpl();
}
Class<?>[] params = c.getParameterTypes();
Annotation[][] anns = c.getParameterAnnotations();
Type[] genericTypes = c.getGenericParameterTypes();
@SuppressWarnings("unchecked") MultivaluedMap<String, String> templateValues = (MultivaluedMap<String, String>) m.get(URITemplate.TEMPLATE_PARAMETERS);
Object[] values = new Object[params.length];
for (int i = 0; i < params.length; i++) {
if (AnnotationUtils.getAnnotation(anns[i], Context.class) != null) {
Object contextValue = contextValues != null ? contextValues.get(params[i]) : null;
if (contextValue == null) {
if (perRequest || InjectionUtils.VALUE_CONTEXTS.contains(params[i].getName())) {
values[i] = JAXRSUtils.createContextValue(m, genericTypes[i], params[i]);
} else {
values[i] = InjectionUtils.createThreadLocalProxy(params[i]);
}
} else {
values[i] = contextValue;
}
} else {
// this branch won't execute for singletons given that the found constructor
// is guaranteed to have only Context parameters, if any, for singletons
Parameter p = ResourceUtils.getParameter(i, anns[i], params[i]);
values[i] = JAXRSUtils.createHttpParameterValue(p, params[i], genericTypes[i], anns[i], m, templateValues, null);
}
}
return values;
}
use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class ClientProxyImpl method handleForm.
private MultivaluedMap<String, String> handleForm(Method m, Object[] params, MultivaluedMap<ParameterType, Parameter> map, List<Parameter> beanParams) {
MultivaluedMap<String, String> form = new MetadataMap<String, String>();
List<Parameter> fm = getParameters(map, ParameterType.FORM);
for (Parameter p : fm) {
addFormValue(form, p.getName(), params[p.getIndex()], getParamAnnotations(m, p));
}
for (Parameter p : beanParams) {
Map<String, BeanPair> values = getValuesFromBeanParam(params[p.getIndex()], FormParam.class);
for (Map.Entry<String, BeanPair> entry : values.entrySet()) {
addFormValue(form, entry.getKey(), entry.getValue().getValue(), entry.getValue().getAnns());
}
}
return form;
}
use of org.apache.cxf.jaxrs.model.Parameter in project tomee by apache.
the class JAXRSUtils method injectParameters.
@SuppressWarnings("unchecked")
public static void injectParameters(OperationResourceInfo ori, BeanResourceInfo bri, Object requestObject, Message message) {
if (bri.isSingleton() && (!bri.getParameterMethods().isEmpty() || !bri.getParameterFields().isEmpty())) {
LOG.fine("Injecting request parameters into singleton resource is not thread-safe");
}
// Param methods
MultivaluedMap<String, String> values = (MultivaluedMap<String, String>) message.get(URITemplate.TEMPLATE_PARAMETERS);
for (Method m : bri.getParameterMethods()) {
Parameter p = ResourceUtils.getParameter(0, m.getAnnotations(), m.getParameterTypes()[0]);
Object o;
if (p.getType() == ParameterType.BEAN) {
o = createBeanParamValue(message, m.getParameterTypes()[0], ori);
} else {
o = createHttpParameterValue(p, m.getParameterTypes()[0], m.getGenericParameterTypes()[0], m.getParameterAnnotations()[0], message, values, ori);
}
InjectionUtils.injectThroughMethod(requestObject, m, o, message);
}
// Param fields
for (Field f : bri.getParameterFields()) {
Parameter p = ResourceUtils.getParameter(0, f.getAnnotations(), f.getType());
final Object o;
if (p.getType() == ParameterType.BEAN) {
o = createBeanParamValue(message, f.getType(), ori);
} else {
o = createHttpParameterValue(p, f.getType(), f.getGenericType(), f.getAnnotations(), message, values, ori);
}
InjectionUtils.injectFieldValue(f, requestObject, o);
}
}
use of org.apache.cxf.jaxrs.model.Parameter in project tomee by apache.
the class ResourceUtils method getOperationFromElement.
private static UserOperation getOperationFromElement(Element e) {
UserOperation op = new UserOperation();
op.setName(e.getAttribute("name"));
op.setVerb(e.getAttribute("verb"));
op.setPath(e.getAttribute("path"));
op.setOneway(Boolean.parseBoolean(e.getAttribute("oneway")));
op.setConsumes(e.getAttribute("consumes"));
op.setProduces(e.getAttribute("produces"));
List<Element> paramEls = DOMUtils.findAllElementsByTagNameNS(e, "http://cxf.apache.org/jaxrs", "param");
List<Parameter> params = new ArrayList<>(paramEls.size());
for (int i = 0; i < paramEls.size(); i++) {
Element paramEl = paramEls.get(i);
Parameter p = new Parameter(paramEl.getAttribute("type"), i, paramEl.getAttribute("name"));
p.setEncoded(Boolean.valueOf(paramEl.getAttribute("encoded")));
p.setDefaultValue(paramEl.getAttribute("defaultValue"));
String pClass = paramEl.getAttribute("class");
if (!StringUtils.isEmpty(pClass)) {
try {
p.setJavaType(ClassLoaderUtils.loadClass(pClass, ResourceUtils.class));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
params.add(p);
}
op.setParameters(params);
return op;
}
use of org.apache.cxf.jaxrs.model.Parameter in project tomee by apache.
the class ResourceUtils method createConstructorArguments.
public static Object[] createConstructorArguments(Constructor<?> c, Message m, boolean perRequest, Map<Class<?>, Object> contextValues, Class<?>[] params, Annotation[][] anns, Type[] genericTypes) {
if (m == null) {
m = new MessageImpl();
}
@SuppressWarnings("unchecked") MultivaluedMap<String, String> templateValues = (MultivaluedMap<String, String>) m.get(URITemplate.TEMPLATE_PARAMETERS);
Object[] values = new Object[params.length];
for (int i = 0; i < params.length; i++) {
if (AnnotationUtils.getAnnotation(anns[i], Context.class) != null) {
Object contextValue = contextValues != null ? contextValues.get(params[i]) : null;
if (contextValue == null) {
if (perRequest || InjectionUtils.VALUE_CONTEXTS.contains(params[i].getName())) {
values[i] = JAXRSUtils.createContextValue(m, genericTypes[i], params[i]);
} else {
values[i] = InjectionUtils.createThreadLocalProxy(params[i]);
}
} else {
values[i] = contextValue;
}
} else {
// this branch won't execute for singletons given that the found constructor
// is guaranteed to have only Context parameters, if any, for singletons
Parameter p = ResourceUtils.getParameter(i, anns[i], params[i]);
values[i] = JAXRSUtils.createHttpParameterValue(p, params[i], genericTypes[i], anns[i], m, templateValues, null);
}
}
return values;
}
Aggregations