title: How to write Java code inside Oracle procedure
body: <p>I have created a Java source and compiled it and wrapped it in an Oracle 19c procedure with the jdk+jre 1.8.0._201. I'm connecting to a suite that uses TLS 1.2 with mutual authentication(with a private key).
  I have already set java permissions using dbms_java.grant_permission.</p>
  
  <p>This is the java code:  </p>
  
  <pre><code>CREATE OR REPLACE and COMPILE JAVA SOURCE NAMED  "Test" AS
  
  
  import java.io.*;
  import java.sql.*;
  import java.net.URL;
  import java.security.KeyStore;
  import java.security.KeyStore.SecretKeyEntry;
  import javax.crypto.SecretKey;
  import javax.net.ssl.HostnameVerifier;
  import javax.net.ssl.HttpsURLConnection;
  import javax.net.ssl.SSLSession;
  public class Test{
      public static void test(String[] body,String[] result, String[] response){
          String s=body[0];
          String lenn = Integer.toString(s.length()); 
          result[0]="ok";
          System.setProperty("java.net.preferIPv4Stack" , "true");
          try  {
             String keyPath = "C:\\me\\keystore.jks";
             String keyPass = "123";
             String keyType = "JKS";
             System.setProperty("javax.net.ssl.keyStore", keyPath);
             System.setProperty("javax.net.ssl.keyStorePassword", keyPass);
             System.setProperty("javax.net.ssl.keyStoreType", keyType);
             URL url = new URL("URL"); 
             HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
             con.setRequestMethod("POST");
             con.setDoOutput( true );
             con.connect();
             //----------send body
             OutputStreamWriter writer = new 
                    OutputStreamWriter(con.getOutputStream());
             writer.write(s);
             writer.flush();
             writer.close();
             //--------- reading the response
             BufferedReader in = new BufferedReader(new 
                    InputStreamReader(con.getInputStream()));
             String inputLine;
             StringBuffer buff = new StringBuffer();
             while ((inputLine = in.readLine()) != null) {
                  buff.append(inputLine);
             }
             response[0]=buff.toString();
             con.disconnect();
        } catch(Exception ex) {
              StringWriter sw = new StringWriter();
              PrintWriter pw = new PrintWriter(sw);
              ex.printStackTrace(pw);
              result[0]=sw.toString();
        }
     } 
  }
  /
  show errors
  /
  
  </code></pre>
  
  <p>I tried all I could but with no luck
  I got the following error:</p>
  
  <pre><code>java.net.SocketException: connect failed, 10022
  An invalid argument was
  supplied.
          at java.net.DualStackPlainSocketImpl.connect0(Native Method)
          at
  java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79
  )
          at
  java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
          a
  t
  java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:2
  06)
          at
  java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
          at
  java.net.PlainSocketImpl.connect(PlainSocketImpl.java:255)
          at
  java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
          at
  java.net.Socket.connect(Socket.java:589)
          at
  sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666)
          at
  sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
          at
  sun.net.NetworkClient.doConnect(NetworkClient.java:180)
          at
  sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
          at
  sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
          at
  sun.net.www.protocol.https.HttpsClient.&lt;init&gt;(HttpsClient.java:264)
          at
  sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
          at
  sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(A
  bstractDelegateHttpsURLConnection.java:191)
          at
  sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java
  :1156)
          at
  sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:
  1050)
          at
  sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDe
  legateHttpsURLConnection.java:177)
          at
  sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl
  .java:162)
          at Test.west(Test:27)
  PL/SQL procedure successfully completed.
  
  </code></pre>
  
  <p>This is the way i have created the oracle procedure:</p>
  
  <pre><code>CREATE OR REPLACE procedure test (body IN out VARCHAR2,result in OUT VARCHAR2,resp in OUT VARCHAR2)
  AS LANGUAGE JAVA
  NAME 'Test.test(java.lang.String[],java.lang.String[],java.lang.String[])';
  </code></pre>
  
  <p>calling the procedure</p>
  
  <pre><code>calling the procedure:
  set serveroutput on
  declare
  body varchar2(32767);
  resp varchar2(32767);
  result varchar2(32767);
  begin
  body:='xml text ..........';
  test(body,result,resp);
  dbms_output.put_line(result);
  dbms_output.put_line(resp);
  dbms_output.put_line(length(resp));
  end;
  /
  </code></pre>