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
  • 1.  Direct Socket Connection

    Posted Wed August 26, 2009 03:23 PM

    Hi,

    We need to sent and receive data through an socket connection to an external socket server. If we run a java program outside wm we dont have any problems open the connection, send and receive data. But when we implement the code below in a Java Service inside wm the application hang until the connection times out. Any ideas on how to solve the problem ?

    Thanks
    Örjan

    Code:

    // pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();
    String host = IDataUtil.getString(pipelineCursor, “host”);
    String port = IDataUtil.getString(pipelineCursor, “port”);
    String data = IDataUtil.getString(pipelineCursor, “data”);
    String responseEndTag = IDataUtil.getString(pipelineCursor, “responseEndTag”);
    pipelineCursor.destroy();
    StringBuffer xml = new StringBuffer(“”);
    try {
    InetAddress inetAddress = InetAddress.getByName(host);
    SocketAddress socketAddress = new InetSocketAddress(inetAddress, Integer.parseInt(port));

    // unbound socket
    Socket socket = new Socket();

    // TimeoutMs.
    int timeoutMs = 2000; // 2 seconds
    socket.connect(socketAddress, timeoutMs);
    OutputStream out = socket.getOutputStream();
    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

    out.write(data.getBytes());
    String line = “”;

    if (in.ready()){
    while((line = in.readLine()) != null){
    xml.append(line);
    if(line.endsWith(responseEndTag)){
    break;
    }
    }
    }
    out.close();
    in.close();
    socket.close();
    }
    catch (UnknownHostException e) {
    xml.append(e.getMessage());
    }
    catch (SocketTimeoutException e) {
    xml.append(e.getMessage());
    }
    catch (IOException e) {
    xml.append(e.getMessage());
    }
    data = xml.toString();
    // pipeline
    IDataCursor pipelineCursor_1 = pipeline.getCursor();
    //valueList[0] = “data”;
    IDataUtil.put( pipelineCursor_1, “data”, data );
    pipelineCursor_1.destroy();


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


  • 2.  RE: Direct Socket Connection

    Posted Wed August 26, 2009 05:13 PM

    They should be the same.
    Did you run your java code on the same box as the WM server? Make sure the remote server is reachable from the WM server.
    Also try longer timeout time.


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


  • 3.  RE: Direct Socket Connection

    Posted Fri August 28, 2009 08:30 PM

    what kind of timeout occurs, connect/send/read???

    if connect/send please check your link network connection (see tongwang comment).
    else, may be this could be help you:

    BufferedInputStream reader = new BufferedInputStream(socket.getInputStream());
    byte b = new byte[1024];
    String response = reader.read(b);

    • refer to java API of using BufferedInputStream

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


  • 4.  RE: Direct Socket Connection

    Posted Fri August 28, 2009 11:32 PM

    I think there is a sample of using sockets within IS available on Advantage. It may be worth a search.


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


  • 5.  RE: Direct Socket Connection

    Posted Fri August 28, 2009 11:34 PM

    Or there is this one in the wMUsers Shareware section from our esteemed leader, Mark Carlson. [URL]wmusers.com


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


  • 6.  RE: Direct Socket Connection

    Posted Mon August 31, 2009 07:53 AM

    Thanks for your help!

    We had some proxy and firewall issues causing the problems.


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