Join wMUsers | Blog at wMUsers | User Control Panel | Site Map | webMethods Jobs |For Employers

Rupinder Singh -- webMethods Ezine Columnist

Add XML Depth to Your Inbound Trading Networks Flat Files



By Rupinder Singh

 

Implementing the read() Method

Once the above supporting methods are completed, the read() method must be implemented.

public int read() throws IOException
  {
    if (pos >= buffer.length)
    {
      String line = reader.readLine();

      if (line == null)
      {
        if (eof)
        {
          return -1;
        }
        eof = true;
        buffer = ("</" + docType + ">").getBytes();
        pos = 0;
      }
      else
      {
        buffer = formatRecord(line).getBytes();
        pos=0;
      }
    }
    return (int)buffer[pos++];
  }

  private String formatRecord(String line)
  {
    StringBuffer sbuffer = new StringBuffer();
    sbuffer.append(newLine + "<" + nodeName + ">");
    StringTokenizer st = new StringTokenizer(line, ",");
    for (int i=0; st.hasMoreTokens(); i++)
    {
      sbuffer.append(newLine + "<" + fieldnames[i] + ">");
      sbuffer.append(st.nextToken());
      sbuffer.append("</" + fieldnames[i] + ">");
    }
    sbuffer.append(newLine + "</" + nodeName + ">" + newLine);
    return sbuffer.toString();
  }

Register the content handler with the webMethods Integration Server using the ServerAPI.registerContentHandler() method and the work is completed.


Summary

The advantage to using the content handlers in the article is that a partner does not need to modify its flat file format to submit documents to Trading Networks. In fact, because the content handler is transparent, the partner appears to be submitting a XML document.

In addition, the above content handler can be registered to handle multiple types of text content from multiple partners.

Two other important notes:

  1. Because the actual conversion of the stream to an IData object is done by the webMethods XML content handler, it is guaranteed to be forward compatible.

  2. If the server has been configured to handle large files, the document would show up as a large document in Trading Networks.



<<Prev  1  [2]  

Go Deeper on the Subject: The wMUsers Discussion Forums


Rupinder Singh has been working in the IT arena for about 10 years with experience in real-time defense systems, SGML parsers and application integration. He has worked on several integration projects in various roles using webMethods and J2EE application servers.

Rupinder is a consultant for Atos Origin and can be reached via email at


Advertise at wMUsers






  Home | Join wMUsers | Discussion Forums | Knowledge Center | Jobs | Shareware | User Groups | Links |
Contact Us | Terms of Service | Privacy Policy

wMUsers is an independent organization and is not sponsored in any manner by Software AG.


© All Rights Reserved, 2001-2008.