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

firing curl script using sample code - fireCommandExec

  • 1.  firing curl script using sample code - fireCommandExec

    Posted Tue January 07, 2014 08:48 AM

    Hi All,

    I am trying to send an image location url using curl script to a restful webservice. The script is working fine when i run it directly on my server unix box. However while trying to fire the script using the sample code - fireCommandExec, i am getting
    the below error.

    500 internal server error.
    We’re sorry but a serious error has occurred in the system.

    curl script -
    curl -k -i -u username:password -H “Content-Type=multipart/form-data” --data “imageURI=imageLocationURL” -X POST endPointURL

    java code used to fire the command -
    Process child = Runtime.getRuntime().exec(command);

    Kindly help me to resolve the issue and let me know if i am doing anything wrong.

    Regards
    Anooja


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


  • 2.  RE: firing curl script using sample code - fireCommandExec

    Posted Tue January 07, 2014 08:56 AM


  • 3.  RE: firing curl script using sample code - fireCommandExec

    Posted Tue January 07, 2014 09:15 AM

    Hi,

    PFB the java code. However I do not feel the issue is with java code. The same code was tried in eclipse, and the script was run without any issue.

    Process child = Runtime.getRuntime().exec(command);

        // read stdout; required to keep this process from becoming a zombie
    InputStream stdout = child.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
    
    int siz = 1024;
    char[] buff = new char[siz];
    
    int r = 0;
    StringBuffer sbf = new StringBuffer();
    while ( ( r = reader.read(buff, 0, siz) ) > 0 )
    {
    sbf.append(buff, 0, r);
    }
    stdoutText = sbf.toString();
    
    // read stderr; required to keep this process from becoming a zombie
    InputStream stderr = child.getErrorStream();
    reader = new BufferedReader(new InputStreamReader(stderr));
    
    StringBuffer sbf2 = new StringBuffer();
    while ( ( r = reader.read(buff, 0, siz) ) > 0 )
    {
    sbf2.append(buff, 0, r);
    }
    stderrText = sbf2.toString();
    
    child.waitFor(); // IllegalThreadStateException, if w/o wait & child not terminated
    status = child.exitValue();
    

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


  • 4.  RE: firing curl script using sample code - fireCommandExec

    Posted Tue January 07, 2014 09:36 AM

    Is the target RESTful web service implemented by Jive REST API? It looks like a server side error, your java code is ok, you’d better confirm this with web service provider.


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


  • 5.  RE: firing curl script using sample code - fireCommandExec

    Posted Tue January 07, 2014 09:53 AM

    Hi,

    Yes, the target is a jive REST API. However what confuses me is that, when i try to run the same curl script from my server unix box i get success response.


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


  • 6.  RE: firing curl script using sample code - fireCommandExec

    Posted Tue January 07, 2014 10:29 AM

    There is something different between Runtime.exec invoke and directly shell invoke about parse the args.
    May be you can try Runtime.getRuntime().exec(new String{“curl”, “-k”, “-i”, “-u”, …}) instead.


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


  • 7.  RE: firing curl script using sample code - fireCommandExec

    Posted Wed January 08, 2014 02:20 AM

    Hi,

    I tried that and it did not work. Also i was able to run another curl script to upload an image to the jive rest API using the same code.


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


  • 8.  RE: firing curl script using sample code - fireCommandExec

    Posted Wed January 08, 2014 07:59 AM

    Hi,

    Is there anything else i can try? :frowning: Not sure what is the issue. I checked with the webservice provider, and they have no error logs at their end to help the situation.


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


  • 9.  RE: firing curl script using sample code - fireCommandExec

    Posted Wed January 08, 2014 08:58 AM

    I think there is one more thing you can try. As you said:

    May be you can try to write this script into a .sh file, and execute it by Runtime.exec.


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


  • 10.  RE: firing curl script using sample code - fireCommandExec

    Posted Thu January 09, 2014 05:14 AM