use of org.apache.cxf.jaxrs.impl.MetadataMap 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
*/
public Object invoke(Object o, Method m, Object[] params) throws Throwable {
Class<?> declaringClass = m.getDeclaringClass();
if (Client.class == declaringClass || InvocationHandlerAware.class == declaringClass || Object.class == declaringClass) {
return m.invoke(this, params);
}
resetResponse();
OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(m);
if (ori == null) {
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<String, String>();
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);
}
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.impl.MetadataMap in project cxf by apache.
the class WadlGenerator method getResourcesList.
public List<ClassResourceInfo> getResourcesList(Message m, UriInfo ui) {
final String slash = "/";
String path = ui.getPath();
if (!path.startsWith(slash)) {
path = slash + path;
}
List<ClassResourceInfo> all = ((JAXRSServiceImpl) m.getExchange().getService()).getClassResourceInfos();
boolean absolutePathSlashOn = checkAbsolutePathSlash && ui.getAbsolutePath().getPath().endsWith(slash);
if (slash.equals(path) && !absolutePathSlashOn) {
return all;
}
List<ClassResourceInfo> cris = new LinkedList<>();
for (ClassResourceInfo cri : all) {
MultivaluedMap<String, String> map = new MetadataMap<>();
if (cri.getURITemplate().match(path, map) && slash.equals(map.getFirst(URITemplate.FINAL_MATCH_GROUP))) {
cris.add(cri);
}
}
return cris;
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class AegisElementProviderTest method testReadWriteComplexMap.
@Test
public void testReadWriteComplexMap() throws Exception {
Map<AegisTestBean, AegisSuperBean> testMap = new HashMap<AegisTestBean, AegisSuperBean>();
Class<InterfaceWithMap> iwithMapClass = InterfaceWithMap.class;
Method method = iwithMapClass.getMethod("mapFunction");
Type mapType = method.getGenericReturnType();
AegisTestBean bean = new AegisTestBean();
bean.setBoolValue(Boolean.TRUE);
bean.setStrValue("hovercraft");
AegisSuperBean bean2 = new AegisSuperBean();
bean2.setBoolValue(Boolean.TRUE);
bean2.setStrValue("hovercraft2");
testMap.put(bean, bean2);
MessageBodyWriter<Map<AegisTestBean, AegisSuperBean>> writer = new AegisElementProvider<Map<AegisTestBean, AegisSuperBean>>();
ByteArrayOutputStream os = new ByteArrayOutputStream();
writer.writeTo(testMap, testMap.getClass(), mapType, new Annotation[] {}, MediaType.APPLICATION_OCTET_STREAM_TYPE, new MetadataMap<String, Object>(), os);
byte[] bytes = os.toByteArray();
String xml = new String(bytes, "utf-8");
MessageBodyReader<Map<AegisTestBean, AegisSuperBean>> reader = new AegisElementProvider<Map<AegisTestBean, AegisSuperBean>>();
byte[] simpleBytes = xml.getBytes("utf-8");
Map<AegisTestBean, AegisSuperBean> map2 = reader.readFrom(null, mapType, new Annotation[] {}, MediaType.APPLICATION_OCTET_STREAM_TYPE, new MetadataMap<String, String>(), new ByteArrayInputStream(simpleBytes));
assertEquals(1, map2.size());
Map.Entry<AegisTestBean, AegisSuperBean> entry = map2.entrySet().iterator().next();
AegisTestBean bean1 = entry.getKey();
assertEquals("hovercraft", bean1.getStrValue());
assertEquals(Boolean.TRUE, bean1.getBoolValue());
AegisTestBean bean22 = entry.getValue();
assertEquals("hovercraft2", bean22.getStrValue());
assertEquals(Boolean.TRUE, bean22.getBoolValue());
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class CrossOriginResourceSharingFilter method findPreflightMethod.
private OperationResourceInfo findPreflightMethod(Map<ClassResourceInfo, MultivaluedMap<String, String>> matchedResources, String requestUri, String httpMethod, MultivaluedMap<String, String> values, Message m) {
final String contentType = MediaType.WILDCARD;
final MediaType acceptType = MediaType.WILDCARD_TYPE;
OperationResourceInfo ori = JAXRSUtils.findTargetMethod(matchedResources, m, httpMethod, values, contentType, Collections.singletonList(acceptType), false, false);
if (ori == null) {
return null;
}
if (ori.isSubResourceLocator()) {
Class<?> cls = ori.getMethodToInvoke().getReturnType();
ClassResourceInfo subcri = ori.getClassResourceInfo().getSubResource(cls, cls);
if (subcri == null) {
return null;
}
MultivaluedMap<String, String> newValues = new MetadataMap<String, String>();
newValues.putAll(values);
return findPreflightMethod(Collections.singletonMap(subcri, newValues), values.getFirst(URITemplate.FINAL_MATCH_GROUP), httpMethod, newValues, m);
}
return ori;
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class CrossOriginResourceSharingFilter method getResourceMethod.
private Method getResourceMethod(Message m, String httpMethod) {
String requestUri = HttpUtils.getPathToMatch(m, true);
List<ClassResourceInfo> resources = JAXRSUtils.getRootResources(m);
Map<ClassResourceInfo, MultivaluedMap<String, String>> matchedResources = JAXRSUtils.selectResourceClass(resources, requestUri, m);
if (matchedResources == null) {
return null;
}
MultivaluedMap<String, String> values = new MetadataMap<String, String>();
OperationResourceInfo ori = findPreflightMethod(matchedResources, requestUri, httpMethod, values, m);
return ori == null ? null : ori.getAnnotatedMethod();
}
Aggregations