openrasta/openrasta-core — Issue #42: Optional url query parameters does not work in the latest openrasta-core revision (https://github.com/openrasta/openrasta-core/commit/169e8e68f3bd9bc4f2a94b12993bcce513f392a1)
Author: MarkKharitonov
Created: 2011-11-11 17:18:56+00:00
State: open

Hi, consider the following trivial code:

public class Kuku
{
}

public class KukuHandler
{
public OperationResult Put(int id, [Optional, DefaultParameterValue(false)] bool a, Kuku dto)
{
Debug.WriteLine("{2} ---> Id = {0}, a = {1}{2}", id, a, Environment.NewLine);
return new OperationResult.MovedPermanently();
}
}

public class Configuration : IConfigurationSource
{
public void Configure()
{
using (OpenRastaConfiguration.Manual)
{
ResourceSpace.Uses.UriDecorator();
ResourceSpace.Uses.UriDecorator();

ResourceSpace.Has.ResourcesOfType()
.AtUri("Kuku/{id}?a={a}")
.HandledBy()
.AsJsonDataContract();
}
}
}

class Program
{
static void Main()
{
var stream = new MemoryStream(Encoding.ASCII.GetBytes("{}"));
var request = new InMemoryRequest
{
HttpMethod = "PUT",
Uri = new Uri("http://localhost/Kuku/123"),
Entity = new HttpEntity(new HttpHeaderDictionary(), stream)
{
ContentLength = stream.Length,
ContentType = MediaType.Json,
},
};
using (var host = new InMemoryHost(new Configuration()))
{
var response = host.ProcessRequest(request);
Debug.Assert(response.StatusCode == (int)HttpStatusCode.MovedPermanently);
}
}
}

Running this program fails the assertion. Here is the debug output:

