use of javax.ws.rs.core.MultivaluedMap in project cxf by apache.
the class RequestDispatcherProvider method setRequestParameters.
protected void setRequestParameters(HttpServletRequestFilter request) {
if (getMessageContext() != null) {
UriInfo ui = getMessageContext().getUriInfo();
MultivaluedMap<String, String> params = ui.getPathParameters();
for (Map.Entry<String, List<String>> entry : params.entrySet()) {
String value = entry.getValue().get(0);
int ind = value.indexOf(';');
if (ind > 0) {
value = value.substring(0, ind);
}
request.setParameter(entry.getKey(), value);
}
List<PathSegment> segments = ui.getPathSegments();
if (!segments.isEmpty()) {
doSetRequestParameters(request, segments.get(segments.size() - 1).getMatrixParameters());
}
doSetRequestParameters(request, ui.getQueryParameters());
request.setParameter(ABSOLUTE_PATH_PARAMETER, ui.getAbsolutePath().toString());
request.setParameter(RELATIVE_PATH_PARAMETER, ui.getPath());
request.setParameter(BASE_PATH_PARAMETER, ui.getBaseUri().toString());
request.setParameter(WEBAPP_BASE_PATH_PARAMETER, (String) getMessageContext().get("http.base.path"));
}
}
use of javax.ws.rs.core.MultivaluedMap in project cxf by apache.
the class XSLTJaxbProvider method createTemplates.
protected Templates createTemplates(Templates templates, Map<String, Object> configuredParams, Map<String, String> outProps) {
if (templates == null) {
if (supportJaxbOnly) {
return null;
}
LOG.severe("No template is available");
throw ExceptionUtils.toInternalServerErrorException(null, null);
}
TemplatesImpl templ = new TemplatesImpl(templates, uriResolver);
MessageContext mc = getContext();
if (mc != null) {
UriInfo ui = mc.getUriInfo();
MultivaluedMap<String, String> params = ui.getPathParameters();
for (Map.Entry<String, List<String>> entry : params.entrySet()) {
String value = entry.getValue().get(0);
int ind = value.indexOf(';');
if (ind > 0) {
value = value.substring(0, ind);
}
templ.setTransformerParameter(entry.getKey(), value);
}
List<PathSegment> segments = ui.getPathSegments();
if (!segments.isEmpty()) {
setTransformParameters(templ, segments.get(segments.size() - 1).getMatrixParameters());
}
setTransformParameters(templ, ui.getQueryParameters());
templ.setTransformerParameter(ABSOLUTE_PATH_PARAMETER, ui.getAbsolutePath().toString());
templ.setTransformerParameter(RELATIVE_PATH_PARAMETER, ui.getPath());
templ.setTransformerParameter(BASE_PATH_PARAMETER, ui.getBaseUri().toString());
if (configuredParams != null) {
for (Map.Entry<String, Object> entry : configuredParams.entrySet()) {
templ.setTransformerParameter(entry.getKey(), entry.getValue());
}
}
}
if (outProps != null) {
templ.setOutProperties(outProps);
}
return templ;
}
use of javax.ws.rs.core.MultivaluedMap in project cxf by apache.
the class InjectionUtils method fillInValuesFromBean.
public static void fillInValuesFromBean(Object bean, String baseName, MultivaluedMap<String, Object> values) {
for (Method m : bean.getClass().getMethods()) {
String methodName = m.getName();
boolean startsFromGet = methodName.startsWith("get");
if ((startsFromGet || isBooleanType(m.getReturnType()) && methodName.startsWith("is")) && m.getParameterTypes().length == 0) {
int minLen = startsFromGet ? 3 : 2;
if (methodName.length() <= minLen) {
continue;
}
String propertyName = StringUtils.uncapitalize(methodName.substring(minLen));
if (baseName.contains(propertyName) || "class".equals(propertyName) || "declaringClass".equals(propertyName)) {
continue;
}
if (!"".equals(baseName)) {
propertyName = baseName + '.' + propertyName;
}
Object value = extractFromMethod(bean, m);
if (value == null) {
continue;
}
if (isPrimitive(value.getClass()) || Date.class.isAssignableFrom(value.getClass())) {
values.putSingle(propertyName, value);
} else if (value.getClass().isEnum()) {
values.putSingle(propertyName, value.toString());
} else if (isSupportedCollectionOrArray(value.getClass())) {
final List<Object> theValues;
if (value.getClass().isArray()) {
theValues = Arrays.asList((Object[]) value);
} else if (value instanceof Set) {
theValues = new ArrayList<>((Set<?>) value);
} else {
theValues = CastUtils.cast((List<?>) value);
}
values.put(propertyName, theValues);
} else if (Map.class.isAssignableFrom(value.getClass())) {
if (isSupportedMap(m.getGenericReturnType())) {
Map<Object, Object> map = CastUtils.cast((Map<?, ?>) value);
for (Map.Entry<Object, Object> entry : map.entrySet()) {
values.add(propertyName + '.' + entry.getKey().toString(), entry.getValue().toString());
}
}
} else {
fillInValuesFromBean(value, propertyName, values);
}
}
}
}
use of javax.ws.rs.core.MultivaluedMap in project cxf 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;
}
use of javax.ws.rs.core.MultivaluedMap in project cxf by apache.
the class SelectMethodCandidatesTest method findTargetResourceClass.
// CHECKSTYLE:OFF
private OperationResourceInfo findTargetResourceClass(List<ClassResourceInfo> resources, Message message, String path, String httpMethod, MultivaluedMap<String, String> values, String requestContentType, List<MediaType> acceptContentTypes, boolean setKeepSubProp) {
// CHECKSTYLE:ON
message = message == null ? new MessageImpl() : message;
Map<ClassResourceInfo, MultivaluedMap<String, String>> mResources = JAXRSUtils.selectResourceClass(resources, path, message);
if (mResources != null) {
OperationResourceInfo ori = JAXRSUtils.findTargetMethod(mResources, createMessage(setKeepSubProp), httpMethod, values, requestContentType, acceptContentTypes);
if (ori != null) {
return ori;
}
}
return null;
}
Aggregations