Trouble using HTTPS POST from Java component

Discussion in 'Java' started by CopperJ, Jun 30, 2004.

  1. CopperJ

    CopperJ Guest

    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:eek:f_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:eek:f_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)
     
    CopperJ, Jun 30, 2004
    #1
    1. Advertising

  2. On 29 Jun 2004 18:22:08 -0700, CopperJ wrote:

    > Does anyone have any insight into what I am doing wrong?
    >
    > 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();


    Don't close the output-stream. Keep it open until

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


    you finished reading from the input-stream.

    > l_inputStream.close();


    So, close it here (before or after).


    Regards, Lothar
    --
    Lothar Kimmeringer E-Mail:
    PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

    Always remember: The answer is forty-two, there can only be wrong
    questions!
     
    Lothar Kimmeringer, Jun 30, 2004
    #2
    1. Advertising

  3. CopperJ

    Roedy Green Guest

    On Wed, 30 Jun 2004 08:15:37 +0200, Lothar Kimmeringer
    <> wrote or quoted :

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


    for sample code, see http://mindprod.com/fileio.html
    tell it you want to do an HTTP-CGI-POST-write.

    Then make a little test case for http and test that. Then modify for
    https. Then if that works, slowly modify to what you need, step by
    step.

    HTTPS depends(depended?) on browser support. Check the class of the
    connection object. You may be making an unwarranted assumption.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 30, 2004
    #3
  4. CopperJ

    CopperJ Guest

    That had some effect - it no longer takes 5 minutes for it to time
    out, but I still get the error "getInputStream: Server returned a
    response code of 400 or greater.". What does this error mean? Does
    it mean the server is rejecting my request?

    Could I have the wrong classpath or bootclasspath values?

    (I'm a Java novice)


    Lothar Kimmeringer <> wrote in message news:<>...
    > On 29 Jun 2004 18:22:08 -0700, CopperJ wrote:
    >
    > > Does anyone have any insight into what I am doing wrong?
    > >
    > > 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();

    >
    > Don't close the output-stream. Keep it open until
    >
    > > while ((s_inputLine = l_inputStream.readLine()) != null)
    > > {
    > > s_rc = s_rc + s_inputLine;
    > > }

    >
    > you finished reading from the input-stream.
    >
    > > l_inputStream.close();

    >
    > So, close it here (before or after).
    >
    >
    > Regards, Lothar
     
    CopperJ, Jun 30, 2004
    #4
  5. On 30 Jun 2004 05:30:40 -0700, CopperJ wrote:

    > That had some effect - it no longer takes 5 minutes for it to time
    > out, but I still get the error "getInputStream: Server returned a
    > response code of 400 or greater.". What does this error mean? Does
    > it mean the server is rejecting my request?


    It means that you should have a look into the log-file of
    the server, because there seems to be a response by the
    server telling you, that something went wrong. What it
    is should be inside the response-body (that your
    HttpUrlConnection-implementation is not willing to give you).
    But looking into the http-access-log of you server and your
    http-error-log should help a little bit.

    Before calling getInputStream, you might check the return-
    code of the server. AFAIR HttpUrlConnection has something
    like getReturnCode().

    If it is 404 the URL you specified is not valid (maybe a
    type or something completely different). If it's something
    like 500 or greater, an error occured in the server-side
    cgi-script. First things can be found in the access-log,
    errors of the second type can be found in the error-log.

    > Could I have the wrong classpath or bootclasspath values?


    No, otherwise you would get something like exceptions that
    a specific class can't be found or something similar.


    Regards, Lothar
    --
    Lothar Kimmeringer E-Mail:
    PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

    Always remember: The answer is forty-two, there can only be wrong
    questions!
     
    Lothar Kimmeringer, Jun 30, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Hammond
    Replies:
    1
    Views:
    752
    Jim Hammond
    Nov 12, 2003
  2. axel
    Replies:
    0
    Views:
    5,049
  3. Axel
    Replies:
    8
    Views:
    1,174
    Adrienne Boswell
    Apr 27, 2009
  4. jotto
    Replies:
    4
    Views:
    417
    jotto
    Oct 2, 2006
  5. Naveen Dhanuka
    Replies:
    1
    Views:
    299
Loading...

Share This Page