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;
}
use of javax.ws.rs.core.MultivaluedMap in project cxf by apache.
the class SelectMethodCandidatesTest method doTestProducesResource.
private void doTestProducesResource(Class<?> resourceClass, String path, String acceptContentTypes, String expectedResponseType, String expectedMethodName) throws Exception {
JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
sf.setResourceClasses(resourceClass);
sf.create();
List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
String contentType = "*/*";
Message m = new MessageImpl();
m.put(Message.CONTENT_TYPE, contentType);
Exchange ex = new ExchangeImpl();
ex.setInMessage(m);
m.setExchange(ex);
Endpoint e = mockEndpoint();
ex.put(Endpoint.class, e);
MetadataMap<String, String> values = new MetadataMap<>();
Map<ClassResourceInfo, MultivaluedMap<String, String>> mResources = JAXRSUtils.selectResourceClass(resources, path, m);
OperationResourceInfo ori = JAXRSUtils.findTargetMethod(mResources, m, "GET", values, contentType, sortMediaTypes(acceptContentTypes));
assertNotNull(ori);
assertEquals(expectedMethodName, ori.getMethodToInvoke().getName());
assertEquals(expectedResponseType, m.getExchange().get(Message.CONTENT_TYPE));
}
Aggregations