SYNAPSE-809 is about a bug in getTextPayload. Since that method is designed to load the content of an element into a String object, the correct solution is to use OMElement#getText() because it does exactly that.
However, loading a CSV file into a String before passing it to Smooks is not a smart solution because Smooks is able read from a stream. Therefore, getTextAsStream is a better solution, assuming that it is used _instead of_ getTextPayload (and not inside getTextPayload). Andreas On Mon, Oct 31, 2011 at 06:29, Jasintha Dasanayaka <[email protected]> wrote: > Hi Andreas > > Here you mention that better solution is to use > ElementHelper#getTextAsStream method but I saw in the synapse > jira(SYNAPSE-809) you had made a comment on that > "ElementHelper#getTextAsStream is useless here." I am little bit confusing > about this could you please explain this > > /Jasintha > > On Thu, Oct 27, 2011 at 2:17 AM, Andreas Veithen <[email protected]> > wrote: >> >> Jasintha, >> >> That method assumes that the object model was produced by a coalescing >> parser, which is not the case here. It should use OMElement#getText() >> instead of OMText#getText(). However, that defeats the purpose of the >> PlainTextBuilder/WrappedTextNodeOMDataSourceFromReader stuff because >> it would read the entire CSV file into memory (Given the method >> signature of PayloadHelper#getTextPayload, it has no other choice). >> The better solution is to use ElementHelper#getTextAsStream from the >> Axiom API because that method enables streaming. >> >> Andreas >> >> On Wed, Oct 26, 2011 at 06:55, Jasintha Dasanayaka <[email protected]> >> wrote: >> > Hi Andreas >> > >> > We are using smooks meditor in ESB to convert csv file to xml but we >> > couldn't convert the whole file into xml it's only convert 4KB size of >> > data >> > .We identified that other part of the massage has lost within the >> > synapse >> > class called "PayloadHelper.java" method name is >> > "getTextPayload(SOAPEnvelope envelope)" that method uses above way to >> > get >> > axiom child >> > >> > you can find this code in synapse trunk class "PayloadHelper.java" >> > line >> > number 199 >> > >> > Thanks & Regards >> > /Jasintha >> > >> > On Tue, Oct 25, 2011 at 11:58 PM, Andreas Veithen >> > <[email protected]> wrote: >> >> >> >> Jasintha, >> >> >> >> The sample code doesn't really show what you are trying to achieve. >> >> Obviously you wouldn't use Axiom to read the content of a file into a >> >> String, so what is the actual use case? >> >> >> >> Andreas >> >> >> >> On Tue, Oct 25, 2011 at 06:48, Jasintha Dasanayaka >> >> <[email protected]> >> >> wrote: >> >> > Hi Andreas >> >> > >> >> > According to you Answer in issue[1] I have modified the method as >> >> > follows >> >> > is this the correct way to do this If not could you please suggest a >> >> > correct >> >> > way >> >> > >> >> > >> >> > >> >> > private static String readFile(String file) throws IOException, >> >> > XMLStreamException { >> >> > >> >> > FileInputStream fin = new FileInputStream(file); >> >> > OMFactory factory = OMAbstractFactory.getOMFactory(); >> >> > String charSetEnc = >> >> > BuilderUtil.getCharSetEncoding("text/plain"); >> >> > QName wrapperQName = BaseConstants.DEFAULT_TEXT_WRAPPER; >> >> > Reader reader; >> >> > try { >> >> > reader = new InputStreamReader(fin, charSetEnc); >> >> > } catch (UnsupportedEncodingException ex) { >> >> > throw new AxisFault("Unsupported encoding: " + >> >> > charSetEnc, >> >> > ex); >> >> > } >> >> > OMElement om = new OMSourcedElementImpl(wrapperQName, >> >> > factory, >> >> > new >> >> > WrappedTextNodeOMDataSourceFromReader(wrapperQName, >> >> > reader)); >> >> > om.serialize(System.out); >> >> > >> >> > /* before modify >> >> > OMNode textNode = om.getFirstOMChild(); >> >> > OMText text = (OMText) textNode; >> >> > return text.getText(); >> >> > */ >> >> > >> >> > StringBuffer buffer = new StringBuffer(); >> >> > Iterator<OMNode> iterator = om.getChildren(); >> >> > while(iterator.hasNext()){ >> >> > OMText text = (OMText) iterator.next(); >> >> > buffer.append(text.getText()); >> >> > } >> >> > >> >> > return buffer.toString(); >> >> > >> >> > } >> >> > >> >> > >> >> > Thanks & Regards >> >> > /Jasintha >> >> > >> >> > [1]-https://issues.apache.org/jira/browse/AXIOM-395 >> >> > >> >> > -- >> >> > Thanks & Regards >> >> > >> >> > Jasintha Dasanayake >> >> > Software Engineer. >> >> > >> >> > WSO2 Inc,|http://wso2.com >> >> > lean . enterprise . middleware >> >> > >> >> > mobile +94 772 916 596 , >> >> > >> >> > >> >> > >> >> >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: [email protected] >> >> For additional commands, e-mail: [email protected] >> >> >> > >> > >> > >> > -- >> > Thanks & Regards >> > >> > Jasintha Dasanayake >> > Software Engineer. >> > >> > WSO2 Inc,|http://wso2.com >> > lean . enterprise . middleware >> > >> > mobile +94 772 916 596 , >> > >> > >> > >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> > > > > -- > Thanks & Regards > > Jasintha Dasanayake > Software Engineer. > > WSO2 Inc,|http://wso2.com > lean . enterprise . middleware > > mobile +94 772 916 596 , > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
