Trouble using HTTPS POST from Java component

From: CopperJ (coppersmith_jill_at_hotmail.com)
Date: 06/30/04

  • Next message: Tony Morris: "Re: compare with empty string uses equals method or == ??"
    Date: 29 Jun 2004 18:22:08 -0700
    
    

    Hello,

    I'm trying to use a Java component running inside EA Server to do an
    HTTPS POST to a 3rd party vendor and I'm not having much luck.

    The component times out after five minutes when it attempts to open
    the input stream. I receive a stack trace with an error
    "getInputStream: Server returned a response code of 400 or greater."

    The vendor says that they see me connect and disconnect, but nothing
    in between. I've written the contents of the s_xml variable I am
    reading in to the system log and it is as I expect, so I know that
    part is working.

    Does anyone have any insight into what I am doing wrong?

    Thanks!

    package com.metavante.n_sns_java_https_post;
    import org.omg.CORBA.*;
    import java.util.*;
    import java.lang.Object;
    import java.io.*;
    import java.net.*;
    import com.sybase.jaguar.net.HttpsURLConnection;

    public class n_sns_java_https_postImpl
    {
            // This is the main public interface.
        public java.lang.String of_httpsPOST (java.lang.String s_file,
    java.lang.String s_url)
            {
            java.lang.String s_xml;
            java.lang.String s_rc = new java.lang.String("");
            String s_inputLine;

                    System.err.println("n_sns_java_https_post:of_httpsPOST: Request to
    post " + s_file + " to " + s_url);
                    s_xml = of_readInputFile(s_file);

                    try
                    {
                    s_rc = "";

                    URL url = new URL( s_url );

                    URLConnection conn = url.openConnection();

                    if (conn instanceof HttpsURLConnection)
                            {
                            HttpsURLConnection https_conn = (HttpsURLConnection) conn;
                            try
                                    {
                                    https_conn.setSSLProperty( "qop","sybpks_intl" );
                                    https_conn.setSSLProperty( "pin", "sybase");
                                    }
                            catch ( CtsSecurity.InvalidPropertyException ipe )
                                    {
                                    System.err.println( ipe );
                                    }
                            catch ( CtsSecurity.InvalidValueException ive )
                                    {
                                    System.err.println( ive );
                                    }

                            https_conn.setRequestMethod("POST");
                            https_conn.setRequestProperty("Content-type", "text/plain");

                            conn.setDoOutput(true);
                            conn.setDoInput(true);
                            conn.connect();
                            PrintWriter out = new PrintWriter(conn.getOutputStream());

                            String s_payload = s_xml;
                            out.println(s_payload);

                            out.flush();
                            out.close();

                            BufferedReader l_inputStream = new BufferedReader(new
    InputStreamReader(conn.getInputStream()));
                            System.err.println("n_sns_java_https_post:of_httpsPOST: --
    input stream open");

                            while ((s_inputLine = l_inputStream.readLine()) != null)
                                    {
                                    s_rc = s_rc + s_inputLine;
                                    }
                            l_inputStream.close();
                            }
                    }

                    catch (Exception e)
                            {
                            e.printStackTrace();
                            return e.getMessage();
                            }
                    return s_rc;
            }

            // This function reads in a file from disk
        private java.lang.String of_readInputFile (java.lang.String sFile)
            {
            java.lang.String sLine;
            java.lang.String s_xml = new java.lang.String("");

                      try
                      {
                            FileReader fr = new FileReader (sFile);
                            BufferedReader inFile = new BufferedReader (fr);

                            sLine = inFile.readLine();

                            while (sLine != null)
                            {
                                    s_xml = s_xml + sLine;
                                    sLine = inFile.readLine();
                            }
                            inFile.close();
                      }

                    catch (FileNotFoundException exception)
                    {
                            s_xml = "ERROR: File " + sFile + " not found.";
                    }

                    catch (IOException exception)
                    {
                            s_xml = "ERROR: " + exception;
                    }
            return s_xml;
            }

    }

    OUTPUT IN LOG:

    Jun 29 18:31:33 2004: java.io.IOException: getInputStream: Server
    returned a response code of 400 or greater.
    Jun 29 18:31:33 2004: at
    com.sybase.jaguar.net.HttpsURLConnection.getInputStream(HttpsURLConnection.java:524)
    Jun 29 18:31:33 2004: at
    com.metavante.n_sns_java_https_post.n_sns_java_https_postImpl.of_httpsPOST(n_sns_java_https_postImpl.java:84)
    Jun 29 18:31:33 2004: at
    com.metavante.n_sns_java_https_post._sk_ROCK_n_sns_java_https_post.invoke(_sk_ROCK_n_sns_java_https_post.java:60)
    Jun 29 18:31:33 2004: at com.sybase.CORBA.local.Socket.call(Native
    Method)
    Jun 29 18:31:33 2004: at
    com.sybase.CORBA.local.OutputStream.write(OutputStream.java:29)
    Jun 29 18:31:33 2004: at
    com.sybase.CORBA.iiop.Connection.invoke(Connection.java:3365)
    Jun 29 18:31:33 2004: at
    ROCK._st_n_sns_java_https_post.of_httpsPOST(_st_n_sns_java_https_post.java:32)
    Jun 29 18:31:33 2004: at
    com.sybase.jsp.ROCK_0005fplayground_0005fhttps$jsp._jspService(ROCK_0005fplayground_0005fhttps$jsp.java:110)
    Jun 29 18:31:33 2004: at
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
    Jun 29 18:31:33 2004: at
    javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    Jun 29 18:31:33 2004: at
    org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:268)
    Jun 29 18:31:33 2004: at
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:461)
    Jun 29 18:31:33 2004: at
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:553)
    Jun 29 18:31:33 2004: at
    javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    Jun 29 18:31:33 2004: at
    com.sybase.jaguar.servlet.JagServlet.service(JagServlet.java:656)
    Jun 29 18:31:33 2004: at
    com.sybase.jaguar.servlet.JagRequestDispatcher.service(JagRequestDispatcher.java:922)
    Jun 29 18:31:33 2004: at
    com.sybase.jaguar.servlet.JagWebResource.service(JagWebResource.java:90)
    Jun 29 18:31:33 2004: at
    com.sybase.jaguar.servlet.JagFilterChain.doFilter(JagFilterChain.java:131)
    Jun 29 18:31:33 2004: at
    com.sybase.jaguar.servlet.ServletEngine._service(ServletEngine.java:804)
    Jun 29 18:31:33 2004: at
    com.sybase.jaguar.servlet.ServletEngine.service(ServletEngine.java:338)
    Jun 29 18:31:33 2004: at
    com.sybase.jaguar.servlet.ServletServiceImpl.doService(ServletServiceImpl.java:52)
    Jun 29 18:31:33 2004: at
    com.sybase.jaguar.servlet._sk_JaguarServlet_ServletService.invoke(_sk_JaguarServlet_ServletService.java:151)


  • Next message: Tony Morris: "Re: compare with empty string uses equals method or == ??"