Wednesday, June 30, 2010

Oracle MFL tutorial

All the documentation is here:
http://download.oracle.com/docs/cd/E13160_01/wli/docs10gr3/pdf/fbhelp.pdf

Some examples here:
http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/testing.html#wp1041203

Excellent tutorial here

http://biemond.blogspot.com/2008/12/flat-file-to-xml-with-oracle-service.html


In a OSB Project, do New, Other, Oracle Service Bus, MFL. Enter a name, like MQFeedParser.
You get this:




GEOMQFeed is the "Message Format", i.e. the "Root Element".

From here you can either insert a Group or a Field. A Group can contain other Groups and/or Fields.
A Group can be OPTIONAL or REQUIRED
A Group can repeat itself
You can define a Group once and use Group References to instantiate it multiple times.

"Choice of Children" means that only one of the fields specified is allowed.

Group Occurrence is self-explanatory.

A TAGGED GROUP is a Group whose start is preceded by a specific value, like NEWGROUP:ACME (the tag being NEWGROUP: and the group name being ACME)


________________________________


A good way to test the MFL is to write a File Transport PS with MFL input

For instance this:

<?xml version='1.0' encoding='windows-1252'?>
<!DOCTYPE MessageFormat SYSTEM 'mfl.dtd'>
<!--   Enter description of the message format here.   -->
<MessageFormat name='SampleMFL' version='2.02'>
    <StructFormat name='Employees' delimOptional='y' repeat='*'>
        <FieldFormat name='Name' type='String' delimOptional='y' length='12' strlenInChars='n' codepage='windows-1252'/>
        <FieldFormat name='Age' type='String' delimOptional='y' length='3' strlenInChars='n' codepage='windows-1252'/>
    </StructFormat>
</MessageFormat>

when your input is this
Pierre01 345Pierre02 346

should return you

<?xml version="1.0" encoding="UTF-8"?>
<SampleMFL>
  <Employees>
    <Name>Pierre01</Name>
    <Age>345</Age>
  </Employees>
  <Employees>
    <Name>Pierre01</Name>
    <Age>345</Age>
  </Employees>
</SampleMFL> 
 
 



If the input data doesn't match the MFL you get:

com.bea.wli.sb.sources.TransformException: Failed to transform MFL content from binary to XML

Caused By: <MFLException>
<ErrorMessage>Did not completely process all input data.</ErrorMessage>
<Details>
<Detail>
<Name>ErrorCode</Name>
<Value>-3</Value>
</Detail>
<Detail>
<Name>DataOffset</Name>
<Value>15</Value>
</Detail>
</Details>
</MFLException>
at com.bea.nonxml.common.MFLException.create(MFLException.java:221)
at com.bea.nonxml.common.MFLException.create(MFLException.java:337)
at com.bea.nonxml.readers.NonXMLReaderVisitor.nextToken(NonXMLReaderVisitor.java:155)
at com.bea.nonxml.readers.TokenNonXMLReader.nextToken(TokenNonXMLReader.java:44)
at com.bea.binxml.v2.readers.SaxTokenReader$ExtendedTokenReaderWrapper.nextToken(SaxTokenReader.java:335)
at com.bea.binxml.v2.readers.SaxTokenReader.process(SaxTokenReader.java:189)
at com.bea.binxml.v2.readers.SaxTokenReader.process(SaxTokenReader.java:154)
at com.bea.wli.common.mfl.MflExecutor.executeXmlObject(MflExecutor.java:126)
at com.bea.wli.sb.resources.mfl.MflExecutor.executeXmlObject(MflExecutor.java:98)
at com.bea.wli.sb.stages.transform.MflTransformImpl.executeXmlObject(MflTransformImpl.java:84)
at com.bea.wli.sb.sources.MFLSource.getInstance(MFLSource.java:113)
at com.bea.wli.sb.sources.MFLTransformer.transform(MFLTransformer.java:75)
at com.bea.wli.sb.sources.MetaTransformer.doTransform(MetaTransformer.java:138)
at com.bea.wli.sb.sources.MetaTransformer.transform(MetaTransformer.java:89)




This http://forums.oracle.com/forums/thread.jspa?threadID=945164 should help,
"try to change the message type from text to binary"

Here
C:\bea11\Oracle_OSB11\lib\modules\com.bea.alsb.resources.mfl.jar

is the MflExecutor


There is this tool WLXT

http://download.oracle.com/docs/cd/E13214_01/wli/docs70/classdocs/com/bea/wlxt/WLXT.html

to unittest MFL.
You should include in the CLASSPATH : com.bea.wli.transform.fbruntime_1.1.0.0.jar and weblogic.jar


File binaryfile = new File("c:/geodata.dat");
WLXT wlxt = new WLXT();
URL mflDocumentName = new URL("file:c:/geodata.mfl");
FileInputStream in = new FileInputStream(mybinaryfile);
Document doc = wlxt.parse(mflDocumentName, in, null);
String xml = WLXT.getXMLText(doc, 0, 2);
System.out.println(xml);


3 comments:

Unknown said...

I'm trying to get this unittest example to work but i can't find com.bea.wli.transform.fbruntime_1.1.0.0.jar nor WLXT class. Can you tell me where to find it?

vernetto said...

sorry for the late reply:

C:\bea11\Oracle_OSB\modules\com.bea.wli.transform.fbruntime_1.2.0.0.jar

or C:\Oracle1\Middleware\Oracle_OSB1\modules\com.bea.wli.transform.fbruntime_1.2.0.0.jar


and the WLXT is in there...

chandu said...

please add delim='\n' to four last filed age