You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2009/05/21 16:17:32 UTC
svn commit: r777126 [1/2] - in /cxf/trunk:
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/
rt/frontend/jaxrs/src/main/java/org...
Author: sergeyb
Date: Thu May 21 14:17:30 2009
New Revision: 777126
URL: http://svn.apache.org/viewvc?rev=777126&view=rev
Log:
JAXRS : support for annotation-free resource beans
Added:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/Parameter.java (with props)
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java (with props)
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserOperation.java (with props)
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserResource.java (with props)
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreNoAnnotations.java (with props)
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/ChapterNoAnnotations.java (with props)
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerUserResourceTest.java (with props)
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/resources.xml (with props)
Removed:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ParameterType.java
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSClientFactoryBeanDefinitionParser.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
cxf/trunk/systests/src/test/resources/jaxrs/WEB-INF/beans.xml
cxf/trunk/systests/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java Thu May 21 14:17:30 2009
@@ -18,6 +18,7 @@
*/
package org.apache.cxf.jaxrs;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.ResourceBundle;
@@ -36,7 +37,9 @@
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.endpoint.EndpointException;
import org.apache.cxf.endpoint.EndpointImpl;
+import org.apache.cxf.jaxrs.model.UserResource;
import org.apache.cxf.jaxrs.provider.ProviderFactory;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
import org.apache.cxf.service.Service;
import org.apache.cxf.service.model.BindingInfo;
import org.apache.cxf.service.model.EndpointInfo;
@@ -222,4 +225,20 @@
ep.put(ProviderFactory.class.getName(), factory);
return factory;
}
+
+ public void setModelBeans(UserResource... resources) {
+ setModelBeans(Arrays.asList(resources));
+ }
+
+ public void setModelBeans(List<UserResource> resources) {
+ serviceFactory.setUserResources(resources);
+ }
+
+ public void setModelRef(String modelRef) {
+ List<UserResource> resources = ResourceUtils.getUserResources(modelRef);
+ if (resources != null) {
+ serviceFactory.setUserResources(resources);
+ }
+ }
+
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java Thu May 21 14:17:30 2009
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
@@ -31,6 +32,7 @@
import org.apache.cxf.common.util.ClassHelper;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.UserResource;
import org.apache.cxf.jaxrs.utils.AnnotationUtils;
import org.apache.cxf.jaxrs.utils.ResourceUtils;
import org.apache.cxf.service.Service;
@@ -125,6 +127,21 @@
}
}
+ public void setUserResources(List<UserResource> resources) {
+ Map<String, UserResource> map = new HashMap<String, UserResource>();
+ for (UserResource ur : resources) {
+ map.put(ur.getName(), ur);
+ }
+ for (UserResource ur : resources) {
+ if (ur.getPath() != null) {
+ ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(map, ur, true);
+ if (cri != null) {
+ classResourceInfos.add(cri);
+ }
+ }
+ }
+ }
+
protected ClassResourceInfo createResourceInfo(Class cls, boolean isRoot) {
ClassResourceInfo classResourceInfo =
ResourceUtils.createClassResourceInfo(cls, cls, isRoot, enableStatic);
@@ -143,17 +160,30 @@
Class<?> realClass = ClassHelper.getRealClass(bean);
- ClassResourceInfo classResourceInfo =
- ResourceUtils.createClassResourceInfo(bean.getClass(), realClass, true, enableStatic);
- if (classResourceInfo != null) {
- classResourceInfos.add(classResourceInfo);
-
- classResourceInfo.setResourceProvider(
+ ClassResourceInfo cri = getCreatedFromModel(realClass);
+ if (cri != null) {
+ cri.setResourceClass(bean.getClass());
+ continue;
+ }
+
+ cri = ResourceUtils.createClassResourceInfo(bean.getClass(), realClass, true, enableStatic);
+ if (cri != null) {
+ classResourceInfos.add(cri);
+ cri.setResourceProvider(
new SingletonResourceProvider(bean));
}
}
}
+ private ClassResourceInfo getCreatedFromModel(Class<?> realClass) {
+ for (ClassResourceInfo cri : classResourceInfos) {
+ if (cri.isCreatedFromModel() && cri.getServiceClass() == realClass) {
+ return cri;
+ }
+ }
+ return null;
+ }
+
protected void initializeServiceModel() {
JAXRSServiceImpl service = new JAXRSServiceImpl(classResourceInfos);
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java Thu May 21 14:17:30 2009
@@ -57,10 +57,10 @@
import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.jaxrs.impl.MetadataMap;
import org.apache.cxf.jaxrs.impl.UriBuilderImpl;
+import org.apache.cxf.jaxrs.model.ParameterType;
import org.apache.cxf.jaxrs.provider.ProviderFactory;
import org.apache.cxf.jaxrs.utils.HttpUtils;
import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.ParameterType;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java Thu May 21 14:17:30 2009
@@ -33,14 +33,7 @@
import java.util.ResourceBundle;
import java.util.logging.Logger;
-import javax.ws.rs.CookieParam;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.MatrixParam;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
@@ -54,11 +47,11 @@
import org.apache.cxf.jaxrs.impl.MetadataMap;
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.model.Parameter;
+import org.apache.cxf.jaxrs.model.ParameterType;
import org.apache.cxf.jaxrs.provider.ProviderFactory;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
import org.apache.cxf.jaxrs.utils.FormUtils;
import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.ParameterType;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageContentsList;
import org.apache.cxf.phase.Phase;
@@ -125,17 +118,16 @@
reportInvalidResourceMethod(m, "INVALID_RESOURCE_METHOD");
}
- MultivaluedMap<ParameterType, Parameter> types =
- getParametersInfo(ori, m, params);
+ MultivaluedMap<ParameterType, Parameter> types = getParametersInfo(ori);
List<Object> pathParams = getPathParamValues(types, params, ori);
int bodyIndex = getBodyIndex(types, ori);
UriBuilder builder = getCurrentBuilder().clone();
if (isRoot) {
- builder.path(ori.getClassResourceInfo().getServiceClass());
+ builder.path(ori.getClassResourceInfo().getURITemplate().getValue());
}
- builder.path(m);
+ builder.path(ori.getURITemplate().getValue());
handleMatrixes(types, params, builder);
handleQueries(types, params, builder);
@@ -173,23 +165,26 @@
}
- private static MultivaluedMap<ParameterType, Parameter> getParametersInfo(OperationResourceInfo ori,
- Method m, Object[] params) {
- MultivaluedMap<ParameterType, Parameter> map = new MetadataMap<ParameterType, Parameter>();
- Annotation[][] paramAnns = m.getParameterAnnotations();
- if (paramAnns.length == 0) {
+ private static MultivaluedMap<ParameterType, Parameter> getParametersInfo(OperationResourceInfo ori) {
+ MultivaluedMap<ParameterType, Parameter> map =
+ new MetadataMap<ParameterType, Parameter>();
+
+ List<Parameter> parameters = ori.getParameters();
+ if (parameters.size() == 0) {
return map;
}
- for (int i = 0; i < paramAnns.length; i++) {
- Parameter p = getParameter(i, paramAnns[i], ori);
+ for (Parameter p : parameters) {
+ if (p.getType() == ParameterType.CONTEXT) {
+ reportInvalidResourceMethod(ori.getMethodToInvoke(), "NO_CONTEXT_PARAMETERS");
+ }
map.add(p.getType(), p);
}
if (map.containsKey(ParameterType.REQUEST_BODY)) {
if (map.get(ParameterType.REQUEST_BODY).size() > 1) {
- reportInvalidResourceMethod(m, "SINGLE_BODY_ONLY");
+ reportInvalidResourceMethod(ori.getMethodToInvoke(), "SINGLE_BODY_ONLY");
}
if (map.containsKey(ParameterType.FORM)) {
- reportInvalidResourceMethod(m, "ONLY_FORM_ALLOWED");
+ reportInvalidResourceMethod(ori.getMethodToInvoke(), "ONLY_FORM_ALLOWED");
}
}
return map;
@@ -281,17 +276,17 @@
// It's a rare case but we might want just to use UriBuilderImpl() directly
// on the client side and tell it to choose the last variable value
for (Parameter p : paramsList) {
- if (valuesMap.containsKey(p.getValue()) && !vars.contains(p.getValue())) {
+ if (valuesMap.containsKey(p.getName()) && !vars.contains(p.getName())) {
int index = 0;
for (Iterator<String> it = valuesMap.keySet().iterator(); it.hasNext(); index++) {
- if (it.next().equals(p.getValue())) {
+ if (it.next().equals(p.getName())) {
list.remove(index);
list.add(index, params[p.getIndex()]);
break;
}
}
} else {
- String paramName = p.getValue();
+ String paramName = p.getName();
if (!"".equals(paramName)) {
list.add(params[p.getIndex()]);
} else {
@@ -319,7 +314,7 @@
List<Parameter> qs = getParameters(map, ParameterType.QUERY);
for (Parameter p : qs) {
if (params[p.getIndex()] != null) {
- addParametersToBuilder(ub, p.getValue(), params[p.getIndex()], ParameterType.QUERY);
+ addParametersToBuilder(ub, p.getName(), params[p.getIndex()], ParameterType.QUERY);
}
}
}
@@ -329,7 +324,7 @@
List<Parameter> mx = getParameters(map, ParameterType.MATRIX);
for (Parameter p : mx) {
if (params[p.getIndex()] != null) {
- addParametersToBuilder(ub, p.getValue(), params[p.getIndex()], ParameterType.MATRIX);
+ addParametersToBuilder(ub, p.getName(), params[p.getIndex()], ParameterType.MATRIX);
}
}
}
@@ -342,7 +337,7 @@
List<Parameter> fm = getParameters(map, ParameterType.FORM);
for (Parameter p : fm) {
if (params[p.getIndex()] != null) {
- FormUtils.addPropertyToForm(form, p.getValue(), params[p.getIndex()]);
+ FormUtils.addPropertyToForm(form, p.getName(), params[p.getIndex()]);
}
}
@@ -354,7 +349,7 @@
List<Parameter> hs = getParameters(map, ParameterType.HEADER);
for (Parameter p : hs) {
if (params[p.getIndex()] != null) {
- headers.add(p.getValue(), params[p.getIndex()].toString());
+ headers.add(p.getName(), params[p.getIndex()].toString());
}
}
}
@@ -364,55 +359,11 @@
List<Parameter> cs = getParameters(map, ParameterType.COOKIE);
for (Parameter p : cs) {
if (params[p.getIndex()] != null) {
- headers.add(HttpHeaders.COOKIE, p.getValue() + '=' + params[p.getIndex()].toString());
+ headers.add(HttpHeaders.COOKIE, p.getName() + '=' + params[p.getIndex()].toString());
}
}
}
- private static Parameter getParameter(int index, Annotation[] anns, OperationResourceInfo ori) {
-
- Context ctx = AnnotationUtils.getAnnotation(anns, Context.class);
- if (ctx != null) {
- reportInvalidResourceMethod(ori.getMethodToInvoke(), "NO_CONTEXT_PARAMETERS");
- }
-
- PathParam a = AnnotationUtils.getAnnotation(anns, PathParam.class);
- if (a != null) {
- return new Parameter(ParameterType.PATH, index, a.value());
- }
-
- QueryParam q = AnnotationUtils.getAnnotation(anns, QueryParam.class);
- if (q != null) {
- return new Parameter(ParameterType.QUERY, index, q.value());
- }
-
- MatrixParam m = AnnotationUtils.getAnnotation(anns, MatrixParam.class);
- if (m != null) {
- return new Parameter(ParameterType.MATRIX, index, m.value());
- }
-
- FormParam f = AnnotationUtils.getAnnotation(anns, FormParam.class);
- if (f != null) {
- return new Parameter(ParameterType.FORM, index, f.value());
- }
-
- HeaderParam h = AnnotationUtils.getAnnotation(anns, HeaderParam.class);
- if (h != null) {
- return new Parameter(ParameterType.HEADER, index, h.value());
- }
-
- Parameter p = null;
- CookieParam c = AnnotationUtils.getAnnotation(anns, CookieParam.class);
- if (c != null) {
- p = new Parameter(ParameterType.COOKIE, index, c.value());
- } else {
- p = new Parameter(ParameterType.REQUEST_BODY, index, null);
- }
-
- return p;
-
- }
-
private Object doChainedInvocation(URI uri, MultivaluedMap<String, String> headers,
OperationResourceInfo ori, Object[] params, int bodyIndex,
MultivaluedMap<ParameterType, Parameter> types) throws Throwable {
@@ -466,30 +417,6 @@
throw new WebApplicationException(405);
}
- private static class Parameter {
- private ParameterType type;
- private int ind;
- private String aValue;
-
- public Parameter(ParameterType type, int ind, String aValue) {
- this.type = type;
- this.ind = ind;
- this.aValue = aValue;
- }
-
- public int getIndex() {
- return ind;
- }
-
- public String getValue() {
- return aValue;
- }
-
- public ParameterType getType() {
- return type;
- }
- }
-
// TODO : what we really need to do is to refactor JAXRSOutInterceptor so that
// it can handle both client requests and server responses - it may need to be split into
// several interceptors - in fact we need to do the same for JAXRSInInterceptor so that we can do
@@ -516,15 +443,18 @@
MultivaluedMap<String, String> headers = (MultivaluedMap)m.get(Message.PROTOCOL_HEADERS);
Method method = ori.getMethodToInvoke();
int bodyIndex = (Integer)m.get("BODY_INDEX");
+ Method aMethod = ori.getAnnotatedMethod();
+ Annotation[] anns = aMethod == null || bodyIndex == -1 ? new Annotation[0]
+ : aMethod.getParameterAnnotations()[bodyIndex];
Object body = objs.get(0);
try {
if (bodyIndex != -1) {
writeBody(body, m, body.getClass(),
- method.getGenericParameterTypes()[bodyIndex],
- method.getParameterAnnotations()[bodyIndex], headers, os);
+ method.getGenericParameterTypes()[bodyIndex],
+ anns, headers, os);
} else {
writeBody(body, m, body.getClass(), body.getClass(),
- method.getDeclaredAnnotations(), headers, os);
+ anns, headers, os);
}
os.flush();
} catch (Exception ex) {
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java Thu May 21 14:17:30 2009
@@ -20,9 +20,11 @@
import java.lang.reflect.InvocationHandler;
import java.net.URI;
+import java.util.Collections;
import java.util.List;
import org.apache.cxf.common.util.ProxyHelper;
+import org.apache.cxf.jaxrs.model.UserResource;
/**
* Factory for creating proxy clients.
@@ -142,6 +144,62 @@
}
/**
+ * Creates a proxy using user resource model
+ * @param baseAddress baseAddress
+ * @param cls proxy class, if not interface then a CGLIB proxy will be created
+ * @param modelRef model location
+ * @return typed proxy
+ */
+ public static <T> T createFromModel(String baseAddress, Class<T> cls, String modelRef,
+ String configLocation) {
+ return createFromModel(baseAddress, cls, modelRef, Collections.emptyList(), configLocation);
+ }
+
+ /**
+ * Creates a proxy using user resource model
+ * @param baseAddress baseAddress
+ * @param cls proxy class, if not interface then a CGLIB proxy will be created
+ * @param modelRef model location
+ * @param providers list of providers
+ * @return typed proxy
+ */
+ public static <T> T createFromModel(String baseAddress, Class<T> cls, String modelRef,
+ List<?> providers, String configLocation) {
+ JAXRSClientFactoryBean bean = WebClient.getBean(baseAddress, configLocation);
+ bean.setProviders(providers);
+ bean.setModelRef(modelRef);
+ return bean.create(cls);
+ }
+
+ /**
+ * Creates a proxy using user resource model
+ * @param baseAddress baseAddress
+ * @param cls proxy class, if not interface then a CGLIB proxy will be created
+ * @param modelBeans model beans
+ * @return typed proxy
+ */
+ public static <T> T createFromModel(String baseAddress, Class<T> cls, List<UserResource> modelBeans,
+ String configLocation) {
+ return createFromModel(baseAddress, cls, modelBeans, Collections.emptyList(), configLocation);
+ }
+
+ /**
+ * Creates a proxy using user resource model
+ * @param baseAddress baseAddress
+ * @param cls proxy class, if not interface then a CGLIB proxy will be created
+ * @param modelBeans model beans
+ * @param providers list of providers
+ * @return typed proxy
+ */
+ public static <T> T createFromModel(String baseAddress, Class<T> cls, List<UserResource> modelBeans,
+ List<?> providers, String configLocation) {
+ JAXRSClientFactoryBean bean = WebClient.getBean(baseAddress, configLocation);
+ bean.setProviders(providers);
+ bean.setModelBeans(modelBeans);
+ return bean.create(cls);
+ }
+
+ /**
* Creates a proxy, baseURI will be set to Client currentURI
*
* @param client Client instance
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java Thu May 21 14:17:30 2009
@@ -21,7 +21,6 @@
import java.net.URI;
import java.util.Map;
-import javax.ws.rs.Path;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MultivaluedMap;
@@ -35,7 +34,6 @@
import org.apache.cxf.jaxrs.JAXRSServiceImpl;
import org.apache.cxf.jaxrs.impl.MetadataMap;
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
import org.apache.cxf.service.Service;
public class JAXRSClientFactoryBean extends AbstractJAXRSFactoryBean {
@@ -126,7 +124,7 @@
Endpoint ep = createEndpoint();
URI baseURI = URI.create(getAddress());
ClassResourceInfo cri = serviceFactory.getClassResourceInfo().get(0);
- boolean isRoot = AnnotationUtils.getClassAnnotation(cri.getServiceClass(), Path.class) != null;
+ boolean isRoot = cri.getURITemplate() != null;
ClientProxyImpl proxyImpl = new ClientProxyImpl(baseURI, baseURI, cri, isRoot, inheritHeaders,
varValues);
initClient(proxyImpl, ep);
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Thu May 21 14:17:30 2009
@@ -42,9 +42,9 @@
import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.jaxrs.ext.form.Form;
+import org.apache.cxf.jaxrs.model.ParameterType;
import org.apache.cxf.jaxrs.utils.HttpUtils;
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.jaxrs.utils.ParameterType;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageContentsList;
import org.apache.cxf.phase.Phase;
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java Thu May 21 14:17:30 2009
@@ -38,6 +38,10 @@
this.m = new LinkedHashMap<K, List<V>>();
}
+ public MetadataMap(int size) {
+ this.m = new LinkedHashMap<K, List<V>>(size);
+ }
+
public MetadataMap(Map<K, List<V>> store) {
this(store, false, false);
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java Thu May 21 14:17:30 2009
@@ -26,7 +26,6 @@
import java.util.Map;
import java.util.logging.Logger;
-import javax.ws.rs.Path;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.UriBuilder;
@@ -37,7 +36,6 @@
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
import org.apache.cxf.jaxrs.model.OperationResourceInfoStack;
import org.apache.cxf.jaxrs.model.URITemplate;
-import org.apache.cxf.jaxrs.utils.AnnotationUtils;
import org.apache.cxf.jaxrs.utils.HttpUtils;
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
import org.apache.cxf.message.Message;
@@ -151,14 +149,13 @@
String sum = "";
for (MethodInvocationInfo invocation : stack) {
OperationResourceInfo ori = invocation.getMethodInfo();
- Path[] paths = {
- AnnotationUtils.getClassAnnotation(ori.getClassResourceInfo().getResourceClass(),
- Path.class),
- AnnotationUtils.getMethodAnnotation(ori.getAnnotatedMethod(), Path.class)
+ URITemplate[] paths = {
+ ori.getClassResourceInfo().getURITemplate(),
+ ori.getURITemplate()
};
- for (Path p : paths) {
- if (p != null) {
- String v = p.value();
+ for (URITemplate t : paths) {
+ if (t != null) {
+ String v = t.getValue();
sum += "/" + (decode ? HttpUtils.pathDecode(v) : v);
}
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java Thu May 21 14:17:30 2009
@@ -166,7 +166,8 @@
invoked = ori == null ? null : ori.getMethodToInvoke();
}
Class<?> targetType = getRawResponseClass(responseObj);
- Type genericType = getGenericResponseType(invoked, responseObj);
+ Type genericType =
+ getGenericResponseType(ori == null ? null : ori.getAnnotatedMethod(), responseObj);
if (genericType instanceof TypeVariable) {
genericType = InjectionUtils.getSuperType(ori.getClassResourceInfo().getServiceClass(),
(TypeVariable)genericType);
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java Thu May 21 14:17:30 2009
@@ -28,6 +28,7 @@
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
+import org.apache.cxf.jaxrs.model.Parameter;
import org.apache.cxf.jaxrs.model.URITemplate;
import org.apache.cxf.jaxrs.utils.AnnotationUtils;
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
@@ -74,8 +75,9 @@
if (AnnotationUtils.isContextClass(params[i])) {
values[i] = JAXRSUtils.createContextValue(m, genericTypes[i], params[i]);
} else {
+ Parameter p = ResourceUtils.getParameter(i, anns[i]);
values[i] = JAXRSUtils.createHttpParameterValue(
- anns[i], params[i], genericTypes[i], m, templateValues, null);
+ p, params[i], genericTypes[i], m, templateValues, null);
}
}
try {
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java Thu May 21 14:17:30 2009
@@ -59,6 +59,10 @@
}
}
+ public void setResourceClass(Class<?> rClass) {
+ resourceClass = rClass;
+ }
+
public Class<?> getServiceClass() {
return serviceClass;
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java Thu May 21 14:17:30 2009
@@ -49,6 +49,7 @@
private List<Field> paramFields;
private List<Method> paramMethods;
private boolean enableStatic;
+ private boolean createdFromModel;
public ClassResourceInfo(Class<?> theResourceClass) {
this(theResourceClass, false);
@@ -63,7 +64,13 @@
}
public ClassResourceInfo(Class<?> theResourceClass, Class<?> theServiceClass, boolean theRoot) {
+ this(theResourceClass, theServiceClass, theRoot, false);
+ }
+
+ public ClassResourceInfo(Class<?> theResourceClass, Class<?> theServiceClass,
+ boolean theRoot, boolean enableStatic) {
super(theResourceClass, theServiceClass, theRoot);
+ this.enableStatic = enableStatic;
if (theRoot) {
initParamFields();
initParamMethods();
@@ -71,13 +78,14 @@
}
public ClassResourceInfo(Class<?> theResourceClass, Class<?> theServiceClass,
- boolean theRoot, boolean enableStatic) {
+ boolean theRoot, boolean enableStatic, boolean createdFromModel) {
super(theResourceClass, theServiceClass, theRoot);
this.enableStatic = enableStatic;
if (theRoot) {
initParamFields();
initParamMethods();
}
+ this.createdFromModel = createdFromModel;
}
public ClassResourceInfo findResource(Class<?> typedClass, Class<?> instanceClass) {
@@ -176,6 +184,10 @@
cri);
}
+ public boolean isCreatedFromModel() {
+ return createdFromModel;
+ }
+
public ResourceProvider getResourceProvider() {
return resourceProvider;
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfo.java Thu May 21 14:17:30 2009
@@ -30,6 +30,7 @@
import org.apache.cxf.jaxrs.utils.AnnotationUtils;
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
public class OperationResourceInfo {
private URITemplate uriTemplate;
@@ -41,16 +42,45 @@
private List<MediaType> consumeMimes;
private boolean encoded;
private String defaultParamValue;
+ private List<Parameter> parameters;
- public OperationResourceInfo(Method m, ClassResourceInfo cri) {
- methodToInvoke = m;
- annotatedMethod = m;
+ public OperationResourceInfo(Method mInvoke, ClassResourceInfo cri) {
+ this(mInvoke, mInvoke, cri);
+ }
+
+ public OperationResourceInfo(Method mInvoke, Method mAnnotated, ClassResourceInfo cri) {
+ methodToInvoke = mInvoke;
+ annotatedMethod = mAnnotated;
+ if (mAnnotated != null) {
+ parameters = ResourceUtils.getParameters(mAnnotated);
+ }
classResourceInfo = cri;
checkMediaTypes();
checkEncoded();
checkDefaultParameterValue();
}
+
+ public OperationResourceInfo(Method m,
+ ClassResourceInfo cri,
+ URITemplate template,
+ String httpVerb,
+ String consumeMediaTypes,
+ String produceMediaTypes,
+ List<Parameter> params) {
+ methodToInvoke = m;
+ annotatedMethod = null;
+ classResourceInfo = cri;
+ uriTemplate = template;
+ httpMethod = httpVerb;
+ consumeMimes = JAXRSUtils.sortMediaTypes(consumeMediaTypes);
+ produceMimes = JAXRSUtils.sortMediaTypes(produceMediaTypes);
+ parameters = params;
+ }
+ public List<Parameter> getParameters() {
+ return parameters;
+ }
+
public URITemplate getURITemplate() {
return uriTemplate;
}
@@ -63,13 +93,13 @@
return classResourceInfo;
}
- public void setClassResourceInfo(ClassResourceInfo c) {
- classResourceInfo = c;
- }
-
public Method getMethodToInvoke() {
return methodToInvoke;
}
+
+ public Method getAnnotatedMethod() {
+ return annotatedMethod;
+ }
public void setMethodToInvoke(Method m) {
methodToInvoke = m;
@@ -83,17 +113,6 @@
httpMethod = m;
}
- public void setAnnotatedMethod(Method m) {
- if (m != null) {
- annotatedMethod = m;
- checkMediaTypes();
- }
- }
-
- public Method getAnnotatedMethod() {
- return annotatedMethod;
- }
-
public boolean isSubResourceLocator() {
return httpMethod == null ? true : false;
}
Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/Parameter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/Parameter.java?rev=777126&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/Parameter.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/Parameter.java Thu May 21 14:17:30 2009
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.model;
+
+
+public class Parameter {
+ private ParameterType type;
+ private int ind;
+ private String aValue;
+ private boolean isEncoded;
+ private String defaultValue;
+
+ public Parameter() {
+
+ }
+
+ public Parameter(String type, String aValue) {
+ this(ParameterType.valueOf(type), 0, aValue);
+ }
+
+ public Parameter(ParameterType type, String aValue) {
+ this(type, 0, aValue);
+ }
+
+ public Parameter(ParameterType type, int ind, String aValue) {
+ this.type = type;
+ this.ind = ind;
+ this.aValue = aValue;
+ }
+
+ public Parameter(ParameterType type, int ind, String aValue,
+ boolean isEncoded, String defaultValue) {
+ this.type = type;
+ this.ind = ind;
+ this.aValue = aValue;
+ this.isEncoded = isEncoded;
+ this.defaultValue = defaultValue;
+ }
+
+ public int getIndex() {
+ return ind;
+ }
+
+ public String getName() {
+ return aValue;
+ }
+
+ public void setName(String value) {
+ aValue = value;
+ }
+
+ public ParameterType getType() {
+ return type;
+ }
+
+ public void setType(String stype) {
+ type = ParameterType.valueOf(stype);
+ }
+
+ public boolean isEncoded() {
+ return isEncoded;
+ }
+
+ public void setEncoded(boolean encoded) {
+ isEncoded = encoded;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ public void setDefaultValue(String dValue) {
+ defaultValue = dValue;
+ }
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/Parameter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/Parameter.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java?rev=777126&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java Thu May 21 14:17:30 2009
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.model;
+
+public enum ParameterType {
+ PATH,
+ QUERY,
+ MATRIX,
+ HEADER,
+ COOKIE,
+ FORM,
+
+ REQUEST_BODY,
+ CONTEXT,
+ UNKNOWN
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java Thu May 21 14:17:30 2009
@@ -283,13 +283,17 @@
return sb.toString();
}
- public static URITemplate createTemplate(ClassResourceInfo cri, Path path) {
+ public static URITemplate createTemplate(Path path) {
- if (path == null) {
+ return createTemplate(path == null ? null : path.value());
+ }
+
+ public static URITemplate createTemplate(String pathValue) {
+
+ if (pathValue == null) {
return new URITemplate("/");
}
- String pathValue = path.value();
if (!pathValue.startsWith("/")) {
pathValue = "/" + pathValue;
}
Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserOperation.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserOperation.java?rev=777126&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserOperation.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserOperation.java Thu May 21 14:17:30 2009
@@ -0,0 +1,113 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.model;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.helpers.CastUtils;
+
+public class UserOperation {
+
+ private String methodName;
+ private String httpMethodName;
+ private String pathValue;
+ private String consumesTypes;
+ private String producesTypes;
+ private List<Parameter> params;
+
+ public UserOperation() {
+
+ }
+
+ public UserOperation(String methodName) {
+ this(methodName, null);
+ }
+
+ public UserOperation(String methodName, String pathValue) {
+ this(methodName, pathValue, null);
+ }
+
+ public UserOperation(String methodName, String pathValue, List<Parameter> ps) {
+ this.methodName = methodName;
+ this.pathValue = pathValue;
+ this.params = ps;
+ }
+
+ public String getName() {
+ return methodName;
+ }
+
+ public void setName(String name) {
+ if (!"".equals(name)) {
+ methodName = name;
+ }
+ }
+
+ public String getVerb() {
+ return httpMethodName;
+ }
+
+ public void setVerb(String name) {
+ if (!"".equals(name)) {
+ httpMethodName = name;
+ }
+ }
+
+ public String getConsumes() {
+ return consumesTypes == null ? MediaType.APPLICATION_XML : consumesTypes;
+ }
+
+ public String getProduces() {
+ return producesTypes == null ? MediaType.APPLICATION_XML : producesTypes;
+ }
+
+ public void setConsumes(String types) {
+ if (!"".equals(types)) {
+ consumesTypes = types;
+ }
+ }
+
+ public void setProduces(String types) {
+ if (!"".equals(types)) {
+ producesTypes = types;
+ }
+ }
+
+ public String getPath() {
+ return pathValue == null ? "/" : pathValue;
+ }
+
+ public void setPath(String path) {
+ if (!"".equals(path)) {
+ pathValue = path;
+ }
+ }
+
+ public void setParameters(List<Parameter> ps) {
+ params = ps;
+ }
+
+ public List<Parameter> getParameters() {
+ return params == null ? CastUtils.cast(Collections.emptyList(), Parameter.class)
+ : Collections.unmodifiableList(params);
+ }
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserOperation.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserResource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserResource.java?rev=777126&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserResource.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserResource.java Thu May 21 14:17:30 2009
@@ -0,0 +1,87 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.model;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.helpers.CastUtils;
+
+public class UserResource {
+
+ private String className;
+ private String pathValue;
+ private List<UserOperation> opers;
+
+ public UserResource() {
+ }
+
+ public UserResource(String className) {
+ this(className, null);
+ }
+
+ public UserResource(String className, String pathValue) {
+ this(className, pathValue, null);
+ }
+
+ public UserResource(String className, String pathValue, List<UserOperation> ops) {
+ this.className = className;
+ this.pathValue = pathValue;
+ this.opers = ops;
+ }
+
+ public String getName() {
+ return className;
+ }
+
+ public void setName(String name) {
+ if (!"".equals(name)) {
+ className = name;
+ }
+ }
+
+ public String getPath() {
+ return pathValue;
+ }
+
+ public void setPath(String path) {
+ if (!"".equals(path)) {
+ pathValue = path;
+ }
+ }
+
+ public void setOperations(List<UserOperation> ops) {
+ opers = ops;
+ }
+
+ public List<UserOperation> getOperations() {
+ return opers == null ? CastUtils.cast(Collections.emptyList(), UserOperation.class)
+ : Collections.unmodifiableList(opers);
+ }
+
+ public Map<String, UserOperation> getOperationsAsMap() {
+ Map<String, UserOperation> map = new HashMap<String, UserOperation>();
+ for (UserOperation op : opers) {
+ map.put(op.getName(), op);
+ }
+ return map;
+ }
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserResource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/UserResource.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java Thu May 21 14:17:30 2009
@@ -30,8 +30,8 @@
import javax.ws.rs.ext.MessageBodyWriter;
import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.jaxrs.model.ParameterType;
import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.ParameterType;
public class PrimitiveTextProvider
implements MessageBodyReader<Object>, MessageBodyWriter<Object> {
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSClientFactoryBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSClientFactoryBeanDefinitionParser.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSClientFactoryBeanDefinitionParser.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSClientFactoryBeanDefinitionParser.java Thu May 21 14:17:30 2009
@@ -28,6 +28,8 @@
import org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor;
import org.apache.cxf.configuration.spring.AbstractFactoryBeanDefinitionParser;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.apache.cxf.jaxrs.model.UserResource;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
@@ -80,9 +82,12 @@
List list = ctx.getDelegate().parseListElement(el, bean.getBeanDefinition());
bean.addPropertyValue(name, list);
} else if ("features".equals(name) || "providers".equals(name)
- || "schemaLocations".equals(name)) {
+ || "schemaLocations".equals(name) || "modelBeans".equals(name)) {
List list = ctx.getDelegate().parseListElement(el, bean.getBeanDefinition());
bean.addPropertyValue(name, list);
+ } else if ("model".equals(name)) {
+ List<UserResource> resources = ResourceUtils.getResourcesFromElement(el);
+ bean.addPropertyValue("modelBeans", resources);
} else {
setFirstChildAsProperty(el, ctx, bean, name);
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java Thu May 21 14:17:30 2009
@@ -32,6 +32,8 @@
import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
+import org.apache.cxf.jaxrs.model.UserResource;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
@@ -79,9 +81,13 @@
List list = ctx.getDelegate().parseListElement(el, bean.getBeanDefinition());
bean.addPropertyValue(name, list);
} else if ("features".equals(name) || "schemaLocations".equals(name)
- || "providers".equals(name) || "serviceBeans".equals(name)) {
+ || "providers".equals(name) || "serviceBeans".equals(name)
+ || "modelBeans".equals(name)) {
List list = ctx.getDelegate().parseListElement(el, bean.getBeanDefinition());
bean.addPropertyValue(name, list);
+ } else if ("model".equals(name)) {
+ List<UserResource> resources = ResourceUtils.getResourcesFromElement(el);
+ bean.addPropertyValue("modelBeans", resources);
} else {
setFirstChildAsProperty(el, ctx, bean, name);
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java Thu May 21 14:17:30 2009
@@ -31,7 +31,6 @@
import javax.ws.rs.Consumes;
import javax.ws.rs.CookieParam;
import javax.ws.rs.DefaultValue;
-import javax.ws.rs.Encoded;
import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.HttpMethod;
@@ -49,7 +48,6 @@
import javax.ws.rs.ext.Providers;
import org.apache.cxf.jaxrs.ext.MessageContext;
-import org.apache.cxf.jaxrs.model.OperationResourceInfo;
public final class AnnotationUtils {
@@ -250,28 +248,10 @@
return null;
}
- public static boolean isEncoded(Annotation[] anns, OperationResourceInfo ori) {
-
- if (AnnotationUtils.getAnnotation(anns, Encoded.class) != null) {
- return true;
- }
-
- if (ori == null) {
- return false;
- }
- return ori.isEncodedEnabled();
- }
-
- public static String getDefaultParameterValue(Annotation[] anns, OperationResourceInfo ori) {
+ public static String getDefaultParameterValue(Annotation[] anns) {
DefaultValue dv = AnnotationUtils.getAnnotation(anns, DefaultValue.class);
- if (dv != null) {
- return dv.value();
- }
+ return dv != null ? dv.value() : null;
- if (ori == null) {
- return null;
- }
- return ori.getDefaultParameterValue();
}
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Thu May 21 14:17:30 2009
@@ -39,6 +39,7 @@
import org.apache.cxf.common.util.UrlUtils;
import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
+import org.apache.cxf.jaxrs.model.ParameterType;
import org.apache.cxf.message.Message;
import org.apache.cxf.transport.Destination;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java Thu May 21 14:17:30 2009
@@ -82,6 +82,7 @@
import org.apache.cxf.jaxrs.impl.tl.ThreadLocalServletContext;
import org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo;
import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.jaxrs.model.ParameterType;
import org.apache.cxf.jaxrs.provider.ProviderFactory;
import org.apache.cxf.message.Message;
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Thu May 21 14:17:30 2009
@@ -46,15 +46,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
-import javax.ws.rs.CookieParam;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.MatrixParam;
-import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.Cookie;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
@@ -89,6 +82,8 @@
import org.apache.cxf.jaxrs.model.ClassResourceInfoComparator;
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
import org.apache.cxf.jaxrs.model.OperationResourceInfoComparator;
+import org.apache.cxf.jaxrs.model.Parameter;
+import org.apache.cxf.jaxrs.model.ParameterType;
import org.apache.cxf.jaxrs.model.URITemplate;
import org.apache.cxf.jaxrs.provider.AbstractConfigurableProvider;
import org.apache.cxf.jaxrs.provider.ProviderFactory;
@@ -182,7 +177,8 @@
MultivaluedMap<String, String> values =
(MultivaluedMap<String, String>)message.get(URITemplate.TEMPLATE_PARAMETERS);
for (Method m : cri.getParameterMethods()) {
- Object o = createHttpParameterValue(m.getAnnotations(),
+ Parameter p = ResourceUtils.getParameter(0, m.getAnnotations());
+ Object o = createHttpParameterValue(p,
m.getParameterTypes()[0],
m.getGenericParameterTypes()[0],
message,
@@ -194,7 +190,8 @@
}
// Param fields
for (Field f : cri.getParameterFields()) {
- Object o = createHttpParameterValue(f.getAnnotations(),
+ Parameter p = ResourceUtils.getParameter(0, f.getAnnotations());
+ Object o = createHttpParameterValue(p,
f.getType(),
f.getGenericType(),
message,
@@ -417,11 +414,13 @@
Message message) {
- Method method = ori.getAnnotatedMethod();
+ Method method = ori.getMethodToInvoke();
Class[] parameterTypes = method.getParameterTypes();
- Type[] genericParameterTypes = method.getGenericParameterTypes();
- Annotation[][] parameterAnnotations = method.getParameterAnnotations();
-
+ Parameter[] paramsInfo = ori.getParameters().toArray(new Parameter[]{});
+ Method annotatedMethod = ori.getAnnotatedMethod();
+ Type[] genericParameterTypes = annotatedMethod == null ? method.getGenericParameterTypes()
+ : annotatedMethod.getGenericParameterTypes();
+ Annotation[][] anns = annotatedMethod == null ? null : annotatedMethod.getParameterAnnotations();
List<Object> params = new ArrayList<Object>(parameterTypes.length);
for (int i = 0; i < parameterTypes.length; i++) {
@@ -435,7 +434,8 @@
Object paramValue = processParameter(param,
genericParam,
- parameterAnnotations[i],
+ anns == null ? new Annotation[0] : anns[i],
+ paramsInfo[i],
values,
message,
ori);
@@ -447,15 +447,14 @@
private static Object processParameter(Class<?> parameterClass,
Type parameterType,
- Annotation[] parameterAnns,
+ Annotation[] parameterAnns,
+ Parameter parameter,
MultivaluedMap<String, String> values,
Message message,
OperationResourceInfo ori) {
-
InputStream is = message.getContent(InputStream.class);
- if (parameterAnns == null
- || !AnnotationUtils.isValidParamAnnotations(parameterAnns)) {
+ if (parameter.getType() == ParameterType.REQUEST_BODY) {
String contentType = (String)message.get(Message.CONTENT_TYPE);
@@ -475,11 +474,11 @@
MediaType.valueOf(contentType),
ori.getConsumeTypes(),
message);
- } else if (parameterAnns[0].annotationType() == Context.class) {
+ } else if (parameter.getType() == ParameterType.CONTEXT) {
return createContextValue(message, parameterType, parameterClass);
} else {
- return createHttpParameterValue(parameterAnns,
+ return createHttpParameterValue(parameter,
parameterClass,
parameterType,
message,
@@ -488,51 +487,48 @@
}
}
- public static Object createHttpParameterValue(Annotation[] anns,
+ public static Object createHttpParameterValue(Parameter parameter,
Class<?> parameterClass,
Type genericParam,
Message message,
MultivaluedMap<String, String> values,
OperationResourceInfo ori) {
- boolean isEncoded = AnnotationUtils.isEncoded(anns, ori);
- String defaultValue = AnnotationUtils.getDefaultParameterValue(anns, ori);
+ boolean isEncoded = parameter.isEncoded() || ori != null && ori.isEncodedEnabled();
+ String defaultValue = parameter.getDefaultValue();
+ if (defaultValue == null && ori != null) {
+ defaultValue = ori.getDefaultParameterValue();
+ }
Object result = null;
- PathParam pathParam = AnnotationUtils.getAnnotation(anns, PathParam.class);
- if (pathParam != null) {
- result = readFromUriParam(message, pathParam, parameterClass, genericParam,
+ if (parameter.getType() == ParameterType.PATH) {
+ result = readFromUriParam(message, parameter.getName(), parameterClass, genericParam,
values, defaultValue, !isEncoded);
}
- QueryParam qp = AnnotationUtils.getAnnotation(anns, QueryParam.class);
- if (qp != null) {
- result = readQueryString(qp, parameterClass, genericParam, message,
+ if (parameter.getType() == ParameterType.QUERY) {
+ result = readQueryString(parameter.getName(), parameterClass, genericParam, message,
defaultValue, !isEncoded);
}
- MatrixParam mp = AnnotationUtils.getAnnotation(anns, MatrixParam.class);
- if (mp != null) {
- result = processMatrixParam(message, mp.value(), parameterClass, genericParam,
+ if (parameter.getType() == ParameterType.MATRIX) {
+ result = processMatrixParam(message, parameter.getName(), parameterClass, genericParam,
defaultValue, !isEncoded);
}
- FormParam fp = AnnotationUtils.getAnnotation(anns, FormParam.class);
- if (fp != null) {
- result = processFormParam(message, fp.value(), parameterClass, genericParam,
+ if (parameter.getType() == ParameterType.FORM) {
+ result = processFormParam(message, parameter.getName(), parameterClass, genericParam,
defaultValue, !isEncoded);
}
- CookieParam cookie = AnnotationUtils.getAnnotation(anns, CookieParam.class);
- if (cookie != null) {
- result = processCookieParam(message, cookie.value(), parameterClass, genericParam,
+ if (parameter.getType() == ParameterType.COOKIE) {
+ result = processCookieParam(message, parameter.getName(), parameterClass, genericParam,
defaultValue);
}
- HeaderParam hp = AnnotationUtils.getAnnotation(anns, HeaderParam.class);
- if (hp != null) {
- result = processHeaderParam(message, hp.value(), parameterClass, genericParam,
+ if (parameter.getType() == ParameterType.HEADER) {
+ result = processHeaderParam(message, parameter.getName(), parameterClass, genericParam,
defaultValue);
}
@@ -726,14 +722,13 @@
}
private static Object readFromUriParam(Message m,
- PathParam uriParamAnnotation,
+ String parameterName,
Class<?> paramType,
Type genericType,
MultivaluedMap<String, String> values,
String defaultValue,
boolean decoded) {
- String parameterName = uriParamAnnotation.value();
if ("".equals(parameterName)) {
return InjectionUtils.handleBean(paramType, values, ParameterType.PATH, m, decoded);
} else {
@@ -751,14 +746,12 @@
//TODO : multiple query string parsing, do it once
- private static Object readQueryString(QueryParam queryParam,
+ private static Object readQueryString(String queryName,
Class<?> paramType,
Type genericType,
Message m,
String defaultValue,
boolean decode) {
- String queryName = queryParam.value();
-
if ("".equals(queryName)) {
return InjectionUtils.handleBean(paramType, new UriInfoImpl(m, null).getQueryParameters(),
ParameterType.QUERY, m, decode);
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=777126&r1=777125&r2=777126&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java Thu May 21 14:17:30 2009
@@ -19,25 +19,49 @@
package org.apache.cxf.jaxrs.utils;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.ResourceBundle;
import java.util.logging.Logger;
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.MatrixParam;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.i18n.BundleUtils;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
import org.apache.cxf.jaxrs.model.MethodDispatcher;
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.model.Parameter;
+import org.apache.cxf.jaxrs.model.ParameterType;
import org.apache.cxf.jaxrs.model.URITemplate;
+import org.apache.cxf.jaxrs.model.UserOperation;
+import org.apache.cxf.jaxrs.model.UserResource;
public final class ResourceUtils {
@@ -50,11 +74,55 @@
}
public static ClassResourceInfo createClassResourceInfo(
+ Map<String, UserResource> resources, UserResource model, boolean isRoot) {
+ if (model.getName() == null) {
+ return null;
+ }
+ Class<?> sClass = loadClass(model.getName());
+ ClassResourceInfo cri = new ClassResourceInfo(sClass, sClass, isRoot, true, true);
+ try {
+ cri.setResourceProvider(new SingletonResourceProvider(sClass.newInstance()));
+ } catch (Exception ex) {
+ throw new RuntimeException("Resource class " + model.getName() + " can not be created");
+ }
+ URITemplate t = URITemplate.createTemplate(model.getPath());
+ cri.setURITemplate(t);
+ MethodDispatcher md = new MethodDispatcher();
+ Map<String, UserOperation> ops = model.getOperationsAsMap();
+ for (Method m : cri.getServiceClass().getMethods()) {
+ UserOperation op = ops.get(m.getName());
+ if (op == null || op.getName() == null) {
+ continue;
+ }
+ OperationResourceInfo ori =
+ new OperationResourceInfo(m, cri, URITemplate.createTemplate(op.getPath()),
+ op.getVerb(), op.getConsumes(), op.getProduces(),
+ op.getParameters());
+ String rClassName = m.getReturnType().getName();
+ if (op.getVerb() == null) {
+ if (resources.containsKey(rClassName)) {
+ ClassResourceInfo subCri = rClassName.equals(model.getName()) ? cri
+ : createClassResourceInfo(resources, resources.get(rClassName), false);
+ if (subCri != null) {
+ cri.addSubClassResourceInfo(subCri);
+ md.bind(ori, m);
+ }
+ }
+ } else {
+ md.bind(ori, m);
+ }
+ }
+ cri.setMethodDispatcher(md);
+ return checkMethodDispatcher(cri) ? cri : null;
+
+ }
+
+ public static ClassResourceInfo createClassResourceInfo(
final Class<?> rClass, final Class<?> sClass, boolean root, boolean enableStatic) {
ClassResourceInfo cri = new ClassResourceInfo(rClass, sClass, root, enableStatic);
if (root) {
- URITemplate t = URITemplate.createTemplate(cri, cri.getPath());
+ URITemplate t = URITemplate.createTemplate(cri.getPath());
cri.setURITemplate(t);
}
@@ -127,14 +195,78 @@
return cs.size() == 0 ? null : cs.get(0);
}
+ public static List<Parameter> getParameters(Method resourceMethod) {
+ Annotation[][] paramAnns = resourceMethod.getParameterAnnotations();
+ if (paramAnns.length == 0) {
+ return CastUtils.cast(Collections.emptyList(), Parameter.class);
+ }
+ List<Parameter> params = new ArrayList<Parameter>(paramAnns.length);
+ for (int i = 0; i < paramAnns.length; i++) {
+ Parameter p = getParameter(i, paramAnns[i]);
+ params.add(p);
+ }
+ return params;
+ }
+
+ public static Parameter getParameter(int index, Annotation[] anns) {
+
+ Context ctx = AnnotationUtils.getAnnotation(anns, Context.class);
+ if (ctx != null) {
+ return new Parameter(ParameterType.CONTEXT, index, null);
+ }
+
+ boolean isEncoded = AnnotationUtils.getAnnotation(anns, Encoded.class) != null;
+ String dValue = AnnotationUtils.getDefaultParameterValue(anns);
+
+ Parameter p = null;
+
+ PathParam a = AnnotationUtils.getAnnotation(anns, PathParam.class);
+ if (a != null) {
+ p = new Parameter(ParameterType.PATH, index, a.value(), isEncoded, dValue);
+ }
+ if (p == null) {
+ QueryParam q = AnnotationUtils.getAnnotation(anns, QueryParam.class);
+ if (q != null) {
+ p = new Parameter(ParameterType.QUERY, index, q.value(), isEncoded, dValue);
+ }
+ }
+ if (p != null) {
+ return p;
+ }
+
+ MatrixParam m = AnnotationUtils.getAnnotation(anns, MatrixParam.class);
+ if (m != null) {
+ return new Parameter(ParameterType.MATRIX, index, m.value(), isEncoded, dValue);
+ }
+
+ FormParam f = AnnotationUtils.getAnnotation(anns, FormParam.class);
+ if (f != null) {
+ return new Parameter(ParameterType.FORM, index, f.value(), isEncoded, dValue);
+ }
+
+ HeaderParam h = AnnotationUtils.getAnnotation(anns, HeaderParam.class);
+ if (h != null) {
+ return new Parameter(ParameterType.HEADER, index, h.value(), isEncoded, dValue);
+ }
+
+ p = null;
+ CookieParam c = AnnotationUtils.getAnnotation(anns, CookieParam.class);
+ if (c != null) {
+ p = new Parameter(ParameterType.COOKIE, index, c.value(), isEncoded, dValue);
+ } else {
+ p = new Parameter(ParameterType.REQUEST_BODY, index, null);
+ }
+
+ return p;
+ }
+
+
private static OperationResourceInfo createOperationInfo(Method m, Method annotatedMethod,
ClassResourceInfo cri, Path path, String httpMethod) {
- OperationResourceInfo ori = new OperationResourceInfo(m, cri);
- URITemplate t =
- URITemplate.createTemplate(cri, path);
+ OperationResourceInfo ori = new OperationResourceInfo(m, annotatedMethod, cri);
+ URITemplate t = URITemplate.createTemplate(path);
ori.setURITemplate(t);
ori.setHttpMethod(httpMethod);
- ori.setAnnotatedMethod(annotatedMethod);
return ori;
}
@@ -148,4 +280,90 @@
}
return true;
}
+
+
+ private static Class<?> loadClass(String cName) {
+ try {
+ return ClassLoaderUtils.loadClass(cName.trim(), ResourceUtils.class);
+ } catch (ClassNotFoundException ex) {
+ throw new RuntimeException("No class " + cName.trim() + " can be found", ex);
+ }
+ }
+
+ public static List<UserResource> getUserResources(String loc) {
+ try {
+ InputStream is = null;
+ if (loc.startsWith("classpath:")) {
+ String path = loc.substring("classpath:".length());
+ is = ResourceUtils.class.getResourceAsStream(path);
+ } else {
+ File f = new File(loc);
+ if (f.exists()) {
+ is = new FileInputStream(f);
+ }
+ }
+ if (is == null) {
+ LOG.warning("No user model is available at " + loc);
+ return null;
+ }
+ return getUserResources(is);
+ } catch (Exception ex) {
+ LOG.warning("Problem with processing a user model at " + loc);
+ }
+
+ return null;
+ }
+
+ public static List<UserResource> getUserResources(InputStream is) throws Exception {
+ Document doc = DOMUtils.readXml(new InputStreamReader(is, "UTF-8"));
+ return getResourcesFromElement(doc.getDocumentElement());
+ }
+
+ public static List<UserResource> getResourcesFromElement(Element modelEl) {
+ List<UserResource> resources = new ArrayList<UserResource>();
+ List<Element> resourceEls =
+ DOMUtils.findAllElementsByTagNameNS(modelEl,
+ "http://cxf.apache.org/jaxrs", "resource");
+ for (Element e : resourceEls) {
+ resources.add(getResourceFromElement(e));
+ }
+ return resources;
+ }
+
+ private static UserResource getResourceFromElement(Element e) {
+ UserResource resource = new UserResource();
+ resource.setName(e.getAttribute("name"));
+ resource.setPath(e.getAttribute("path"));
+ List<Element> operEls =
+ DOMUtils.findAllElementsByTagNameNS(e,
+ "http://cxf.apache.org/jaxrs", "operation");
+ List<UserOperation> opers = new ArrayList<UserOperation>(operEls.size());
+ for (Element operEl : operEls) {
+ opers.add(getOperationFromElement(operEl));
+ }
+ resource.setOperations(opers);
+ return resource;
+ }
+
+ 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.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<Parameter>(paramEls.size());
+ for (Element paramEl : paramEls) {
+ Parameter p = new Parameter(paramEl.getAttribute("type"), paramEl.getAttribute("name"));
+ p.setEncoded(Boolean.valueOf(paramEl.getAttribute("encoded")));
+ p.setDefaultValue(paramEl.getAttribute("default"));
+ params.add(p);
+ }
+ op.setParameters(params);
+ return op;
+ }
+
}