Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenRasta URI Maps to Wrong Method and returns inconsistent http status codes

I'm using OpenRasta framework in a .net service and I have two methods as below in the handler

public OperationResult Get(int Number)
{
// Do some operation and get an entity
  return new OperationResult.OK(Single-MyResource);
}

public OperationResult GetQ()
{
// Do some operation and get an entity
  return new OperationResult.OK(List-Of-MyResource);
}

My configuration looks like below

ResourceSpace.Has.ResourcesOfType<MyResource>()
          .AtUri("/MyResource/{Id}")
          .And.AtUri("/MyResource")
          .HandledBy<MyResourceHandler>()
          .AsJsonDataContract() 
          .And.AsXmlDataContract()


 ResourceSpace.Has.ResourcesOfType<IList<MyResource>>()
         .AtUri("/MyResources") 
         .HandledBy<MyResourceHandler>()
         .AsJsonDataContract()
         .And.AsXmlDataContract();

HttpMethod: GET AcceptHeader: "application/json" URI: http://testDomain.com/MyResource/

The above request gives me the List of MyResource , same as what i get for the below Request

HttpMethod: GET AcceptHeader: "application/json" URI: http://testDomain.com/MyResources/

After changing Configuration to

ResourceSpace.Has.ResourcesOfType<MyResource>()
          .AtUri("/MyResource/{Id}")
          .And.AtUri("/MyResource").Named("MyResource")
          .HandledBy<MyResourceHandler>()
          .AsJsonDataContract() 
          .And.AsXmlDataContract()

and making appropriate change in handler i.e

[HttpOperation(HttpMethod.GET, ForUriName = "MyResource")]

OpenRasta returns 415 http Status Code.

The above is not consistent again.

For my other Resource for similar configuration as above OpenRasta throws 403 http Status Code

like image 313
sham Avatar asked Nov 24 '25 02:11

sham


1 Answers

The first case is correct. You share a handler between the two. As such, when the handler is looked at to select a method, there is one candidate with a parameter and one without. When you to to /MyResource, it finds the handler and find the method that has no parameter. This is expected behavior.

In your second configuration, there's something missing there. A 415 is when the request data is not understood by OR. As it's a GET, there should be no request media type to deal with. This one will require a debug log to check what is going on. Are you sure your request is not coming with some request data and a Content-Type?

like image 166
SerialSeb Avatar answered Nov 27 '25 17:11

SerialSeb