Results 1 to 9 of 9

Thread: Spring.Web.Mvc4/WebAPI controller issue with O Data queries

  1. #1
    Join Date
    Jun 2012
    Posts
    2

    Default Spring.Web.Mvc4/WebAPI controller issue with O Data queries

    Hi there,

    I encountered an issue with the use of o data queries in conjunction with spring instantiated WebAPI controllers.

    If I modify my application to derive from SpringMvcApplication then I immediately lose the o data query capability. The test urls that I attempt do not throw an exception but do not execute the o data query e.g. filter.

    On closer examination I found that a number of what look like key properties of the spring instantiated controller are null (i.e. properties of the base ApiController). These include Configuration (System.Web.Http.HttpConfiguration), ControllerContext (System.Web.Http.Controllers.HttpControllerContext ), Request (System.Net.Http.HttpRequestMessage) and Url (System.Web.Http.Routing.UrlHelper). I suspect that the o data filter cannot work due to the null HttpRequestmessage. I compared to a non-spring enabled WebAPI project.

    Would that be correct?

    So I guess given that spring, in general, instantiates the objects on start up of the application then the the request message could not yet actually be available? So does that mean that the controller objects should be lazy loaded at the time of the request?

    Does this make sense?

    Thanks
    Martin

  2. #2
    Join Date
    Apr 2012
    Posts
    13

    Default

    Hi there,

    with today sources from GitHub I actually get the following exception when applying OData filters:

    Code:
    Spring.Context.ApplicationContextException
    
    {"No context registered. Use the 'RegisterContext' method or the 'spring/context' section from your configuration file."}
    
    in ContextRegistry.cs
       public static IApplicationContext GetContext()
    Cheers,
    --
    Dante

  3. #3
    Join Date
    Jul 2010
    Posts
    245

    Default

    Can you post a brief snippet of exactly what it is that you're doing when you get this error? A sample controller action that causes it, perhaps --?

    Thanks,
    -Steve B.

  4. #4
    Join Date
    Apr 2012
    Posts
    13

    Default

    Hi there,

    To reproduce the issue simply add [Queryable] attribute to an ApiController and call it with an OData uri:

    out of my hat
    Code:
        public class CampaignController : ApiController
        {
            // GET /api/campaign
            [Queryable]
            public IQueryable<Campaign> Get()
            {
                    var Campaigns = new Campaign[]
                    {
                            new Campaign { Year = 2009 },
                            new Campaign { Year = 2010 },
                            new Campaign { Year = 2011 },
                            new Campaign { Year = 2012 },
                    };
    
                    return Campaigns.AsQueryable();
            }
    
            ...
    with fiddler or something similar call it with an OData uri such as

    Code:
    http://localhost:3122/api/Campaign?$skip=1&$top=2
    
    or
    
    http://localhost:3122/api/Campaign?$filter=Year%20eq%202010
    Thank you,
    --
    dante

  5. #5
    Join Date
    Jul 2010
    Posts
    245

    Default

    Can you verify which version of MVC4 you are using (e.g., BETA, RC, your own build off the MVC trunk, etc.)? There have been some changes to the IQueryable support in MVC4 across each of these and I want to ensure that we're testing against the same version you are seeing this with.

    Thanks for catching this; we (obviously) want to address it properly before SPRNET 2.0 goes GA.

    -Steve B.

  6. #6
    Join Date
    Apr 2012
    Posts
    13

    Default

    It should be plain RC.

    Just checked:

    Assembly System.Web.Mvc
    D:\Sources\Panflute\Sources\Panflute\packages\Micr osoft.AspNet.Mvc.4.0.20505.0\lib\net40\System.Web. Mvc.dll
    --
    dante

  7. #7
    Join Date
    Jul 2010
    Posts
    245

    Default

    Just FYI, we've looked into this and it actually appears to be unrelated to the use of OData filters and is instead more fundamental to the way we're providing the WebAPI with its DependencyResolver (more specifically what happens when the WebAPI attempts to *dispose* of the DependencyResolver). We're looking into this now (and will of course also confirm that the fix properly supports OData filters as well).

    Watch this thread for updated info.

    -Steve B.

  8. #8
    Join Date
    Apr 2012
    Posts
    13

    Default

    Hi there,

    Thank you very much for all your efforts.
    --
    dante

  9. #9
    Join Date
    Jul 2010
    Posts
    245

    Default

    No problem. BTW, this is now fixed in commit https://github.com/SpringSource/spri...a1116dc7dbd394 and has been pushed to the github remote now. As with most things, its a simple fix once I realized the error. The problem was indeed broader than just Odata/IQueryable support but I've also now added an 'OdataController' to the examples/spring.web.mvc4quickstart project that demonstrates that OData/IQueryable support is properly working under our MVC4 support.

    Although its completely unrelated to this issue you were reporting re: the unregistered ApplicationContext, do be advised that if you are using the RC bits for MVC4 there is a bug in the RC that affects the webapi dependency resolution (see http://aspnetwebstack.codeplex.com/workitem/212 for more details). As I say, this MVC4 RC bug is unrelated to your reported issue here but I'm just advising everyone using the RC about this issue b/c if it hits you it will probably take you some time to discern what's really wrong. Its already fixed in the MVC4 trunk/master but the RC bits do contain the erroneous code.

    Please let us know if the fix we introduced in https://github.com/SpringSource/spri...a1116dc7dbd394 properly addresses your issue. If so, that should be the final issue that needs to be addressed before we can go ahead and release the official M1 preview bits for SPRNET-2.0.

    Thanks again for reporting this and working with us to help us pin down the cause~!

    -Steve B.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •