C# BsonDocument.Parse and invalid JSON - mongodb

Am I missing something? BsonDocument.Parse() appears to allow invalid JSON input where there is valid document before the invalid characters start?
For example I would consider invalid, but parses fine:
{
"_id": ObjectId("5731080e61737e37f84c848d")
}
This is not a typo(
What happens is it will parse the initial document and ignore anything after the initial document.
Surely it should treat this as invalid?
This is likely because the parser simply parses the first document then stops, but I'd argue if anything else is in the token stream it should be considered a fail.

BsonDocument.Parse() appears to allow invalid JSON input where there is valid document before the invalid characters start?
Yes, the JsonReader allows the reading of multiple top-level documents, in accordance with how many formats output a document per-line. Looks like the BsonDocument.Parse only read until the end of the first document, while the JsonReader knows there is more to read and waiting to read the next one (which will throw exception).
Surely it should treat this as invalid?
I've opened a ticket CSHARP-1676 for this case. Perhaps if there is an extra 'text' after the first document it should also throw FormatException. Feel free to watch/upvote the ticket to receive updates.
This is based on mongocsharpdriver v2.2.x
Update: The ticket has been resolved and targeted for release v2.2.5. See ticket for more information.

Related

How to fix rejecting invalid message: quickfix.IncorrectDataFormat

I have a QuickFIX initiator getting 1.23E-6 in tag 270 from market data. Then I saw QuickFIX/J throw the following error:
Rejecting invalid message: quickfix.IncorrectDataFormat: Incorrect data format for value, field=270
Any idea how to avoid the rejection and parse the correct value?
I also receive the scientific format of number from my 35=8 message in tag 44 (price), but I could just getString then convert them into BigDecimal with no issue.
The real problem here is that your counterparty should not be sending a scientific-notation value in that field. The field has type "Price", and per spec, that should be a whole or decimal number, thus that's what the QF engine is validating.
So, I don't know who your counterparty is, but maybe you want to check with their support and see if this might be a legit bug on their end.
(I can't explain why your 35=8/tag-44 message is being accepted. There must be a detail to your situation that I'm not aware of.)
If you need to work around this anyway: An easy cheat way to make the engine accept this message is to simply change the field's type to "string" in your Data Dictionary xml file. Of course, that will require you to always explicitly convert the string to BigDecimal, but it sounds like you will not have a problem with that.

Invalid signature returned when previewing 7digital track

I am attempting to preview a track via the 7digital api. I have utilised the reference app to test the endpoint here:-
http://7digital.github.io/oauth-reference-page/
I have specified what I consider to be the correct format query, as in:-
http://previews.7digital.com/clip/8514023?oauth_consumer_key=MY_KEY&country=gb&oauth_nonce=221946762&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1456932878&oauth_version=1.0&oauth_signature=c5GBrJvxPIf2Kci24pq1qD31U%2Bs%3D
and yet, regardless of what parameters I enter I always get an invalid signature as a response. I have also incorporated this into my javascript code using the same oauth signature library as the reference page and yet still get the same invalid signature returned.
Could someone please shed some light on what I may be doing incorrectly?
Thanks.
I was able to sign it using:
url = http://previews.7digital.com/clip/8514023
valid consumer key & consumer secret
field 'country' = 'GB'
Your query strings parameters look a bit out of order. For OAuth the base string, used to sign, is meant to be in alphabetical order, so country would be first in this case. Once generated it doesn't matter the order in the final request, but the above tool applies them back in the same order (so country is first).
Can you make sure there aren't any spaces around your key/secret? It doesn't appear to strip white space.
If you have more specific problems it may be best to get in touch with 7digital directly - https://groups.google.com/forum/#!forum/7digital-api

FIX Message Can 35=X does not have Symbol or SecID/SecIDSource

Hi I need help to understand, if 35=X message should contain Symbol/SecID within the repeating group.
The FIX Specification indicates that under the repeating group both 55 and 48/22 are optional.
I received a message from my client without a symbol tag, please help me undersatnd if that was a bad formed message
20150923-15:06:14.976 : 8=FIXT.1.19=33635=X34=19153349=SENDER52=20150923-15:06:14.63756=RECEIVER268=8279=0269=1270=99.609375271=289279=0269=1270=99.6171875271=241279=0269=1270=99.625271=154279=0269=1270=99.6328125271=139279=0269=0270=99.6015625271=268279=0269=0270=99.59375271=244279=0269=0270=99.5859375271=171279=0269=0270=99.578125271=21610=198
You are advised to treat the default FIX message and field definitions as a set of suggested definitions.
In practice, no commercial FIX counterparty uses these definitions as-is. Every counterparty I've connected to makes modifications, adding or removing fields from messages or groups, creating new fields, or sometimes adding entirely new messages. No counterparty supports every message and field.
When connecting to a counterparty, do not assume anything. Your counterparty should provide documentation on how they expect their interface to be used, and which messages and fields they will send and which they expect to receive from you.
You need to read their specs and modify your FIXnn.xml DataDictionary file to match what they will be sending you.
If their spec says they will send you Symbol and/or SecurityID in a 35=X message, you need to make sure your DD file matches that.
This page might be helpful to you. (It's technically for the C# QuickFIX/n, but the DD file is the same for all QF versions.)
http://quickfixn.org/tutorial/custom-fields-groups-and-messages.html

How does Accept HTTP header affect returned content when dealing with exceptions?

I have a REST resource that returns a jpeg image for example. The user sets as his accept header "image/jpeg." However a problem occurs on the server such as the image not existing. We want to return that exception to the user. Normally this exception can be returned as xml, json or html.
Is it acceptable behaviour to default to a html exception or should the return exception be as type jpeg and therefore gibberish?
As Celeda says in the comment above, it is perfectly fine to return a different content type than is declared in "Accept". The authors encourage the return of error messaged in the body when error conditions exist.
The Accept header is simply a way for the server to be guaranteed that it has generated a response that the client considers "acceptable". Errors are, by definition, not acceptable (at least they aren't to my clients :) so the format is kind of irrelevant. Certainly, jpeg gibberish wouldn't be acceptable.

How to find the #fragment in a URL in Lift

I'm pretty new to Lift, and one of the things I've been trying to find is how to, in the context of a snippet, find the '#' in the current page's URL. So if a user visits http://www.example.com/some/path/page#stuff then I would like to extract "stuff" from that. I've been googling and searching the API docs and have yet to find anything for this.
I don't think the part behind the # ever gets sent to the server in the first place.
That's what wikipedia has to say about it:
In URIs a hashmark # introduces the
optional fragment near the end of the
URL. The generic RFC 3986 syntax for
URIs also allows an optional query
part introduced by a question mark ?.
In URIs with a query and a fragment
the fragment follows the query. Query
parts depend on the URI scheme and are
evaluated by the server — e.g., http:
supports queries unlike ftp:.
Fragments depend on the document MIME
type and are evaluated by the client
(Web-browser). Clients are not
supposed to send URI-fragments to
servers when they retrieve a document,
and without help from a local
application (see below) fragments do
not participate in HTTP redirections.
I don't think the part behind the #
ever gets sent to the server in the
first place.
You are correct, sir. That is the entire point of the hash.
Dylan, you could do something from the Javascript side:
$.ajax( { data : { fragment : window.location.hash ...