Author: heiko.braun(a)jboss.com
Date: 2007-11-20 06:30:56 -0500 (Tue, 20 Nov 2007)
New Revision: 5069
Added:
stack/native/branches/rest/src/main/java/org/jboss/rs/model/AbstractResourceOperation.java
Modified:
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ResourceServlet.java
stack/native/branches/rest/src/main/java/org/jboss/rs/model/AbstractRegexResolveable.java
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ParameterBinding.java
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceLocator.java
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceMethod.java
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModel.java
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelParser.java
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceResolver.java
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/Invocation.java
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/InvocationBuilder.java
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/RuntimeContext.java
stack/native/branches/rest/src/test/java/org/jboss/test/rs/invocation/InvocationBuilderTestCase.java
Log:
Fixed parameter binding
Modified:
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ResourceServlet.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ResourceServlet.java 2007-11-20
10:22:23 UTC (rev 5068)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ResourceServlet.java 2007-11-20
11:30:56 UTC (rev 5069)
@@ -104,8 +104,9 @@
Stack<ResourceLocator> visitedLocators = resolver.getVisitedLocator();
while(!visitedLocators.isEmpty())
{
- ResourceLocator loc = visitedLocators.pop();
-
+ ResourceLocator loc = visitedLocators.pop();
+ rt.setWorkingPath(resolver.getLocatorWorkingPath(loc));
+
InvocationBuilder builder = new DefaultInvocationBuilder();
builder.addInvocationModel(loc.getParameterBinding());
builder.addInvocationModel(loc.getOperationBinding());
@@ -118,7 +119,8 @@
// create an Invocation instance
InvocationBuilder builder = new DefaultInvocationBuilder();
-
+ rt.setWorkingPath(resolver.getMethodWorkingPath());
+
if(subResourceInstance!=null)
builder.addInvocationModel(new PresetInvocationTarget(subResourceInstance));
Modified:
stack/native/branches/rest/src/main/java/org/jboss/rs/model/AbstractRegexResolveable.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/model/AbstractRegexResolveable.java 2007-11-20
10:22:23 UTC (rev 5068)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/model/AbstractRegexResolveable.java 2007-11-20
11:30:56 UTC (rev 5069)
@@ -29,21 +29,23 @@
* @author Heiko.Braun(a)jboss.com
* @version $Revision$
*/
-abstract class AbstractRegexResolveable
+abstract class AbstractRegexResolveable<T>
{
public final String URI_PARAM_PATTERN = "(.*?)";
public final String CHILD_SUFFIX_PATTERN = "(/.*)?";
public final String CHILDLESS_SUFFIX_PATTERN = "(/)?";
protected Pattern regexPattern;
- private boolean isCompiled;
+ private boolean isCompiled;
+ protected T parent = null;
+
protected void initFromUriTemplate(String uriTemplate)
{
- initFromUriTemplate(uriTemplate, null);
+ setupRegexPatterns(uriTemplate, null);
}
- protected void initFromUriTemplate(String uriTemplate, UriParamHandler handler)
+ protected void setupRegexPatterns(String uriTemplate, UriParamHandler handler)
{
assert uriTemplate!=null;
assert !uriTemplate.startsWith("/");
@@ -156,6 +158,10 @@
return token.startsWith("{") && token.endsWith("}");
}
+ public T getParent() {
+ return parent;
+ }
+
abstract boolean hasChildren();
abstract void freeze();
@@ -164,5 +170,5 @@
{
void newUriParam(int regexGroup, String paramName);
}
-
+
}
Added:
stack/native/branches/rest/src/main/java/org/jboss/rs/model/AbstractResourceOperation.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/model/AbstractResourceOperation.java
(rev 0)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/model/AbstractResourceOperation.java 2007-11-20
11:30:56 UTC (rev 5069)
@@ -0,0 +1,71 @@
+package org.jboss.rs.model;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.lang.reflect.Method;
+
+/**
+ * Common base class for {@link org.jboss.rs.model.ResourceLocator}
+ * and {@link org.jboss.rs.model.ResourceMethod}
+ */
+abstract class AbstractResourceOperation extends AbstractRegexResolveable
+{
+ protected String uriTemplate;
+ protected Method invocationTarget;
+ protected ParameterBinding parameterBinding;
+ protected boolean frozen;
+
+ AbstractResourceOperation(String uriTemplate, Method invocationTarget)
+ {
+ this.uriTemplate = uriTemplate;
+ this.invocationTarget = invocationTarget;
+ }
+
+ void freeze()
+ {
+ // We need to know which param belongs to what regex group
+ final Map<String, Integer> regexInfo = new HashMap<String, Integer>();
+ UriParamHandler collectRegexInfo = new UriParamHandler()
+ {
+ public void newUriParam(int regexGroup, String paramName)
+ {
+ regexInfo.put(paramName, regexGroup);
+ }
+ };
+
+ setupRegexPatterns(this.uriTemplate, collectRegexInfo);
+
+ setupParameterBinding(regexInfo);
+
+ // Lock instance
+ this.frozen = true;
+ }
+
+ private void setupParameterBinding(Map<String, Integer> regexInfo)
+ {
+ // Create ParameterBindig
+ this.parameterBinding = new ParameterBinding(this.regexPattern);
+
+ // Annotations on method parameters
+ this.parameterBinding.registerParameterAnnotations(invocationTarget);
+
+ // Additional info abpout the regex binding
+ for(String paramName : regexInfo.keySet())
+ {
+ int group = regexInfo.get(paramName);
+ this.parameterBinding.registerRegexGroupForParam(group, paramName);
+ }
+ }
+
+ public ParameterBinding getParameterBinding()
+ {
+ assert frozen;
+ return parameterBinding;
+ }
+
+ public OperationBinding getOperationBinding()
+ {
+ assert frozen;
+ return new OperationBinding(this.invocationTarget);
+ }
+}
Property changes on:
stack/native/branches/rest/src/main/java/org/jboss/rs/model/AbstractResourceOperation.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ParameterBinding.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ParameterBinding.java 2007-11-20
10:22:23 UTC (rev 5068)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ParameterBinding.java 2007-11-20
11:30:56 UTC (rev 5069)
@@ -38,14 +38,26 @@
import java.util.regex.Pattern;
/**
- * Carries mapping information about
+ * ParameterBinding maps {@link org.jboss.rs.runtime.RuntimeContext} parameter
+ * to {@link Invocation} instances. ParameterBinding works on the full request path
+ * ({@link org.jboss.rs.runtime.RuntimeContext#getPath()}).
+ *
+ * <p>
+ * It carries mapping information about
* <ul>
- * <li>MatrixParam
- * <li>QueryParam
- * <li>UriParam
- * <li>HttpContext
- * <li>HeaderParam
+ * <li>MatrixParam
+ * <li>QueryParam
+ * <li>UriParam
+ * <li>HttpContext
+ * <li>HeaderParam
* </ul>
+ *
+ * <p>
+ * UriParameter are extracted by using using regular expressions.
+ *
+ * @see org.jboss.rs.model.ResourceMethod
+ * @see org.jboss.rs.model.ResourceLocator
+ *
* @author Heiko.Braun(a)jboss.com
* @version $Revision$
*/
@@ -80,12 +92,21 @@
/* Parameter types except for entity body*/
Map<Integer, Class> parameterTypes = new HashMap<Integer, Class>();
+ ParameterBinding(Pattern rootPattern)
+ {
+ this.regex = rootPattern;
+ }
+
public void accept(Invocation invocation)
{
RuntimeContext ctx = invocation.getContext();
- String path = ctx.getPath();
+ String workingPath = ctx.getWorkingPath();
- Matcher matcher = regex.matcher(path);
+ assert ctx!=null;
+ assert workingPath !=null;
+
+ // local workingPath matching
+ Matcher matcher = regex.matcher(workingPath);
boolean matches = matcher.matches();
if(!matches)
@@ -95,7 +116,7 @@
for(String param : uriParam.keySet())
{
int paramIndex = uriParam.get(param);
- String paramValue = matcher.group(regexMapping.get(param) + 1);
+ String paramValue = matcher.group(regexMapping.get(param));
invocation.insertParameterInstance(paramIndex, paramValue);
}
@@ -123,12 +144,6 @@
}
}
- ParameterBinding(Pattern rootPattern)
- {
- // Extend pattern to strip root path, results in additional groups
- this.regex = Pattern.compile(PREFIX_PATTERN +rootPattern.toString());
- }
-
void registerRegexGroupForParam(int group, String paramName)
{
regexMapping.put(paramName, group);
Modified:
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceLocator.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceLocator.java 2007-11-20
10:22:23 UTC (rev 5068)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceLocator.java 2007-11-20
11:30:56 UTC (rev 5069)
@@ -22,25 +22,20 @@
package org.jboss.rs.model;
import java.lang.reflect.Method;
-import java.util.Map;
-import java.util.HashMap;
/**
+ * Resource locator meta data.
+ *
* @author Heiko.Braun(a)jboss.com
* @version $Revision$
*/
-public class ResourceLocator extends AbstractRegexResolveable
-{
+public class ResourceLocator extends AbstractResourceOperation {
private ResourceModel link;
-
- private String uriTemplate;
- private Method invocationTarget;
- private ParameterBinding parameterBinding;
-
- ResourceLocator(Method invocationTarget, ResourceModel link)
+
+ ResourceLocator(ResourceModel parent, Method invocationTarget, ResourceModel link)
{
- this.invocationTarget = invocationTarget;
- this.uriTemplate = link.getUriTemplate();
+ super(link.getUriTemplate(), invocationTarget);
+ super.parent = parent;
this.link = link;
}
@@ -60,48 +55,6 @@
return true;
}
- void freeze()
- {
- // We need to know which param belongs to what regex group
- final Map<String, Integer> regexInfo = new HashMap<String, Integer>();
- UriParamHandler collectRegexInfo = new UriParamHandler()
- {
- public void newUriParam(int regexGroup, String paramName)
- {
- regexInfo.put(paramName, regexGroup);
- }
- };
-
- initFromUriTemplate(this.uriTemplate, collectRegexInfo);
-
- // Create ParameterBindig
- this.parameterBinding = new ParameterBinding(this.regexPattern);
-
- // Annotations on method parameters
- this.parameterBinding.registerParameterAnnotations(invocationTarget);
-
- // Additional info abpout the regex binding
- for(String paramName : regexInfo.keySet())
- {
- int group = regexInfo.get(paramName);
- this.parameterBinding.registerRegexGroupForParam(group, paramName);
- }
- }
-
- public ParameterBinding getParameterBinding() {
- return parameterBinding;
- }
-
- public Method getInvocationTarget() {
- return invocationTarget;
- }
-
- public OperationBinding getOperationBinding()
- {
- return new OperationBinding(this.invocationTarget);
- }
-
-
public String toString() {
return "ResourceLocator{uri="+uriTemplate+",
regex="+regexPattern+"}";
}
Modified: stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceMethod.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceMethod.java 2007-11-20
10:22:23 UTC (rev 5068)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceMethod.java 2007-11-20
11:30:56 UTC (rev 5069)
@@ -24,38 +24,31 @@
import org.jboss.rs.MethodHTTP;
import org.jboss.rs.util.Convert;
+import javax.activation.MimeType;
import javax.ws.rs.ConsumeMime;
import javax.ws.rs.ProduceMime;
-import javax.activation.MimeType;
-import java.lang.reflect.Method;
import java.lang.annotation.Annotation;
-import java.util.List;
+import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
+import java.util.List;
/**
+ * Resource mthod meta data.
+ *
* @author Heiko.Braun(a)jboss.com
* @version $Revision$
*/
-public class ResourceMethod extends AbstractRegexResolveable
-{
- private MethodHTTP methodHTTP;
- private String uriTemplate;
- private Method invocationTarget;
+public class ResourceMethod extends AbstractResourceOperation {
+ private MethodHTTP methodHTTP;
private List<MimeType> consumeMimeTypes = new ArrayList<MimeType>();
private List<MimeType> produceMimeTypes = new ArrayList<MimeType>();
- private ParameterBinding parameterBinding;
-
- private boolean frozen;
-
- ResourceMethod(MethodHTTP method, String uriTemplate, Method invocationTarget)
+ ResourceMethod(ResourceModel parent, MethodHTTP method, String uriTemplate, Method
invocationTarget)
{
- this.uriTemplate = uriTemplate;
+ super(uriTemplate, invocationTarget);
+ super.parent = parent;
this.methodHTTP = method;
- this.invocationTarget = invocationTarget;
}
public MethodHTTP getMethodHTTP()
@@ -90,50 +83,12 @@
return produceMimeTypes;
}
- public ParameterBinding getParameterBinding()
- {
- assert frozen;
- return parameterBinding;
- }
-
- public OperationBinding getOperationBinding()
- {
- return new OperationBinding(this.invocationTarget);
- }
-
void freeze()
{
- // We need to know which param belongs to what regex group
- final Map<String, Integer> regexInfo = new HashMap<String, Integer>();
- UriParamHandler collectRegexInfo = new UriParamHandler()
- {
- public void newUriParam(int regexGroup, String paramName)
- {
- regexInfo.put(paramName, regexGroup);
- }
- };
+ super.freeze();
- // setup the regex stuff and push uriParam info to ParameterBinding
- initFromUriTemplate(this.uriTemplate, collectRegexInfo);
-
// parse the mime annotations
initMimeTypes();
-
- // Create ParameterBindig
- this.parameterBinding = new ParameterBinding(this.regexPattern);
-
- // Annotations on method parameters
- this.parameterBinding.registerParameterAnnotations(invocationTarget);
-
- // Additional info abpout the regex binding
- for(String paramName : regexInfo.keySet())
- {
- int group = regexInfo.get(paramName);
- this.parameterBinding.registerRegexGroupForParam(group, paramName);
- }
-
- // Lock instance
- this.frozen = true;
}
private void initMimeTypes()
Modified: stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModel.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModel.java 2007-11-20
10:22:23 UTC (rev 5068)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModel.java 2007-11-20
11:30:56 UTC (rev 5069)
@@ -25,13 +25,13 @@
import java.util.List;
/**
+ * Resource meta data.
+ *
* @author Heiko.Braun(a)jboss.com
* @version $Revision$
*/
public class ResourceModel extends AbstractRegexResolveable
{
- private ResourceModel parent = null;
-
private String uriTemplate;
private Class invocationTarget;
@@ -46,7 +46,7 @@
public ResourceModel(ResourceModel parent, String uriTemplate, Class
invocationTarget)
{
- this.parent = parent;
+ super.parent = parent;
this.uriTemplate = uriTemplate;
this.invocationTarget = invocationTarget;
}
@@ -78,12 +78,7 @@
{
return !subResourceMethods.isEmpty() || !resourceLocators.isEmpty();
}
-
- ResourceModel getParent()
- {
- return parent;
- }
-
+
public Class getInvocationTarget()
{
return invocationTarget;
Modified:
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelParser.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelParser.java 2007-11-20
10:22:23 UTC (rev 5068)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceModelParser.java 2007-11-20
11:30:56 UTC (rev 5069)
@@ -64,43 +64,20 @@
{
for( Method m : resource.getInvocationTarget().getDeclaredMethods() )
- {
+ {
parseMethod(m, resource);
// todo: constructors
}
- // freeze resource
+ // freeze root resource
resource.freeze();
- log.debug("---");
- log.debug(resource);
-
- // freeze resource methods
- for(ResourceMethod rm : resource.getResourceMethods())
- {
- rm.freeze();
- log.debug(rm);
- }
-
- // log locators methods
- for(ResourceLocator loc : resource.getResourceLocator())
- {
- log.debug(loc);
- }
-
- // freeze sub resource methods
- for(ResourceMethod srm : resource.getSubResourceMethods())
- {
- srm.freeze();
- log.debug(srm);
- }
-
- log.debug("---");
+ logResourceTree(resource);
}
- private void parseMethod(Method method, ResourceModel resource)
- {
+ private void parseMethod(Method method, ResourceModel parentResource)
+ {
if(method.isAnnotationPresent(UriTemplate.class))
{
UriTemplate uri = method.getAnnotation(UriTemplate.class);
@@ -115,20 +92,24 @@
// sub resource method
Annotation a = method.getAnnotation(requestType);
resourceMethod = new ResourceMethod(
+ parentResource,
Convert.annotationToMethodHTTP(a), uri.value(), method
);
- resource.addSubResourceMethod(resourceMethod);
+
+ resourceMethod.freeze();
+ parentResource.addSubResourceMethod(resourceMethod);
}
}
// subresource locator
if(null == resourceMethod)
{
- ResourceModel subResource = new ResourceModel(resource, uri.value(),
method.getReturnType());
- ResourceLocator locator = new ResourceLocator(method, subResource);
- locator.freeze();
- resource.addSubResourceLocator(locator);
+ ResourceModel subResource = new ResourceModel(parentResource, uri.value(),
method.getReturnType());
+ ResourceLocator locator = new ResourceLocator(parentResource, method,
subResource);
+ locator.freeze();
+ parentResource.addSubResourceLocator(locator);
+
// recursive
parseInternal(subResource);
}
@@ -142,12 +123,41 @@
// resource method
Annotation a = method.getAnnotation(requestType);
ResourceMethod resourceMethod = new ResourceMethod(
+ parentResource,
Convert.annotationToMethodHTTP(a), "", method
);
- resource.addResourceMethod(resourceMethod);
+
+ resourceMethod.freeze();
+ parentResource.addResourceMethod(resourceMethod);
}
}
}
}
+ private void logResourceTree(ResourceModel resource)
+ {
+ log.debug("---");
+ log.debug(resource);
+
+ // freeze resource methods
+ for(ResourceMethod rm : resource.getResourceMethods())
+ {
+ log.debug(rm);
+ }
+
+ // log locators methods
+ for(ResourceLocator loc : resource.getResourceLocator())
+ {
+ log.debug(loc);
+ }
+
+ // freeze sub resource methods
+ for(ResourceMethod srm : resource.getSubResourceMethods())
+ {
+ log.debug(srm);
+ }
+
+ log.debug("---");
+ }
+
}
Modified:
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceResolver.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceResolver.java 2007-11-20
10:22:23 UTC (rev 5068)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceResolver.java 2007-11-20
11:30:56 UTC (rev 5069)
@@ -31,7 +31,7 @@
* Resolves resource methods from {@link
org.jboss.rs.runtime.RuntimeContext#getPath()}.<br>
* Once a set a of resource methods is identified, the resolver
* delegates to a {@link org.jboss.rs.media.ContentNegotiation} plugin
- * to do the fine grained media type matching.
+ * to do a more fine grained media type matching.
*
* @author Heiko.Braun(a)jboss.com
* @version $Revision$
@@ -45,6 +45,10 @@
private ContentNegotiation connegPlugin;
private Stack<ResourceLocator> visitedLocator = new
Stack<ResourceLocator>();
+
+ private Map<ResourceLocator, String> locatorWorkingPath = new
HashMap<ResourceLocator, String>();
+
+ private String methodWorkingPath;
/**
* Provides a resolver with the default content negotitation.
@@ -96,7 +100,7 @@
}
if(null == resourceMethod)
- throw new NoMethodException("No method for URI
'"+context.getPath());
+ throw new NoMethodException("No method matches URI
'"+context.getPath());
// gotcha
return resourceMethod;
@@ -119,11 +123,15 @@
resourceMethod = resolveResourceMethod(dfsEntry, nextUriToken);
// root didn't match, so recurse locators to find a resource
- if(null == resourceMethod)
+ if(resourceMethod!=null)
{
+ methodWorkingPath = nextUriToken;
+ }
+ else
+ {
ResourceMatch<ResourceModel> subResource = resolveByLocator(dfsEntry);
if(subResource!=null)
- resourceMethod = dfsResourceMatch(subResource);
+ resourceMethod = dfsResourceMatch(subResource);
}
return resourceMethod;
@@ -154,8 +162,10 @@
for(ResourceLocator loc : resourceMatch.model.getResourceLocator())
{
if(match.model == loc.field())
+ {
visitedLocator.add(0, loc);
-
+ locatorWorkingPath.put(loc, resourceMatch.qualifier.nextUriToken);
+ }
}
return match;
@@ -212,8 +222,19 @@
return connegPlugin.match(context, matches);
}
-
public Stack<ResourceLocator> getVisitedLocator() {
return visitedLocator;
}
+
+ public String getLocatorWorkingPath(ResourceLocator loc)
+ {
+ assert locatorWorkingPath.containsKey(loc);
+ return locatorWorkingPath.get(loc);
+ }
+
+ public String getMethodWorkingPath()
+ {
+ assert methodWorkingPath!=null;
+ return methodWorkingPath;
+ }
}
Modified: stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/Invocation.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/Invocation.java 2007-11-20
10:22:23 UTC (rev 5068)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/Invocation.java 2007-11-20
11:30:56 UTC (rev 5069)
@@ -46,7 +46,7 @@
// invocation metadata about the bean
private Class targetBean;
- private Object targetInstance;
+ private Object targetInstance;
public Invocation(RuntimeContext context)
{
Modified:
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/InvocationBuilder.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/InvocationBuilder.java 2007-11-20
10:22:23 UTC (rev 5068)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/InvocationBuilder.java 2007-11-20
11:30:56 UTC (rev 5069)
@@ -37,7 +37,7 @@
private List<InvocationModel> invocationModels = new
LinkedList<InvocationModel>();
/**
- * Add invocaiton model to an order list.
+ * Add invocaiton model to an ordered list.
*
* @param model
*/
Modified:
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/RuntimeContext.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/RuntimeContext.java 2007-11-20
10:22:23 UTC (rev 5068)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/RuntimeContext.java 2007-11-20
11:30:56 UTC (rev 5069)
@@ -34,6 +34,9 @@
import java.util.Stack;
/**
+ * Requesting a resource thorugh HTTP creates a runtime context<br>
+ * The context is associated with a set of {@link ResourceModel}
+ *
* @author Heiko.Braun(a)jboss.com
* @version $Revision$
*/
@@ -58,6 +61,8 @@
// The associated runtime model for a web context
private List<ResourceModel> rootResources;
+ private String workingPath;
+
public RuntimeContext(MethodHTTP requestMethod, URI uri, List<ResourceModel>
rootResources)
{
this.requestMethod = requestMethod;
@@ -147,4 +152,14 @@
{
return path;
}
+
+ public String getWorkingPath()
+ {
+ return workingPath;
+ }
+
+ public void setWorkingPath(String workingPath)
+ {
+ this.workingPath = workingPath;
+ }
}
Modified:
stack/native/branches/rest/src/test/java/org/jboss/test/rs/invocation/InvocationBuilderTestCase.java
===================================================================
---
stack/native/branches/rest/src/test/java/org/jboss/test/rs/invocation/InvocationBuilderTestCase.java 2007-11-20
10:22:23 UTC (rev 5068)
+++
stack/native/branches/rest/src/test/java/org/jboss/test/rs/invocation/InvocationBuilderTestCase.java 2007-11-20
11:30:56 UTC (rev 5069)
@@ -24,19 +24,13 @@
import junit.framework.TestCase;
import org.jboss.rs.ResourceRegistry;
import org.jboss.rs.MethodHTTP;
-import org.jboss.rs.runtime.RuntimeContext;
-import org.jboss.rs.runtime.InvocationBuilder;
-import org.jboss.rs.runtime.DefaultInvocationBuilder;
-import org.jboss.rs.runtime.Invocation;
-import org.jboss.rs.runtime.InvocationHandler;
-import org.jboss.rs.model.ResourceModel;
-import org.jboss.rs.model.ResourceModelParser;
-import org.jboss.rs.model.ResourceResolver;
-import org.jboss.rs.model.ResourceMethod;
+import org.jboss.rs.runtime.*;
+import org.jboss.rs.model.*;
import org.jboss.test.rs.WidgetList;
import javax.ws.rs.core.HttpHeaders;
import java.util.List;
+import java.util.Stack;
import java.net.URI;
/**
@@ -67,12 +61,37 @@
assertNotNull(method);
assertEquals("spec/{name}", method.getUriTemplate());
+ // evaluate locator stack
+ Object subResourceInstance = null;
+ Stack<ResourceLocator> visitedLocators = resolver.getVisitedLocator();
+ while(!visitedLocators.isEmpty())
+ {
+ ResourceLocator loc = visitedLocators.pop();
+
+ // adopt working path
+ context.setWorkingPath(resolver.getLocatorWorkingPath(loc));
+
+ InvocationBuilder builder = new DefaultInvocationBuilder();
+ builder.addInvocationModel(loc.getParameterBinding());
+ builder.addInvocationModel(loc.getOperationBinding());
+ Invocation locatorInvocation = builder.build(context);
+
+ InvocationHandler bridgeInvoker = new DefaultInvocationHandler();
+ subResourceInstance = bridgeInvoker.invoke(locatorInvocation);
+
+ }
+
// setup a builder
InvocationBuilder builder = new DefaultInvocationBuilder();
+ context.setWorkingPath(resolver.getMethodWorkingPath());
+
+ if(subResourceInstance!=null)
+ builder.addInvocationModel(new PresetInvocationTarget(subResourceInstance));
+
builder.addInvocationModel(method.getParameterBinding());
-
- // create an Invocation instance
+ builder.addInvocationModel(method.getOperationBinding());
Invocation invocation = builder.build(context);
+
Object parameterInstance = invocation.getParameterInstances().get(0);
assertTrue(parameterInstance!=null);
assertTrue("Wildcard parameter {name} not bound",
parameterInstance.equals("Bar"));
@@ -87,6 +106,7 @@
ResourceResolver resolver = ResourceResolver.newInstance(context);
ResourceMethod method = resolver.resolve();
+ context.setWorkingPath(resolver.getMethodWorkingPath());
assertNotNull(method);
assertEquals("special", method.getUriTemplate());