public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags) { MediaTypeHeaderValue mediaType = UriMtHelper.GetJsonMediaType(helper.GetActionResultMediaType()); helper.AddActionResultRepresentationParameter(mediaType, flags); return(mediaType); }
private void ValidateOutgoingJsonMediaType() { var contentType = Representation.GetContentType(); List <NameValueHeaderValue> incomingParameters = requestMessage.Headers.Accept.SelectMany(a => a.Parameters).ToList(); string[] incomingProfiles = incomingParameters.Where(nv => nv.Name == "profile").Select(nv => nv.Value).Distinct().ToArray(); string[] outgoingProfiles = contentType != null?contentType.Parameters.Where(nv => nv.Name == "profile").Select(nv => nv.Value).Distinct().ToArray() : new string[] { }; if (incomingProfiles.Any() && outgoingProfiles.Any() && !outgoingProfiles.Intersect(incomingProfiles).Any()) { if (outgoingProfiles.Contains(UriMtHelper.GetJsonMediaType(RepresentationTypes.Error).Parameters.First().Value)) { // outgoing error so even though incoming profiles does not include error representation return error anyway but with 406 code HttpStatusCode = HttpStatusCode.NotAcceptable; } else { // outgoing profile not included in incoming profiles and not already an error so throw a 406 throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable)); } } }
public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags) { MediaTypeHeaderValue mediaType = UriMtHelper.GetJsonMediaType(RepresentationTypes.CollectionValue); return(mediaType); }
public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags) { return(UriMtHelper.GetJsonMediaType(helper.GetTypeMemberMediaType())); }
public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags) { return(UriMtHelper.GetJsonMediaType(RepresentationTypes.User)); }
private void MapToRepresentation(Exception e, HttpRequestMessage req) { if (e is WithContextNOSException) { ArgumentsRepresentation.Format format = e is BadPersistArgumentsException ? ArgumentsRepresentation.Format.Full : ArgumentsRepresentation.Format.MembersOnly; RestControlFlags flags = e is BadPersistArgumentsException ? ((BadPersistArgumentsException)e).Flags : RestControlFlags.DefaultFlags(); var contextNosException = e as WithContextNOSException; if (contextNosException.Contexts.Any(c => c.ErrorCause == Cause.Disabled || c.ErrorCause == Cause.Immutable)) { representation = NullRepresentation.Create(); } else if (contextNosException.ContextSurface != null) { representation = ArgumentsRepresentation.Create(req, contextNosException.ContextSurface, format, flags, UriMtHelper.GetJsonMediaType(RepresentationTypes.BadArguments)); } else if (contextNosException.Contexts.Any()) { representation = ArgumentsRepresentation.Create(req, contextNosException.Contexts, format, flags, UriMtHelper.GetJsonMediaType(RepresentationTypes.BadArguments)); } else { representation = NullRepresentation.Create(); } } else if (e is ResourceNotFoundNOSException || e is NotAllowedNOSException || e is PreconditionFailedNOSException || e is PreconditionHeaderMissingNOSException || e is NoContentNOSException) { representation = NullRepresentation.Create(); } else { representation = ErrorRepresentation.Create(e); } }