RE: [Servingxml-help] Content is notallowed in prolog?
Brought to you by:
danielaparker
From: Akhil S. S. <ak...@ma...> - 2006-02-04 07:22:52
|
=20=0D=0A=0D=0AI'm sorry to be such a bother. I am trying to embed the serv= ingXML=0D=0Acomponent into ServiceMix JMS components. Mainly so I can send = a=0D=0Atextstring and convert it into=20=0D=0A=0D=0AXML before it enters th= e JBI bus. The code I came up with is=0D=0A=0D=0A=20=0D=0A=0D=0A = AppContext appContext =3D new=0D=0ADefaultAppConte= xt(APPLICATION_NAME,=20=0D=0A=0D=0A=20=0D=0Adriver.getResources(), driver.g= etNameTable());=0D=0A=0D=0A ServiceConte= xt serviceContext =3D new=0D=0ADefaultServiceContext(appContext, "servingxm= l");=0D=0A=0D=0A =20=0D=0A=0D=0A = Name serviceName =3D=0D=0AName.parse(serviceCont= ext, SERVICE_SOURCE_NAME);=0D=0A=0D=0A =0D= =0A=0D=0A StreamSource defaultStreamSour= ce =3D=0D=0Anew StringStreamSource(text);=0D=0A=0D=0A = ByteArrayOutputStream boss =3D new=0D=0AByteArrayOutputStream= ();=0D=0A=0D=0A StreamSink defaultStream= Sink =3D new=0D=0AOutputStreamSinkAdaptor(boss);=0D=0A=0D=0A = =20=0D=0A=0D=0A Flow= flow =3D new=0D=0AFlowImpl(defaultStreamSource, defaultStreamSink);=0D=0A=0D= =0A =20=0D=0A=0D=0A = RecordBuilder recordBuilder =3D new=0D=0ARecordBuilder(System= Constants.PARAMETERS_TYPE_NAME);=0D=0A=0D=0A = // Add some parameters, if any =20=0D=0A=0D=0A = Record parameters =3D=0D=0ArecordBuilder.toRecord();=0D=0A=0D=0A= =20=0D=0A=0D=0A = Service service =3D=0D=0A(Service)appContext.getResources().look= upServiceComponent(Service.class,=0D=0AserviceName);=0D=0A=0D=0A = if (service =3D=3D null) {=0D=0A=0D=0A = throw new=0D=0AServingXmlException("Can= not find service " + serviceName);=0D=0A=0D=0A = }=0D=0A=0D=0A service.execute(ser= viceContext,=0D=0Aparameters, flow);=0D=0A=0D=0A = =20=0D=0A=0D=0A boss.flush();=0D= =0A=0D=0A String tempString =3D new=0D=0A= String(boss.toByteArray());=0D=0A=0D=0A = source =3D new=0D=0ABytesSource(tempString.trim().getBytes());=0D=0A=0D=0A =0D= =0A=0D=0AThe main problem I faced is that there is a file sink but no strin= g=0D=0Asink. So I have tried to put the output of servingXML into a bytestr= eam=0D=0Aand convert that into a string but since that be the problem can y= ou=0D=0Aadvise on a possible workaround=3F Or would coming up with a String= Sink be=0D=0Aa better option=3F=0D=0A=0D=0A=20=0D=0A=0D=0AThanks=0D=0A=0D=0A= Akhil Srinivasan =20=0D=0A=0D=0A=20=0D=0A=0D=0A ___= __ =20=0D=0A=0D=0AFrom: Daniel Parker [mailto:dan...@sy...] =0D= =0ASent: Saturday, February 04, 2006 9:12 AM=0D=0ATo: Akhil S. Srinivasan=0D= =0ACc: ser...@li...=0D=0ASubject: Re: [Servingxml-= help] Content is notallowed in prolog=3F=0D=0A=0D=0A=20=0D=0A=0D=0AAkhil,=0D= =0A=0D=0A=20=0D=0A=0D=0A"Content is not allowed in prolog" is a parser erro= r message, that's=0D=0Acomplaining about the beginning of the received mess= age, namely <=3Fxml=0D=0Aversion=3D"1.0" encoding=3D"utf-8"=3F>. Try print= ing out the hex values of=0D=0Athe first few bytes of the message and make = sure there's no character,=0D=0Aspace, or junk text before the <=3F.=0D=0A=0D= =0A=20=0D=0A=0D=0AAlso, messages in utf-8 encoding can contain three leadin= g bytes, EF BB=0D=0ABF,called a BOM, and there is a known bug with versions= of Java before=0D=0A1.5, Java didn't handle BOMs on UTF-8 documents proper= ly, see=0D=0Ahttp://bugs.sun.com/bugdatabase/view_bug.do=3Fbug_id=3D4508058= =2E So check if=0D=0Ayour message contains a BOM. Try using Java 1.5 if y= ou're not already=0D=0Adoing so, and see if that helps. =20=0D=0A=0D=0A=20=0D= =0A=0D=0ARegards,=0D=0A=0D=0ADaniel Parker=0D=0A=0D=0A=09----- Original Mes= sage -----=20=0D=0A=0D=0A=09From: Akhil S. Srinivasan <mailto:akhilss@maste= k.com> =20=0D=0A=0D=0A=09To: Daniel Parker <mailto:danielaparker@sympatico.= ca> =20=0D=0A=0D=0A=09Cc: ser...@li...=20=0D=0A=0D= =0A=09Sent: Friday, February 03, 2006 3:16 AM=0D=0A=0D=0A=09Subject: RE: [S= ervingxml-help] Content is notallowed in prolog=3F=0D=0A=0D=0A=09=20=0D=0A=0D= =0A=09I tried as you have suggested but have run up against the same=0D=0Ap= roblem.=0D=0A=0D=0A=09=20=0D=0A=0D=0A=09Receiving message=0D=0A=0D=0A=09NMR= (content) org.apache.servicemix.jbi.jaxp.BytesSource@90ed81=0D=0A=0D=0A=09N= MR(content) <=3Fxml version=3D"1.0" encoding=3D"utf-8"=3F><ord:orders=0D=0A= xmlns:ord=3D"http:/=0D=0A=0D=0A=09/mastek.com/demos/servicemixtest/orders"=0D= =0Axmlns:xsi=3D"http://www.w3.org/2001/XMLSc=0D=0A=0D=0A=09hema-instance"=0D= =0Axsi:schemaLocation=3D"order-record.xsd"><ord:order><ord:ordertype>B=0D=0A=0D= =0A=09=0D=0A</ord:ordertype><ord:companyticker>AMZN</ord:companyticker><ord= :companyn=0D=0Aame>Amaz=0D=0A=0D=0A=09on=0D=0AInc</ord:companyname><ord:qua= ntity>10.0</ord:quantity></ord:order></ord:=0D=0Aorder=0D=0A=0D=0A=09s>=0D=0A=0D= =0A=09sending to client-sender=0D=0A=0D=0A=09sent to client-sender=0D=0A=0D= =0A=09=20=0D=0A=0D=0A=09[Fatal Error] :1:1: Content is not allowed in prolo= g.=0D=0A=0D=0A=09com.servingxml.util.ServingXmlException: Content is not al= lowed=0D=0Ain prolog.=0D=0A=0D=0A=09 at=0D=0Acom.servingxml.componen= ts.xmlpipeline.Pipeline.execute(Pipeline.java:=0D=0A=0D=0A=0994)=0D=0A=0D=0A= =09 at=0D=0Acom.servingxml.components.inverserecordmapping.XmlRecord= Reader.readRe=0D=0A=0D=0A=09cords(XmlRecordReader.java:93)=0D=0A=0D=0A=09 = at=0D=0Acom.servingxml.components.recordio.RecordPipeline.execute(Rec= ordPipel=0D=0A=0D=0A=09ine.java:69)=0D=0A=0D=0A=09 at=0D=0Acom.servi= ngxml.components.recordio.ProcessRecordsAppender.execute(Pro=0D=0A=0D=0A=09= cessRecordsAppender.java:81)=0D=0A=0D=0A=09 at=0D=0Acom.servingxml.c= omponents.service.ServiceImpl.execute(ServiceImpl.jav=0D=0A=0D=0A=09a:66)=0D= =0A=0D=0A=09 at=0D=0Acom.mastek.servicemix.ServingXmlTransformer.toR= esult(ServingXmlTransf=0D=0A=0D=0A=09ormer.java:130)=0D=0A=0D=0A=09 = at=0D=0Acom.mastek.servicemix.TextSourceMarshaler.asString(TextSourceMarsha= le=0D=0A=0D=0A=09r.java:28)=0D=0A=0D=0A=09 at=0D=0Aorg.apache.servic= emix.components.jms.JmsMarshaler.messageAsString(Jms=0D=0A=0D=0A=09Marshale= r.java:91)=0D=0A=0D=0A=09 at=0D=0Aorg.apache.servicemix.components.j= ms.JmsMarshaler.createMessage(JmsMa=0D=0A=0D=0A=09rshaler.java:68)=0D=0A=0D= =0A=09 at=0D=0Aorg.apache.servicemix.components.jms.JmsSenderCompone= nt$1.createMessa=0D=0A=0D=0A=09ge(JmsSenderComponent.java:72)=0D=0A=0D=0A=09= =20=0D=0A=0D=0A=09I am posing my entire resource file in. I hope it helps=0D= =0A=0D=0A=09=20=0D=0A=0D=0A=09<=3Fxml version=3D"1.0"=3F>=0D=0A=0D=0A=09 =0D= =0A=0D=0A=09<sx:resources xmlns:sx=3D"http://www.servingxml.com/core"=0D= =0A=0D=0A=09=0D=0Axmlns:msv=3D"http://www.servingxml.com/extensions/msv"=0D= =0A=0D=0A=09=0D=0Axmlns:ord=3D"http://mastek.com/demos/servicemixtest/order= s">=0D=0A=0D=0A=09=20=0D=0A=0D=0A=09 <sx:parameter name=3D"validate">=0D=0A=0D= =0A=09 <sx:defaultValue>no</sx:defaultValue>=0D=0A=0D=0A=09 </sx:parame= ter>=0D=0A=0D=0A=09=20=0D=0A=0D=0A=09 <sx:service id=3D"orderstoxml">=0D=0A=0D= =0A=09 <sx:serialize>=0D=0A=0D=0A=09 <sx:transform>=0D=0A=0D=0A=09 = <sx:content ref=3D"orders"/>=20=0D=0A=0D=0A=09 </sx:transform>=0D= =0A=0D=0A=09 </sx:serialize>=0D=0A=0D=0A=09 </sx:service>=0D=0A=0D=0A=09= =20=0D=0A=0D=0A=09 <sx:recordContent id=3D"orders">=0D=0A=0D=0A=09 <sx:= flatFileReader>=0D=0A=0D=0A=09 <!-- Is not needed, it does the transfo= rm then on anything=0D=0Agiven=0D=0A=0D=0A=09 <sx:stringSource /= >=0D=0A=0D=0A=09 <sx:urlSource url=3D"orders.csv"/>=20=0D=0A=0D=0A= =09 -->=0D=0A=0D=0A=09 <sx:flatFile ref=3D"ordersFlatFile"/>=0D=0A=0D= =0A=09 <!-- causes error for some reason=0D=0A=0D=0A=09 = <msv:msvRecordFilter=0D=0Aschema=3D"order-record.xsd"/>=0D=0A=0D=0A=09 = -->=0D=0A=0D=0A=09 </sx:flatFileReader>=0D=0A=0D=0A=09 <sx:record= Mapping ref=3D"ordersToXmlMapping"/>=0D=0A=0D=0A=09 </sx:recordContent>=0D= =0A=0D=0A=09 =20=0D=0A=0D=0A=09 <sx:flatFile id=3D"ordersFlatFile">=0D=0A=0D= =0A=09 <sx:commentSymbol value=3D"#"/>=0D=0A=0D=0A=09 <sx:flatFileBod= y>=0D=0A=0D=0A=09 <sx:flatRecordType id=3D"order">=0D=0A=0D=0A=09 = <sx:fieldDelimiter value=3D","/>=0D=0A=0D=0A=09 <sx:delimited= Field name=3D"ordertype-field"=0D=0Alabel=3D"OrderType"/>=0D=0A=0D=0A=09 = <sx:delimitedField name=3D"companyticker-field"=0D=0Alabel=3D"CompanyTic= ker"/>=0D=0A=0D=0A=09 <sx:delimitedField name=3D"companyname-field= "=0D=0Alabel=3D"CompanyName"/>=0D=0A=0D=0A=09 <sx:delimitedField n= ame=3D"quantity-field"=0D=0Alabel=3D"Quantity"/>=0D=0A=0D=0A=09 </sx= :flatRecordType>=0D=0A=0D=0A=09 </sx:flatFileBody>=0D=0A=0D=0A=09 </sx:= flatFile> =20=0D=0A=0D=0A=09=20=0D=0A=0D=0A=09 <sx:recordMapping id=3D= "ordersToXmlMapping">=0D=0A=0D=0A=09 <ord:orders=0D=0Axmlns:ord=3D"htt= p://mastek.com/demos/servicemixtest/orders"=0D=0A=0D=0A=09=0D=0Axmlns:xsi=3D= "http://www.w3.org/2001/XMLSchema-instance"=0D=0A=0D=0A=09 = xsi:schemaLocation=3D"order-record.xsd">=20=0D=0A=0D=0A=09 <sx:onRec= ord>=0D=0A=0D=0A=09 <ord:order>=0D=0A=0D=0A=09 <sx:fieldEle= mentMap field=3D"ordertype-field"=0D=0Aelement=3D"ord:ordertype"/> =20=0D=0A=0D= =0A=09 <sx:fieldElementMap field=3D"companyticker-field"=0D=0Aelem= ent=3D"ord:companyticker"/> =20=0D=0A=0D=0A=09 <sx:fieldEl= ementMap field=3D"companyname-field"=0D=0Aelement=3D"ord:companyname"/> =0D= =0A=0D=0A=09 <sx:fieldElementMap field=3D"quantity-field"=0D=0Aele= ment=3D"ord:quantity"/> =20=0D=0A=0D=0A=09 </ord:order> =20=0D= =0A=0D=0A=09 </sx:onRecord>=0D=0A=0D=0A=09 </ord:orders>=0D=0A=0D=0A= =09 </sx:recordMapping>=20=0D=0A=0D=0A=09 =20=0D=0A=0D=0A=09 <sx:service = id=3D"orderstocsv" name=3D"orderstocsv">=0D=0A=0D=0A=09 <sx:writeRecords= >=0D=0A=0D=0A=09 <sx:flatFileWriter>=0D=0A=0D=0A=09 <sx:flatFil= e ref=3D"ordersFlatFile"/>=0D=0A=0D=0A=09 </sx:flatFileWriter>=0D=0A=0D= =0A=09 <sx:xmlRecordReader>=0D=0A=0D=0A=09 <sx:inverseRecordMap= ping ref=3D"ordersToCSVMapping"/>=0D=0A=0D=0A=09 <sx:transform>=0D=0A=0D= =0A=09 <sx:document/>=0D=0A=0D=0A=09 </sx:transform>=0D= =0A=0D=0A=09 </sx:xmlRecordReader>=0D=0A=0D=0A=09 </sx:writeRecords= > =20=0D=0A=0D=0A=09 </sx:service>=0D=0A=0D=0A=09=20=0D=0A=0D=0A=09 = =20=0D=0A=0D=0A=09 <sx:inverseRecordMapping id=3D"ordersToCSV= Mapping">=0D=0A=0D=0A=09 <sx:documentFragmentMap path=3D"/ord:orders/ord= :order">=0D=0A=0D=0A=09 <sx:fragmentRecordMap recordType=3D"order">=0D= =0A=0D=0A=09 <sx:fragmentFieldMap select=3D"ord:ordertype"=0D=0Afiel= d=3D"ordertype"/>=0D=0A=0D=0A=09 <sx:fragmentFieldMap select=3D"ord:= companyticker"=0D=0Afield=3D"companyticker"/>=0D=0A=0D=0A=09 <sx:fra= gmentFieldMap select=3D"ord:companyname"=0D=0Afield=3D"companyname"/>=0D=0A=0D= =0A=09 <sx:fragmentFieldMap select=3D"ord:quantity"=0D=0Afield=3D"qu= antity"/>=0D=0A=0D=0A=09 </sx:fragmentRecordMap>=0D=0A=0D=0A=09 </s= x:documentFragmentMap>=0D=0A=0D=0A=09 </sx:inverseRecordMapping>=0D=0A=0D=0A= =09 =20=0D=0A=0D=0A=09</sx:resources>=0D=0A=0D=0A=09=20=0D= =0A=0D=0A=09And while I am at it my schema definition=0D=0A=0D=0A=09=20=0D=0A=0D= =0A=09<xsd:schema xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema"=0D=0A=0D=0A= =09=0D=0Axmlns:ord=3D"http://mastek.com/demos/servicemixtest/orders"=0D=0A=0D= =0A=09=0D=0AtargetNamespace=3D"http://mastek.com/demos/servicemixtest/order= s"=0D=0A=0D=0A=09 elementFormDefault=3D"unqualified"=0D=0A=0D=0A=09= attributeFormDefault=3D"unqualified">=0D=0A=0D=0A=09=20=0D=0A=0D= =0A=09 <xsd:annotation>=0D=0A=0D=0A=09 <xsd:documentation xml:lang=3D"en">=0D= =0A=0D=0A=09 Order Sent record schema=20=0D=0A=0D=0A=09 </xsd:documentat= ion>=0D=0A=0D=0A=09 </xsd:annotation>=0D=0A=0D=0A=09=20=0D=0A=0D=0A=09 <xsd= :element name=3D"orders" type=3D"ord:OrderRecords"/>=0D=0A=0D=0A=09=20=0D=0A=0D= =0A=09 <xsd:complexType name=3D"OrderRecords">=0D=0A=0D=0A=09 <xsd:sequenc= e>=0D=0A=0D=0A=09 <xsd:element name=3D"order" type=3D"ord:OrderRecord"=0D= =0AminOccurs=3D"0" maxOccurs=3D"unbounded"/>=0D=0A=0D=0A=09 </xsd:sequence= >=0D=0A=0D=0A=09 </xsd:complexType>=0D=0A=0D=0A=09=20=0D=0A=0D=0A=09 <!-- T= his element's name matches the value of the name=0D=0Aattribute in the px:f= latFileRecordType element. -->=0D=0A=0D=0A=09 <xsd:complexType name=3D"Orde= rRecord">=0D=0A=0D=0A=09 <xsd:sequence>=0D=0A=0D=0A=09 <xsd:element name= =3D"ordertype" type=3D"ord:OrderType"/>=0D=0A=0D=0A=09 <xsd:element name=3D= "companyticker" type=3D"ord:CompanyTicker"/>=0D=0A=0D=0A=09 <xsd:element = name=3D"companyname" type=3D"xsd:string"/>=0D=0A=0D=0A=09 <xsd:element na= me=3D"quantity" type=3D"xsd:integer"/> =20=0D=0A=0D=0A=09 </xsd:sequen= ce>=0D=0A=0D=0A=09 </xsd:complexType>=0D=0A=0D=0A=09=20=0D=0A=0D=0A=09 <xs= d:simpleType name=3D"OrderType">=0D=0A=0D=0A=09 <xsd:restriction base=3D= "xsd:string">=0D=0A=0D=0A=09 <xsd:length value=3D"1" fixed=3D"true"/>=0D= =0A=0D=0A=09 </xsd:restriction>=0D=0A=0D=0A=09 </xsd:simpleType>=0D=0A=0D= =0A=09 =20=0D=0A=0D=0A=09 <xsd:simpleType name=3D"CompanyTicker">=0D=0A=0D= =0A=09 <xsd:restriction base=3D"xsd:string">=0D=0A=0D=0A=09 <xsd:le= ngth value=3D"4" fixed=3D"true"/>=0D=0A=0D=0A=09 </xsd:restriction>=0D=0A=0D= =0A=09 </xsd:simpleType>=0D=0A=0D=0A=09 =20=0D=0A=0D=0A=09</xsd:schema>=0D= =0A=0D=0A=09=20=0D=0A=0D=0A=09Akhil Srinivasan=0D=0A=0D=0A=09=20=0D=0A=0D=0A=0D= =0AMASTEK=20=0D=0A"Making a valuable difference"=0D=0AMastek in NASSCOM's '= India Top 20' Software Service Exporters List.=0D=0AIn the US, we're called= MAJESCOMASTEK=0D=0A=0D=0A~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~~~~~~~~~~~~~~~~~~~~~=0D=0A~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=0D=0AOp= inions expressed in this e-mail are those of the individual and not=0D=0Ath= at of Mastek Limited, unless specifically indicated to that effect.=0D=0AMa= stek Limited does not accept any responsibility or liability for it.=0D=0AT= his e-mail and attachments (if any) transmitted with it are=0D=0Aconfidenti= al and/or privileged and solely for the use of the intended=0D=0Aperson or = entity to which it is addressed. Any review, re-transmission,=0D=0Adissemin= ation or other use of or taking of any action in reliance upon=0D=0Athis in= formation by persons or entities other than the intended=0D=0Arecipient is = prohibited. This e-mail and its attachments have been=0D=0Ascanned for the = presence of computer viruses. It is the responsibility=0D=0Aof the recipien= t to run the virus check on e-mails and attachments=0D=0Abefore opening the= m. If you have received this e-mail in error, kindly=0D=0Adelete this e-mai= l from all computers.=0D=0A~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~~~~~~~~~~~~~~~~~~~~~~=0D=0A~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=0D=0A=0D= =0A=20=0D=0A=0D=0A=20=0D=0A=0D=0A=20=0D=0A=0D=0AMASTEK=20=0D=0A"Making a va= luable difference"=0D=0AMastek in NASSCOM's 'India Top 20' Software Service= Exporters List.=0D=0AIn the US, we're called MAJESCOMASTEK=0D=0A=0D=0A~~~~= ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=0D=0AOpinions expressed in this e-mail are = those of the individual and not that of Mastek Limited, unless specifically= indicated to that effect. Mastek Limited does not accept any responsibilit= y or liability for it. This e-mail and attachments (if any) transmitted wit= h it are confidential and/or privileged and solely for the use of the inten= ded person or entity to which it is addressed. Any review, re-transmission,= dissemination or other use of or taking of any action in reliance upon thi= s information by persons or entities other than the intended recipient is p= rohibited. This e-mail and its attachments have been scanned for the presen= ce of computer viruses. It is the responsibility of the recipient to run th= e virus check on e-mails and attachments before opening them. If you have r= eceived this e-mail in error, kindly delete this e-mail from all computers.=0D= =0A~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=0D=0A |