webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  How to write Content Handler

    Posted Mon July 15, 2002 05:19 AM

    Hi,
    If i want to write a content handler program, where should i start from? Could you please provide a sample program or guideline for me to foolow?

    Regards
    Cliff Seow


    #webMethods
    #webMethods-General
    #Integration-Server-and-ESB


  • 2.  RE: How to write Content Handler

    Posted Tue July 16, 2002 01:56 AM

    Here is the content handler code which I wrote to handle CSV (Comma Seperated Value) files.
    There are two files. The first one is
    HandlerFactory_csv.java (instance creation) and the second one is ContentHandler_csv.java (actual implementation) which persists the (lets assume a CSV file submitted to IS thru FTP from a client) CSV file contents into a text file at the server.

    This content handler has to be registered with the IS with the content type (can be configured as a pacakge level startup service) before it can be invoked by the IS.

    Below is the java code:

    HandlerFactory_csv.java

    import com.wm.app.b2b.server.ContentHandlerFactory;
    import com.wm.app.b2b.server.ContentHandler;

    public class HandlerFactory_csv extends ContentHandlerFactory
    {

    public HandlerFactory_csv()
    {
    }
    
    public ContentHandler create()
    {
    return new ContentHandler_csv();
    }
    

    }

    ContentHandler_csv.java

    import com.wm.app.b2b.server.ContentHandler;
    import com.wm.app.b2b.server.InvokeState;
    import com.wm.util.Values;
    import java.io.*;

    public class ContentHandler_csv implements ContentHandler
    {

    public ContentHandler_csv()
    {
    }
    
    public String getContentType()
    {
    return "text/csv";
    }
    
    public Values getInputValues(InputStream inputstream, InvokeState invokestate) throws IOException
    {
    
    Values values = new Values();
    ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
    try
    {
    byte abyte0[] = new byte[4096];
    int i;
    while((i = inputstream.read(abyte0)) != -1)
    bytearrayoutputstream.write(abyte0, 0, i);
    
    byte abyte1[] = new byte[bytearrayoutputstream.size()];
    abyte1 = bytearrayoutputstream.toByteArray();
    
    String file = "c:\csvOutFile.txt";
    FileOutputStream fos = new FileOutputStream(new File(file));
    fos.write(abyte1);
    }
    catch(IOException ioexception)
    {
    System.out.println("ContentHandler_csv: Exception occurred while handling input file: " + ioexception);
    }
    finally
    {
    if(bytearrayoutputstream != null)
    try
    {
    bytearrayoutputstream.close();
    }
    catch(IOException _ex)
    {
    System.out.println("ContentHandler_csv: Exception occurred while closing bytearrayoutputstream!" + _ex);
    }
    }
    return values;
    }
    
    public void putOutputValues(OutputStream outputstream, Values values, InvokeState invokestate) throws IOException
    {
    }
    

    }

    Let me know if this helped you.
    Cheers.


    #Integration-Server-and-ESB
    #webMethods-General
    #webMethods


  • 3.  RE: How to write Content Handler

    Posted Tue July 23, 2002 11:42 AM

    What�s the content handler invoked when I call services using the client API (client.jar)?
    How can I set a content-type using the TContext object?


    #webMethods
    #webMethods-General
    #Integration-Server-and-ESB


  • 4.  RE: How to write Content Handler

    Posted Fri March 06, 2009 06:27 AM