IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

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
Expand all | Collapse all

How to get the xml file in the java service programmatically

  • 1.  How to get the xml file in the java service programmatically

    Posted Wed March 23, 2011 04:38 PM

    Hi, I was told to write a cache logic using “Ehcache”. Here I have to get the ehcache.xml file to IS java service programmatically, and I have searched for that and I found something.

    It was told that we can use

    context.connect(server, username, password)

    but it is for submitting the xml file to that server, here I want to retrieve the xml file to the IS programmatically.

    Please suggest me an idea.

    Thanks,
    Venkat


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 2.  RE: How to get the xml file in the java service programmatically

    Posted Tue March 29, 2011 03:16 AM

    If you want to do it from webMethods, you can use getFile service which will bring the XML data in bytes… Use xmlStringToNode, and NodeToDocument service to view the XML in IS document format…

    Senthil


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 3.  RE: How to get the xml file in the java service programmatically

    Posted Tue March 29, 2011 07:16 PM

    Hi Senthil, I see what you are saying but in webMethods 8.0 we have a enhanced “getFile” java service which gives the file data in either “byte”, “stream”, “reader” or “string”.

    I am taking the output of that service as “string” and directly using it but it is giving me “null”, I am not getting where is the problem.

    Please go through the documentation of 8.0 version before looking into this code for “getFile” built-in java service.

    IData loadAs=IDataFactory.create();
    IDataCursor loadAsCursor=loadAs.getCursor();
    loadAsCursor.setValue(((Object) “string”));
    try {
    context.invoke(“pub.file”,“getFile”, loadAs);
    body=context.invoke(“pub.file”,“getFile”,fileName);
    } catch(Exception e) {
    e.printStackTrace();
    throw new ServiceException(“\n”+“Could not invoke the file”);
    }
    try {
    bodyCursor=body.getCursor();
    if(bodyCursor.first(“string”)) {
    string=IDataUtil.getIData(bodyCursor,“string”);
    stringCursor=string.getCursor();
    xmlFileData=(String) stringCursor.getValue();
    }
    /if(pipeLineCursor.first(“body”)) {
    body=IDataUtil.getIData(pipeLineCursor,“body”);
    bodyCursor=body.getCursor();
    if(bodyCursor.first(“string”)) {
    string=IDataUtil.getIData(bodyCursor,“string”);
    stringCursor=string.getCursor();
    xmlFileData=(String) stringCursor.getValue();
    }
    }
    /
    /if(pipeLineCursor.first(“string”)) {
    string=IDataUtil.getIData(bodyCursor,“string”);
    stringCursor=string.getCursor();
    xmlFileData=(String) stringCursor.getValue();
    }
    /
    /if(pipeLineCursor.first(“body”) && bodyCursor.first(“string”)) {
    xmlFileData=(String) stringCursor.getValue();
    }
    /
    } catch(Exception e) {
    e.printStackTrace();
    throw new ServiceException(“\n”+“Could not retrieve data from the file”);
    }

    Thanks,
    Venkat.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods