0 Replies Latest reply on Apr 10, 2013 5:09 PM by 439619

    Problems Creating a Java Class using a webservice with certificate


      i'm developing a java class that call's a webservice that needs a certificate, i'm not used to work with java, last time was 10 years ago, so i'm having some troubles because of the certificate.

      I already add the certificate using java control panel > Security > Certificates. When testing i get the following error: IOException (java.io.IOException: subject key, Unknown key spec)

      I think I need to define the certificate in my class, but i'm having a lots of trouble with the samples that i found over the internet, nothing works and i'm running out of time.

      This is my Class

      create or replace and compile java source named "FishInfoAt" as
      import java.net.*;
      import java.io.*;
      import java.security.*;

      public class FishInfoAt
           public FishInfoAt()

           public static String send(String urlfishinfoat, String mensagem, String mensagem1, String mensagem2, String mensagem3)
                // Init
                String response = "";
                String msgtotal = mensagem+mensagem1+mensagem2+mensagem3;
                String a = "";

                HttpURLConnection conn = null;

                     URL url = new URL(urlfishinfoat);
                     conn = (HttpURLConnection) url.openConnection();

                     conn.setRequestProperty("Content-type", "text/xml; charset=utf-8");
                     conn.setRequestProperty("SOAPAction", "https://servicos.portaldasfinancas.gov.pt:401/sgdtws/documentosTransporte/");
                     conn.setRequestProperty("Content-Length","" + msgtotal.length());


                     OutputStream out = conn.getOutputStream();

                     InputStream in = conn.getInputStream();
                     int value;
                     while( (value = in.read()) != -1)

                catch(Exception e)
      response = ("*** ERROR - IOException (" + e.getMessage() + a + ")");

      return response;