9-[2011-11-11 17:16:51Z] Information(0) Registering host of type OpenRasta.Hosting.InMemory.InMemoryHost
9-[2011-11-11 17:16:52Z] Verbose(0) Using dependency resolver of type OpenRasta.DI.InternalDependencyResolver
9-[2011-11-11 17:16:52Z] Verbose(0) Registering host's root dependencies.
9-[2011-11-11 17:16:52Z] Information(0) Using dependency registrar of type OpenRasta.Configuration.DefaultDependencyRegistrar.
9-[2011-11-11 17:16:52Z] Verbose(0) Ignoring constructor, following dependencies didn't have a registration:OpenRasta.TypeSystem.Surrogates.ISurrogateBuilder[]
9-[2011-11-11 17:16:52Z] Verbose(0) Registering host's leaf dependencies.
9-[2011-11-11 17:16:52Z] Verbose(0) Using configuration source A.Configuration
9-[2011-11-11 17:16:52Z] Verbose(0) Ignoring constructor, following dependencies didn't have a registration:System.Func`1[System.Collections.Generic.IEnumerable`1[OpenRasta.Configuration.MetaModel.Handlers.IMetaModelHandler]]
9-[2011-11-11 17:16:52Z] Verbose(0) Ignoring constructor, following dependencies didn't have a registration:System.Diagnostics.TraceSource
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing the pipeline.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor ResponseEntityCodecResolverContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor ResponseEntityWriterContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor BootstrapperContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor HttpMethodOverriderContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor UriDecoratorsContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor ResourceTypeResolverContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor HandlerResolverContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor AuthenticationContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor AuthenticationChallengerContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Ignoring constructor, following dependencies didn't have a registration:OpenRasta.OperationModel.MethodBased.IMethodFilter[]
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor OperationCreatorContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor OperationFilterContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor OperationHydratorContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor OperationCodecSelectorContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor OperationInvokerContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor OperationResultInvokerContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor OperationInterceptorContributor.
9-[2011-11-11 17:16:52Z] Verbose(0) Initialized contributor EndContributor.
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor ResponseEntityCodecResolverContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor ResponseEntityWriterContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor HttpMethodOverriderContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor UriDecoratorsContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor ResourceTypeResolverContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor HandlerResolverContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor AuthenticationContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor AuthenticationChallengerContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor OperationCreatorContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor OperationFilterContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor OperationHydratorContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor OperationCodecSelectorContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor OperationInvokerContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor OperationResultInvokerContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor OperationInterceptorContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Start(1) Entering PipelineRunner: Initializing contributor EndContributor.
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Information(0) Contributor call chain has been processed and results in the following pipeline:
9-[2011-11-11 17:16:52Z] Information(0) 0 BootstrapperContributor
9-[2011-11-11 17:16:52Z] Information(0) 1 HttpMethodOverriderContributor
9-[2011-11-11 17:16:52Z] Information(0) 2 AuthenticationContributor
9-[2011-11-11 17:16:52Z] Information(0) 3 UriDecoratorsContributor
9-[2011-11-11 17:16:52Z] Information(0) 4 ResourceTypeResolverContributor
9-[2011-11-11 17:16:52Z] Information(0) 5 HandlerResolverContributor
9-[2011-11-11 17:16:52Z] Information(0) 6 OperationCreatorContributor
9-[2011-11-11 17:16:52Z] Information(0) 7 OperationFilterContributor
9-[2011-11-11 17:16:52Z] Information(0) 8 OperationCodecSelectorContributor
9-[2011-11-11 17:16:52Z] Information(0) 9 OperationHydratorContributor
9-[2011-11-11 17:16:52Z] Information(0) 10 OperationInterceptorContributor
9-[2011-11-11 17:16:52Z] Information(0) 11 OperationInvokerContributor
9-[2011-11-11 17:16:52Z] Information(0) 12 OperationResultInvokerContributor
9-[2011-11-11 17:16:52Z] Information(0) 13 ResponseEntityCodecResolverContributor
9-[2011-11-11 17:16:52Z] Information(0) 14 AuthenticationChallengerContributor
9-[2011-11-11 17:16:52Z] Information(0) 15 ResponseEntityWriterContributor
9-[2011-11-11 17:16:52Z] Information(0) 16 EndContributor
9-[2011-11-11 17:16:52Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:52Z] Information(0) Pipeline has been successfully initialized.
9-[2011-11-11 17:16:58Z] Verbose(0) Incoming host request for http://localhost/Kuku/123
9-[2011-11-11 17:16:58Z] Verbose(0) Adding communication context data
9-[2011-11-11 17:16:58Z] Warning(0) Contributor call for BootstrapperContributor had a null Action.
9-[2011-11-11 17:16:58Z] Start(1) Entering PipelineRunner: Executing contributor HttpMethodOverriderContributor.OverrideHttpVerb
9-[2011-11-11 17:16:58Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:58Z] Start(1) Entering PipelineRunner: Executing contributor AuthenticationContributor.AuthoriseRequest
9-[2011-11-11 17:16:58Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:58Z] Start(1) Entering PipelineRunner: Executing contributor UriDecoratorsContributor.ProcessDecorators
9-[2011-11-11 17:16:58Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:58Z] Start(1) Entering PipelineRunner: Executing contributor ResourceTypeResolverContributor.ResolveResource
9-[2011-11-11 17:16:58Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:58Z] Start(1) Entering PipelineRunner: Executing contributor HandlerResolverContributor.ResolveHandler
9-[2011-11-11 17:16:58Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:58Z] Start(1) Entering PipelineRunner: Executing contributor OperationCreatorContributor.CreateOperations
9-[2011-11-11 17:16:58Z] Verbose(0) Created operation named Put with signature KukuHandler::Put(Int32 id, Boolean a, Kuku dto)
9-[2011-11-11 17:16:58Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:16:58Z] Start(1) Entering PipelineRunner: Executing contributor OperationFilterContributor.ProcessOperations
9-[2011-11-11 17:16:58Z] Verbose(0) Found 1 operation(s) with a matching name.
9-[2011-11-11 17:16:58Z] Verbose(0) Found 0 operation(s) with matching [HttpOperation] attribute.
9-[2011-11-11 17:16:58Z] Verbose(0) No resource or no uri name. Not filtering.
9-[2011-11-11 17:17:00Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:17:00Z] Start(1) Entering PipelineRunner: Executing contributor OperationCodecSelectorContributor.ProcessOperations
9-[2011-11-11 17:17:00Z] Information(0) Operation KukuHandler::Put(Int32 id, Boolean a, Kuku dto) selected with 2 required members and 1 optional members, with codec JsonDataContractCodec with score 1.
9-[2011-11-11 17:17:00Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:17:00Z] Start(1) Entering PipelineRunner: Executing contributor OperationHydratorContributor.ProcessOperations
9-[2011-11-11 17:17:00Z] Information(0) Operation KukuHandler::Put(Int32 id, Boolean a, Kuku dto) was selected with a codec score of 1
9-[2011-11-11 17:17:00Z] Information(0) Loaded codec OpenRasta.Codecs.JsonDataContractCodec
9-[2011-11-11 17:17:00Z] Verbose(0) Switching to full object media type reading.
A first chance exception of type 'System.FormatException' occurred in System.Xml.dll
A first chance exception of type 'System.Xml.XmlException' occurred in System.Runtime.Serialization.dll
A first chance exception of type 'System.Runtime.Serialization.SerializationException' occurred in System.Runtime.Serialization.dll
9-[2011-11-11 17:17:00Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:17:00Z] Verbose(0) Pipeline is in RenderNow mode.
9-[2011-11-11 17:17:00Z] Start(1) Entering PipelineRunner: Executing contributor OperationResultInvokerContributor.RunOperationResult
9-[2011-11-11 17:17:00Z] Information(0) Executing OperationResult OperationResult: type=MethodNotAllowed, statusCode=405.
9-[2011-11-11 17:17:00Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:17:00Z] Start(1) Entering PipelineRunner: Executing contributor ResponseEntityCodecResolverContributor.FindResponseCodec
9-[2011-11-11 17:17:00Z] Information(0) No response codec was searched for. The response entity is null or a response codec is already set.
9-[2011-11-11 17:17:00Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:17:00Z] Start(1) Entering PipelineRunner: Executing contributor AuthenticationChallengerContributor.ChallengeIfUnauthorized
9-[2011-11-11 17:17:00Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:17:00Z] Start(1) Entering PipelineRunner: Executing contributor ResponseEntityWriterContributor.WriteResponse
9-[2011-11-11 17:17:00Z] Verbose(0) There was no response entity, not rendering.
9-[2011-11-11 17:17:00Z] Verbose(0) Writing http headers.
9-[2011-11-11 17:17:00Z] Stop(1) Exiting PipelineRunner
9-[2011-11-11 17:17:00Z] Information(0) Pipeline finished.
9-[2011-11-11 17:17:00Z] Verbose(0) Request finished.

Thanks.