internal override string Serialize(RepresentationFormat format, URI baseUri, ExtensionInjector extensions) { MappingWriter writer = format.SerializeMapping(Type); Serializer.InjectExtensions(writer, this, baseUri, extensions); Serialize(new MappingSerializer(writer, baseUri, extensions)); writer.Done(); return(format.Complete(writer)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void write(org.codehaus.jackson.JsonGenerator out, org.neo4j.server.rest.repr.RepresentationFormat format, Object value, TransactionStateChecker checker) throws java.io.IOException private void Write(JsonGenerator @out, RepresentationFormat format, object value, TransactionStateChecker checker) { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: if (value instanceof java.util.Map<?, ?>) if (value is IDictionary <object, ?> ) { @out.writeStartObject(); try { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: for (java.util.Map.Entry<String, ?> entry : ((java.util.Map<String, ?>) value).entrySet()) foreach (KeyValuePair <string, ?> entry in ((IDictionary <string, ?>)value).SetOfKeyValuePairs()) { @out.writeFieldName(entry.Key); write(@out, format, entry.Value, checker); } } finally { @out.writeEndObject(); } }
internal abstract string Serialize(RepresentationFormat format, URI baseUri, ExtensionInjector extensions);
internal override string serialize(RepresentationFormat format, URI baseUri, ExtensionInjector extensions) { return(""); }
// Asynchronously gets the representation of a resource from the Web API. // See the method definition in the IOAuth2ServerAccess interface for a full description. public async Task<Tuple<String, String>> GetResourceAsync(String resourceUri, String accessToken, RepresentationFormat format) { // Check the args. if (resourceUri == null) throw new ArgumentNullException("resourceUri"); if (accessToken == null) throw new ArgumentNullException("accessToken"); if (String.IsNullOrWhiteSpace(resourceUri)) throw new ArgumentException("The resource URI is empty or whitespace.", "resourceUri"); if (String.IsNullOrWhiteSpace(accessToken)) throw new ArgumentException("The access token is empty or whitespace.", "accessToken"); if ((format != RepresentationFormat.Json) && (format != RepresentationFormat.Xml)) throw new ArgumentException("The representation format is invalid.", "format"); // Get the resource from the Web API. HttpClient httpClient = null; try { httpClient = new HttpClient(); // Set the Authorization header to identify the user. The access token is not base64-encoded here // because it is expected to already be base64-encodedi. httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); // Set the Accept header to indicate whether we want a JSON or XML based resource representation. httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue( (format == RepresentationFormat.Json) ? "application/json" : "application/xml" )); // Send a GET request for the resource and await the response. var response = await httpClient.GetAsync(resourceUri); // According to the status of the response... switch (response.StatusCode) { case HttpStatusCode.OK: { var representation = await response.Content.ReadAsStringAsync(); var mediaType = response.Content.Headers.ContentType.MediaType; return Tuple.Create(representation, mediaType); } // We will assume that any other status code is an error status code. default: { // Get error information from the reason phrase. var errorInfo = GetErrorInformation(response.ReasonPhrase); // Has the access token expired (or is it invalid)? var accessTokenRejected = IsAccessTokenExpiredOrInvalid(response); // Was the request blocked/forbidden due to a Fair Usage Policy violation? var blockedDueToFup = IsRequestBlockedDueToFairUsagePolicy(response, errorInfo.Item2); // recognised Web API error code (or null) // Throw WebApiException, specifying as much information about the error as possible. throw new WebApiException(errorInfo.Item1) // exception message = error message { StatusCode = response.StatusCode, // status code ErrorCode = errorInfo.Item2, // recognised Web API error code (or null) UnrecognisedErrorCode = errorInfo.Item3, // unrecognised Web API error code (or null) AccessTokenExpiredOrInvalid = accessTokenRejected, RequestForbiddenDueToFairUsagePolicyViolation = blockedDueToFup }; } } } catch (WebApiException) { // Re-throw this exception. throw; } catch (Exception ex) { // Log the error. var errorMessage = "Error on talking to the Web API. " + ex.ToString(); System.Diagnostics.Debug.WriteLine(errorMessage); _logging.LogError(errorMessage); throw new WebApiException("Failed to talk to the Revolution Web API.", ex); } finally { if (httpClient != null) httpClient.Dispose(); } }
public EntityOutputFormat(RepresentationFormat format, URI baseUri, ExtensionInjector extensions) : base(format, baseUri, extensions) { }