Trouble using HTTPS POST from Java component

C

CopperJ

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)
 
L

Lothar Kimmeringer

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: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
R

Roedy Green

conn.setDoOutput(true);

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.
 
C

CopperJ

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)
 
L

Lothar Kimmeringer

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: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top