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.


#TechXchangePresenter
 View Only
Expand all | Collapse all

In java service how to get java.sql.Connection created in IS

  • 1.  In java service how to get java.sql.Connection created in IS

    Posted Mon May 14, 2018 06:31 PM

    I’d like to get more information on how to get java.sql.Connection created in IS in java service.

    So far I gathered some information like this

    java.sql.Connection conn =
    (java.sql.Connection)IDataUtil.get(pipeline.getCursor(),
    com.wm.adapter.wmjdbc.services.ExecuteService.PIPELINE_CONNECTION);

    Somehow I couldn’t find the class com.wm.adapter.wmjdbc.services.ExecuteService in my designer 10.1 env.

    Also I found some other code like

    try{
    ConnectionDataNode node = ConnectionDataNodeManager.getConnectionDataNode(connName);
    ConnectionResource resource = null;
    if (node != null) {
    resource = node.getConnectionResource();
    }
    

    I couldn’t find ConnectionDataNode in my designer 10.1 either.

    Please help.

    regards,
    Hwuii


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


  • 2.  RE: In java service how to get java.sql.Connection created in IS

    Posted Mon May 14, 2018 07:07 PM

    You just have to use a special type of JDBC adapter. IIRC, it’s called “execute service”. Then, the connection managed by the IS is handed over under a special name in the pipeline. I don’t remember exactly the name, but it’s documented in the JDBC adapter docs. You don’t have to access the value via a constant field; just write its value as a string constant.

    I wouldn’t use DataNode and NodeManager; I don’t think this is a supported way of doing things.


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


  • 3.  RE: In java service how to get java.sql.Connection created in IS

    Posted Tue May 22, 2018 03:46 PM

    Create a new JDBC Adapter service with the template as “ExecuteService” on a connection that you want to use in your Java service. Inside the Java service use below code and you will be able to safely access the connection from Java service. In the adapter service that you created, you have to give your Java service as service name to invoke.

    When you execute the adapter service, it will execute the Java service using the connection information from the adapter service.

    Code:
    java.sql.Connection conn = (java.sql.Connection)IDataUtil.get(pipeline.getCursor(), “$db_service_connection”);


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


  • 4.  RE: In java service how to get java.sql.Connection created in IS

    Posted Fri May 25, 2018 11:13 AM

    Thank you all!

    Somehow I still got NullPointerException when I tried to get DB connection in pipeline.

    I attached a screenshot. ExeSvc is the ExecuteService I created earlier.

    Any idea?

    Regards,

    Hui


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


  • 5.  RE: In java service how to get java.sql.Connection created in IS

    Posted Fri May 25, 2018 12:06 PM

    You need to run the adapter service(created using the exec service template) to invoke the Java service. If you run the Java service directly then it can’t find the connection details.


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


  • 6.  RE: In java service how to get java.sql.Connection created in IS

    Posted Fri May 25, 2018 12:27 PM

    Thank you Akshith!

    Invoking ExeSvc worked:-)


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


  • 7.  RE: In java service how to get java.sql.Connection created in IS

    Posted Tue December 18, 2018 12:16 PM

    Thank you Akshith for your advise! However, that looks quite strange to me even though it works. Would there be an alternative way to get one of the currently open connections directly from the WmJDBCAdapter package in the Java Service?

    Best regards,
    Marcus


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


  • 8.  RE: In java service how to get java.sql.Connection created in IS

    Posted Tue December 18, 2018 05:29 PM

    This might appear strange to you, but it’s a perfectly valid control flow. The idea is that the connections are allocated from the pool when an adapter service is executed. Inside the service, you don’t have to “open” a connection but just have to access an already open one. It is handed over to you unter a special and documented name in the pipeline.

    Why would you want to get a connection “directly from the WmJDBCAdapter package”? Why would it be better than what you have now?


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


  • 9.  RE: In java service how to get java.sql.Connection created in IS

    Posted Thu December 20, 2018 05:00 AM

    Do you let the engine control your car or do you drive it yourself?

    Back to topic: I found the com.wm.app.jdbc.* library and the com.wm.app.b2b.server.* library with JDBC-related classes. While the latter is documented, it doesn’t seem to allow access the connections of the JDBC adapter package. Unfortunately, I couldn’t find any documentation on the former. Any hints?


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


  • 10.  RE: In java service how to get java.sql.Connection created in IS

    Posted Thu December 20, 2018 08:52 AM

    Marcus,
    You will have more luck using service in WmDB package to have more control over the connections. Its been almost 10 years since i used that package but i remember using the services in that package to open and close connections to database within the code.

    Cheers,
    Akshith


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


  • 11.  RE: In java service how to get java.sql.Connection created in IS

    Posted Thu December 20, 2018 06:38 PM

    Do you repair you car by yourself? Have you heard of inversion of control?

    I think I gave you a good advice. If you are not going to follow it, it’s your perfectly valid choice.


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


  • 12.  RE: In java service how to get java.sql.Connection created in IS

    Posted Fri December 21, 2018 07:26 AM

    Dear Akshith,
    thanks for your hint! Unfortunately, the WmDB is not part of our IS installation as it is deprecated. So I guess we have to look for other packages/libraries.

    Best regards,
    Marcus


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


  • 13.  RE: In java service how to get java.sql.Connection created in IS

    Posted Tue January 15, 2019 03:13 AM

    Meanwhile SAG informed me that it is OK to still use the WmDB package and asked me to submit a feature request to ask for a successor, what I did. Anybody interested in the same functionality is welcome to vote for feature request 06635 on Brainstorm.

    Best regards,
    Marcus


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


  • 14.  RE: In java service how to get java.sql.Connection created in IS

    Posted Tue January 15, 2019 09:59 AM

    Why not using the JDBC-Adapter-Service templates to create AdapterServices on top of the connections in the JDBC-Adapter?

    Regards,
    Holger


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


  • 15.  RE: In java service how to get java.sql.Connection created in IS

    Posted Tue February 12, 2019 08:38 AM

    Hello Holger,
    actually, SAG also suggested this workaround and I would be fine with it if handing over the results from the JDBC adapter service to the Java service was type-safe for all data structures. But it is only for string, not even for dates or boolean types. So I asked them for a solution to this question. At the moment, this is the state of affairs.

    Best regards,
    Marcus


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


  • 16.  RE: In java service how to get java.sql.Connection created in IS

    Posted Tue February 12, 2019 10:08 AM

    Hi Marcus,

    you might want to consider opening a feature request in Brainstorm (reachable via Empower) then.

    Regards,
    Holger


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


  • 17.  RE: In java service how to get java.sql.Connection created in IS

    Posted Tue February 12, 2019 11:18 AM

    Hi Holger,
    probably yes, but I want to await their answer first. Maybe they have got another solution ready. I’ll keep you posted.

    Best regards,
    Marcus


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