0 Replies Latest reply on Apr 29, 2019 5:41 AM by 3922556

    Java unable to call socket service

    3922556

      So I have created a service on JDeveloper with socket adapter where a message is read from. I have followed the steps mentioned in the following link for that: https://shrikworld.blogspot.com/2014/11/demystifying-oracle-socket-adapter.html However the problem is that when i create the java class to test the service, i get an error.

      I have been trying to figure out what the issue is but i cant find anything useful on this. Here is a description of the SocketAdapter in my weblogic console:

      Host: localhost KeepAlive: true EnableSDP: false backlogQueue: 0 port: 12110 SSLEnable: false NeedClientAuthentication: false Timeout: 1000

      Here is my java class:

      1. import java.io.BufferedReader;
      2. import java.io.IOException;
      3. import java.io.InputStreamReader;
      4. import java.io.OutputStream;
      5. import java.net.Socket;
      6. public class Client {
      7.     public static void main(String[] args) {
      8.         try {
      9.             Socket socket;
      10.             final String HOST = "localhost";
      11.             final int PORT = 12110;
      12.             try {
      13.                 socket = new Socket(HOST, PORT);
      14.             } catch (IOException ioe) {
      15.                 System.out.println(">>>");
      16.                 System.out.println(ioe.getMessage());
      17.                 System.out.println(">>>");
      18.                 throw ioe;
      19.             }
      20.             System.out.println("sending data: EmpDetails;");
      21.             OutputStream os = socket.getOutputStream();
      22.             byte[] b = "fn111111ln111111232007-01-01100\nfn211111ln211111232007-11-01200\nfn311111ln311111232007-12-01300".getBytes();
      23.             for (int i = 0; i < b.length; i++) {
      24.                 os.write(b[i]);
      25.             }
      26.             os.flush();
      27.             socket.shutdownOutput();
      28.             System.out.println("receiving data");
      29.             BufferedReader soc_in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
      30.             String successCode = soc_in.readLine();
      31.             System.out.println("Success Code: " + successCode);
      32.             socket.close();
      33.         } catch (IOException ioe) {
      34.             ioe.printStackTrace();
      35.         }
      36.     }
      37. }

      and here is the error I get when I try running the code:

      1. java.net.ConnectException: Connection refused: connect
      2. at java.net.DualStackPlainSocketImpl.connect0(Native Method)
      3. at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
      4. at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
      5. at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
      6. at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
      7. at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
      8. at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      9. at java.net.Socket.connect(Socket.java:589)
      10. at java.net.Socket.connect(Socket.java:538)
      11. at java.net.Socket.<init>(Socket.java:434)
      12. at java.net.Socket.<init>(Socket.java:211)
      13. at SocketAdapter.Client.main(Client.java:18)