use of org.apache.cxf.jaxrs.model.ParameterType in project tomee by apache.
the class InjectionUtils method injectIntoMap.
private static Object injectIntoMap(Type genericType, Annotation[] paramAnns, MultivaluedMap<String, String> processedValues, boolean decoded, ParameterType pathParam, Message message) {
ParameterizedType paramType = (ParameterizedType) genericType;
Class<?> keyType = (Class<?>) paramType.getActualTypeArguments()[0];
Type secondType = InjectionUtils.getType(paramType.getActualTypeArguments(), 1);
if (secondType instanceof ParameterizedType) {
MultivaluedMap<Object, Object> theValues = new MetadataMap<>();
ParameterizedType valueParamType = (ParameterizedType) secondType;
Class<?> valueType = (Class<?>) InjectionUtils.getType(valueParamType.getActualTypeArguments(), 0);
for (Map.Entry<String, List<String>> processedValuesEntry : processedValues.entrySet()) {
List<String> valuesList = processedValuesEntry.getValue();
for (String value : valuesList) {
Object o = InjectionUtils.handleParameter(value, decoded, valueType, valueType, paramAnns, pathParam, message);
theValues.add(convertStringToPrimitive(processedValuesEntry.getKey(), keyType), o);
}
}
return theValues;
}
Map<Object, Object> theValues = new HashMap<>();
Class<?> valueType = (Class<?>) InjectionUtils.getType(paramType.getActualTypeArguments(), 1);
for (Map.Entry<String, List<String>> processedValuesEntry : processedValues.entrySet()) {
List<String> valuesList = processedValuesEntry.getValue();
for (String value : valuesList) {
Object o = InjectionUtils.handleParameter(value, decoded, valueType, valueType, paramAnns, pathParam, message);
theValues.put(convertStringToPrimitive(processedValuesEntry.getKey(), keyType), o);
}
}
return theValues;
}
use of org.apache.cxf.jaxrs.model.ParameterType in project cxf by apache.
the class WadlGenerator method doWriteJaxrsBeanParam.
private void doWriteJaxrsBeanParam(StringBuilder sb, OperationResourceInfo ori, Class<?> beanType, boolean isJson, ParameterType... parameterTypes) {
for (Method m : beanType.getMethods()) {
if (m.getName().startsWith("set")) {
String propertyName = StringUtils.uncapitalize(m.getName().substring(3));
Field f = InjectionUtils.getDeclaredField(beanType, propertyName);
for (ParameterType parameterType : parameterTypes) {
Class<? extends Annotation> annClass = getAnnotationFromParamType(parameterType);
Annotation annotation = m.getAnnotation(annClass);
if (annotation != null) {
Parameter pm = new Parameter(parameterType, propertyName);
pm.setEncoded(m.getAnnotation(Encoded.class) != null);
DefaultValue dv = m.getAnnotation(DefaultValue.class);
if (dv != null) {
pm.setDefaultValue(dv.value());
}
doWriteParam(ori, sb, pm, m.getParameterTypes()[0], m.getGenericParameterTypes()[0], propertyName, new Annotation[] {}, isJson);
} else if (f != null) {
annotation = f.getAnnotation(annClass);
if (annotation != null) {
Parameter pm = new Parameter(parameterType, propertyName);
pm.setEncoded(f.getAnnotation(Encoded.class) != null);
DefaultValue dv = f.getAnnotation(DefaultValue.class);
if (dv != null) {
pm.setDefaultValue(dv.value());
}
doWriteParam(ori, sb, pm, f.getType(), f.getGenericType(), propertyName, new Annotation[] {}, isJson);
}
}
}
if (m.getAnnotation(BeanParam.class) != null) {
doWriteJaxrsBeanParam(sb, ori, m.getParameterTypes()[0], isJson, parameterTypes);
} else if (f != null && f.getAnnotation(BeanParam.class) != null) {
doWriteJaxrsBeanParam(sb, ori, f.getType(), isJson, parameterTypes);
}
}
}
}
use of org.apache.cxf.jaxrs.model.ParameterType in project cxf by apache.
the class ClientProxyImpl method invoke.
/**
* Updates the current state if Client method is invoked, otherwise
* does the remote invocation or returns a new proxy if subresource
* method is invoked. Can throw an expected exception if ResponseExceptionMapper
* is registered
*/
@Override
public Object invoke(Object o, Method m, Object[] params) throws Throwable {
checkClosed();
Class<?> declaringClass = m.getDeclaringClass();
if (Client.class == declaringClass || InvocationHandlerAware.class == declaringClass || Object.class == declaringClass || Closeable.class == declaringClass || AutoCloseable.class == declaringClass) {
return m.invoke(this, params);
}
resetResponse();
OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(m);
if (ori == null) {
if (m.isDefault()) {
return invokeDefaultMethod(declaringClass, o, m, params);
}
reportInvalidResourceMethod(m, "INVALID_RESOURCE_METHOD");
}
MultivaluedMap<ParameterType, Parameter> types = getParametersInfo(m, params, ori);
List<Parameter> beanParamsList = getParameters(types, ParameterType.BEAN);
int bodyIndex = getBodyIndex(types, ori);
List<Object> pathParams = getPathParamValues(m, params, types, beanParamsList, ori, bodyIndex);
UriBuilder builder = getCurrentBuilder().clone();
if (isRoot) {
addNonEmptyPath(builder, ori.getClassResourceInfo().getURITemplate().getValue());
}
addNonEmptyPath(builder, ori.getURITemplate().getValue());
handleMatrixes(m, params, types, beanParamsList, builder);
handleQueries(m, params, types, beanParamsList, builder);
URI uri = builder.buildFromEncoded(pathParams.toArray()).normalize();
MultivaluedMap<String, String> headers = getHeaders();
MultivaluedMap<String, String> paramHeaders = new MetadataMap<>();
handleHeaders(m, params, paramHeaders, beanParamsList, types);
handleCookies(m, params, paramHeaders, beanParamsList, types);
if (ori.isSubResourceLocator()) {
ClassResourceInfo subCri = cri.getSubResource(m.getReturnType(), m.getReturnType());
if (subCri == null) {
reportInvalidResourceMethod(m, "INVALID_SUBRESOURCE");
}
MultivaluedMap<String, String> subHeaders = paramHeaders;
if (inheritHeaders) {
subHeaders.putAll(headers);
}
ClientState newState = getState().newState(uri, subHeaders, getTemplateParametersMap(ori.getURITemplate(), pathParams));
ClientProxyImpl proxyImpl = new ClientProxyImpl(newState, proxyLoader, subCri, false, inheritHeaders);
proxyImpl.setConfiguration(getConfiguration());
return JAXRSClientFactory.createProxy(m.getReturnType(), proxyLoader, proxyImpl);
}
headers.putAll(paramHeaders);
getState().setTemplates(getTemplateParametersMap(ori.getURITemplate(), pathParams));
Object body = null;
if (bodyIndex != -1) {
body = params[bodyIndex];
if (body == null) {
bodyIndex = -1;
}
} else if (types.containsKey(ParameterType.FORM)) {
body = handleForm(m, params, types, beanParamsList);
} else if (types.containsKey(ParameterType.REQUEST_BODY)) {
body = handleMultipart(types, ori, params);
} else if (hasFormParams(params, beanParamsList)) {
body = handleForm(m, params, types, beanParamsList);
}
setRequestHeaders(headers, ori, types.containsKey(ParameterType.FORM), body == null ? null : body.getClass(), m.getReturnType());
try {
return doChainedInvocation(uri, headers, ori, params, body, bodyIndex, null, null);
} finally {
resetResponseStateImmediatelyIfNeeded();
}
}
use of org.apache.cxf.jaxrs.model.ParameterType in project cxf by apache.
the class ClientProxyImpl method getParametersInfo.
protected MultivaluedMap<ParameterType, Parameter> getParametersInfo(Method m, Object[] params, OperationResourceInfo ori) {
MultivaluedMap<ParameterType, Parameter> map = new MetadataMap<>();
List<Parameter> parameters = ori.getParameters();
if (parameters.isEmpty()) {
return map;
}
int requestBodyParam = 0;
int multipartParam = 0;
for (Parameter p : parameters) {
if (isIgnorableParameter(m, p)) {
continue;
}
if (p.getType() == ParameterType.REQUEST_BODY) {
requestBodyParam++;
if (getMultipart(ori, p.getIndex()) != null) {
multipartParam++;
}
}
map.add(p.getType(), p);
}
if (map.containsKey(ParameterType.REQUEST_BODY)) {
if (requestBodyParam > 1 && requestBodyParam != multipartParam) {
reportInvalidResourceMethod(ori.getMethodToInvoke(), "SINGLE_BODY_ONLY");
}
if (map.containsKey(ParameterType.FORM)) {
reportInvalidResourceMethod(ori.getMethodToInvoke(), "ONLY_FORM_ALLOWED");
}
}
return map;
}
use of org.apache.cxf.jaxrs.model.ParameterType in project cxf by apache.
the class InjectionUtils method injectIntoMap.
// CHECKSTYLE:OFF
private static Object injectIntoMap(Class<?> rawType, Type genericType, Annotation[] paramAnns, MultivaluedMap<String, String> processedValues, boolean decoded, ParameterType pathParam, Message message) {
// CHECKSTYLE:ON
ParameterizedType paramType = (ParameterizedType) genericType;
Class<?> keyType = (Class<?>) paramType.getActualTypeArguments()[0];
Type secondType = InjectionUtils.getType(paramType.getActualTypeArguments(), 1);
if (secondType instanceof ParameterizedType) {
MultivaluedMap<Object, Object> theValues = new MetadataMap<Object, Object>();
ParameterizedType valueParamType = (ParameterizedType) secondType;
Class<?> valueType = (Class<?>) InjectionUtils.getType(valueParamType.getActualTypeArguments(), 0);
for (Map.Entry<String, List<String>> processedValuesEntry : processedValues.entrySet()) {
List<String> valuesList = processedValuesEntry.getValue();
for (String value : valuesList) {
Object o = InjectionUtils.handleParameter(value, decoded, valueType, valueType, paramAnns, pathParam, message);
theValues.add(convertStringToPrimitive(processedValuesEntry.getKey(), keyType), o);
}
}
return theValues;
}
Map<Object, Object> theValues = new HashMap<>();
Class<?> valueType = (Class<?>) InjectionUtils.getType(paramType.getActualTypeArguments(), 1);
for (Map.Entry<String, List<String>> processedValuesEntry : processedValues.entrySet()) {
List<String> valuesList = processedValuesEntry.getValue();
for (String value : valuesList) {
Object o = InjectionUtils.handleParameter(value, decoded, valueType, valueType, paramAnns, pathParam, message);
theValues.put(convertStringToPrimitive(processedValuesEntry.getKey(), keyType), o);
}
}
return theValues;
}
Aggregations