This week's book giveaway is in the Java in General forum. We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line! See this thread for details.
So im trying to send a string that is essentially an xml document. On the client side the string length is larger then what i get on the serverside which causes problems in my application. The client side string has newline and carriage returns but when recieved in the webservice i only see the newlines which account for the missing characters. I do not want to URL encode the string since this would be suboptimal in my situation. what other options do i have to ensure exactly what i send it received in the web service??
On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.
Nothing to do with SOAP, particularly. As it says in section 2.11 of the XML Recommendation:
"To simplify the tasks of applications, the XML processor MUST behave as if it normalized all line breaks in external parsed entities (including the document entity) on input, before parsing, by translating both the two-character sequence #xD #xA and any #xD that is not followed by #xA to a single #xA character."
thanks for the infor. Im not processing the xml here, im just essentially reading a txt file and sending the string result accross to the webservice. The value can be any arbitrary string and in this specific case it just happens to be as a result of reading an xml file. So do you mean to say that when i read a file that is xml i most do some post/pre processing?
so there is no way to send a string across soap that contains a carriage return and have it preserve the carriage return? Basically i want to store exactly what is passed in the form it is passed so filtering out the carriage return means when i return the string to the user when they try to retrieve it , it will not be exactly what they entered... is this because of something SOAP is doing?
May I ask what the purpose of the application is, or at least what the purpose of sending an entire XML document as a String object would be? I've done something similar in the past, and admit, it isn't the best solution. JAXB marshalling and unmarshalling is the best way, in my opinion, to send XML data that represents objects. Even in the application i mentioned above, we still used JAXB to unmarshall the String containing the XML.
I suppose CDATA sections are an option.. basically the application allows you to store annotations ... kinda like a comment which can be any arbritary string of any size (with db limitations). The webservice call is passed an object which is the serialized version of the object that holds the string... something like "literal(length(5)value(hello))" which then it deserializes back into an object. To parse the serialisation we break up the string into tokens by the "(" and the ")".. and i use the length field to determine how long the string was so that i can extract the value correctly ( in case the string had a ")" in it or spaces etc the length param tells me the exact expected length). In this specific case the client is sending over a very large string which they created by parsing an xml doc like isaid..turns out it contains "\r \n" at the end of every line. So when i serialize on the client side the length includes the "\r" but when i desrialize on the server side the length is incorrect and my parsing breaks down. I suppose i can tell the client that we dont support "\r" in the strings so they would have to filter them out... or wrap them in CDATA tags... just wierd that its being striped out anyways... i think i know how to get around this.. but id like to know WHY its doing it